Jump to content

Resetting a form?


snottrocket

Recommended Posts

That's really the only way i can categorize this particular question.

 

I have a site loading a form into an iframe. probably not the smartest thing to do but I've built a one-page portfolio site that scrolls to each anchor point with the scrollTo script.  None the less, my form loads into my frame.

 

I started thinking about usability and how odd it might be to a non-techie, non-webby visitor to go to the form, submit and then maybe want to send another message. Although not very probable, it's the stuff we don't anticipate happening that usually gets us in deep.  Really, what I'm looking for is something where after the visitor submits the form and it says "thank you for sending us an email" that it would either automatically reset my index page OR give the visitor the option of manually resetting the page.

 

my form

 

<form method="POST" action="mailer.php"><br />
Name:<br />

   <input type="text" name="name" size="50"><br>
   <br />
   E-Mail:<br>
   <input type="text" name="email" size="50"><br>
   <br />
   Comments:<br>
   <textarea wrap="soft" rows="5" name="message" cols="48"></textarea>
   <br>
   <br>
   <input type="submit" value="Submit" name="submit">
</form>

 

 

php script

<?php
if(isset($_POST['submit']) || isset( $_POST['submit_x'] )) {

$to = "[email protected]";
$subject = "Contact from a visitor";
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

$body = "From: $name\n E-Mail: $email\n Message:\n $message";

echo "Your email has been sent to $to!";
mail($to, $subject, $body);

} else {

echo "blarg!!!";

}
?>

Link to comment
https://forums.phpfreaks.com/topic/231223-resetting-a-form/
Share on other sites

 

Depending on how you want it to work, there are two things you can try:

 

Add a Reset button to the form, so the user can manually reset -

<input type="reset" value="Reset" name="reset">

 

Add an onLoad reset to the <body> tag so the form resets automatically when the script executes and reloads it -

<body onLoad="document.forms['formname'].reset();>

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/231223-resetting-a-form/#findComment-1190127
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.