save button functionality

checks if valid first