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@mydomain.com";
$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
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
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.