Skip to content Skip to sidebar Skip to footer

Reset A Form Through Javascript That Is Called Via Php

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();

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 } 

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");

then the form page

if(isset($_GET['formpostwassuccessful']))
  echo "Thank you. Your form was sent.";

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:

  1. User fills in the form
  2. Presses submit
  3. Your php script sendmail.php validates the form
  4. If there were some validation errors [set error message]
  5. If there were some mail sending errors [set error message]
  6. If everything is ok [set success message]
  7. 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.


Post a Comment for "Reset A Form Through Javascript That Is Called Via Php"