Here's a simplified description of how this can be done - by which I mean submitting your data - and how it is then handled.
form: this has an action attribute (contact.php for you) and all named items withing the from are sent to the action target. This page is then opened after you do whatever you do with the data you sent. If you must use a form for whatever it is you wish to do then one way of doing this is to reopen the same page that you just submitted with the changes you wish (prefill submitted data, for example, along with success or fail message). I would not do it this way, that is, with forms, if I wish to stay on the same page.
AJAX: AJAX allows you to send data to the server, handle it, and then send a response back to the page that sent the data. You can use it to update any part of the existing page. For you, perhaps this would be to put 'success' or 'failure' in an empty area you reserved for the message. AJAX can be learned here.
Once you get used to using AJAX, you will generally prefer it to a form - but forms do have their place.