Reset A Form Through Javascript That Is Called Via Php May 27, 2024 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(); CopyRemove this codeEDIT:Use this code:Baca JugaHow Can I Display Value Of A Div With A Button Click?Html Form With SendemailChange Data-attribute On Click Of Html Elementsif(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 } CopySolution 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"); Copythen the form pageif(isset($_GET['formpostwassuccessful'])) echo"Thank you. Your form was sent."; Copyalso 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 formPresses submitYour php script sendmail.php validates the formIf 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 You may like these postsDifferent Display Value For Selecte Text Using Select2.jsUnique Random Number Generation Using JavascriptUncaught Failed To Get Parent Origin From Url HashHow To Fix An Error Of Website Iframe? 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"