Reset A Form Through Javascript That Is Called Via Php November 30, 2022 Post a Comment Ok I have googled for hours and found nothing that works. I need help desperately I have got a form with the following elements in it. Solution 1: That's because you're going back in the history - browsers remember forms when you go back/forward. What you are doing isn't a "normal" user experience - I would suggest you print out a nice looking page saying thanks in the "sendmail.php" file and then let the user navigate to wherever they want to on your site. Solution 2: as Ed said, you are going back in history, and the browser remembers it. Try this: instead of this line: window.location.href='javascript:history.go(-1)'; write : window.location.href='RelativePathToActualForm'; Solution 3: Your Problem is with the javascript code: window.location.href='javascript:history.go(-1)'; document.enquiry.reset(); Copy Remove this code EDIT: Use this code: if(mail($to, $subject,$message)){?> <SCRIPT LANGUAGE='JavaScript'> alert('Your Enquiry was sent successfully we will get back to you shortly'); window.location.href='/*YOUR FORM PAGE LINK*/'; </SCRIPT> <?php } Copy Solution 4: After processing the form post you should redirect to another page (or again to your form) and display your message there e.g.: php header("Location: form.php?formpostwassuccessful=1"); Copy then the form page if(isset($_GET['formpostwassuccessful'])) echo "Thank you. Your form was sent."; Copy also see redirect after post? Solution 5: First look at example of using php session-based flash messages http://mikeeverhart.net/php/session-based-flash-messages/ Usual flow: User fills in the form Presses submit Your php script sendmail.php validates the form If there were some validation errors [set error message] If there were some mail sending errors [set error message] If everything is ok [set success message] Call from php redirect to the form display page. [set error|success message] - using the link provided above how to set the message. Now important part every time you render your form, you should check for set messages, if there are some messages - display them. How do those messages work? It simply sets the message to session ($_SESSION) array, and then when the message is displayed, the message is unset from session. Share Post a Comment for "Reset A Form Through Javascript That Is Called Via Php"
Post a Comment for "Reset A Form Through Javascript That Is Called Via Php"