Jump to content

How to reset a contact form


music_fan01

Recommended Posts

My contact form works, but how can I reset it so that when someone fills in the required information and the send the email, I want the information from the text boxes to clear. Right now, it doesnt do that, the name,email address, and message remains in the text boxes.

 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Author: Reality Software
Website: http://www.realitysoftware.ca
Note: This is a free template released under the Creative Commons Attribution 3.0 license, 
which means you can use it in any way you want provided you keep the link to the author intact.
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact</title>
<link href="style.css" rel="stylesheet" type="text/css" /></head>
<body>
<!-- header -->
    <div id="header">
    	<div id="logo"><a href="#">Header</a></div>
        <div id="menu">
        	<ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Link 1</a></li>
            <li><a href="#">Link 2</a></li>
            <li><a href="#">Link 3</a></li>
            <li><a href="#">Contact</a></li>
    <li><a href="#">Guestbook</a></li>
            </ul>
      </div>
  </div>
    <!--end header -->
    <!-- main -->
    <div id="main">
    <div id="content">

   
<div id="text">
                <h1><strong>Contact</strong></h1>
</div>
<br/>
<br/>
<br/>
<br/>
<br/>

<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>

<?php  
      
        if (isset($_POST['Submit'])) {  
      
            if ($_POST['name'] != "") {  
                $_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);  
                if ($_POST['name'] == "") {  
                    $errors .= 'Please enter a valid name.<br/><br/>';  
                }  
            } else {  
                $errors .= 'Please enter your name.<br/>';  
            }  
      
            if ($_POST['email'] != "") {  
                $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);  
                if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {  
                    $errors .= "$email is <strong>NOT</strong> a valid email address.<br/><br/>";  
                }  
            } else {  
                $errors .= 'Please enter your email address.<br/>';  
            }  
      
            if ($_POST['message'] != "") {  
                $_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING);  
                if ($_POST['message'] == "") {  
                    $errors .= 'Please enter a message to send.<br/>';  
                }  
            } else {  
                $errors .= 'Please enter a message to send.<br/>';  
            }  
      
            if (!$errors) {  
                $first_name=$_POST['name'];
	$email_address=$_POST['email'];
	$subject = 'Email Submission'; 
	$message=$_POST['message'];

	mail("myemailaddress@gmail.com","$subject",
	$message,"From: $first_name <$email_address>"); 
      
                echo "Thank you for your email!<br/><br/>";  
            } else {  
                echo '<div style="color: red">' . $errors . '<br/></div>';  
            }  
        }  
    ?>  

      
    <form name="form1" method="post" action="contact.php">  
    Name: <br/>  
    <input type="text" name="name" value="<?php echo $_POST['name']; ?>" size="50" /><br/><br/>  
    Email Address: <br/>  
    <input type="text" name="email" value="<?php echo $_POST['email']; ?>" size="50"/> <br/><br/>  
    Message: <br/>  
    <textarea name="message" rows="5" cols="50"><?php echo $_POST['message']; ?></textarea>  
    <br/>  
    <input type="Submit" name="Submit" value="Submit"/>  
    <input type="Reset" name="Reset" value="Reset"/>

    </form>
         

     <!-- footer -->
<br/>
<br/>
<br/>


    <div id="footer">
    <div id="left_footer">© Copyright 2011<strong> Author </strong></div>
    <div id="right_footer">

<!-- Please do not change or delete this link. Read the license! Thanks. :-) -->
Design by <a href="http://www.realitysoftware.ca" title="Website Design">Reality Software</a>

<!-- end footer --></div>
<!-- end main --></div>
</body>
</html>





Link to comment
Share on other sites

You should be able to reload the page with a header and add the thank you as a get value.

<?PHP
//So instead of echoing here in your processing script
//echo "Thank you for your email!<br/><br/>";
// use a header with get

header("Location:contact.php?thankyou");

//Then outside the processing script add 
If (isset($_GET['thankyou')){
echo "Thank you for your email!<br/><br/>";
}
?>

Link to comment
Share on other sites

Just to make sure I am placing it in the right spot.

 


Author: Reality Software
Website: http://www.realitysoftware.ca
Note: This is a free template released under the Creative Commons Attribution 3.0 license, 
which means you can use it in any way you want provided you keep the link to the author intact.
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact</title>
<link href="style.css" rel="stylesheet" type="text/css" /></head>
<body>
<!-- header -->
    <div id="header">
    	<div id="logo"><a href="#">Header</a></div>
        <div id="menu">
        	<ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Link 1</a></li>
            <li><a href="#">Link 2</a></li>
            <li><a href="#">Link 3</a></li>
            <li><a href="#">Contact</a></li>
    <li><a href="#">Guestbook</a></li>
            </ul>
      </div>
  </div>
    <!--end header -->
    <!-- main -->
    <div id="main">
    <div id="content">

   
<div id="text">
                <h1><strong>Contact</strong></h1>
</div>
<br/>
<br/>
<br/>
<br/>
<br/>

<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>

<?php  
      
        if (isset($_POST['Submit'])) {  
      
            if ($_POST['name'] != "") {  
                $_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);  
                if ($_POST['name'] == "") {  
                    $errors .= 'Please enter a valid name.<br/><br/>';  
                }  
            } else {  
                $errors .= 'Please enter your name.<br/>';  
            }  
      
            if ($_POST['email'] != "") {  
                $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);  
                if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {  
                    $errors .= "$email is <strong>NOT</strong> a valid email address.<br/><br/>";  
                }  
            } else {  
                $errors .= 'Please enter your email address.<br/>';  
            }  
      
            if ($_POST['message'] != "") {  
                $_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING);  
                if ($_POST['message'] == "") {  
                    $errors .= 'Please enter a message to send.<br/>';  
                }  
            } else {  
                $errors .= 'Please enter a message to send.<br/>';  
            }  
      
            if (!$errors) {  
                $first_name=$_POST['name'];
	$email_address=$_POST['email'];
	$subject = 'Email Submission'; 
	$message=$_POST['message'];

	mail("myemailaddress@gmail.com","$subject",
	$message,"From: $first_name <$email_address>"); 
      
               header("Location:contact.php?thankyou");
              If (isset($_GET['thankyou')){
             echo "Thank you for your email!<br/><br/>";
}  
            } else {  
                echo '<div style="color: red">' . $errors . '<br/></div>';  
            }  
        }  
    ?>  

      
    <form name="form1" method="post" action="contact.php">  
    Name: <br/>  
    <input type="text" name="name" value="<?php echo $_POST['name']; ?>" size="50" /><br/><br/>  
    Email Address: <br/>  
    <input type="text" name="email" value="<?php echo $_POST['email']; ?>" size="50"/> <br/><br/>  
    Message: <br/>  
    <textarea name="message" rows="5" cols="50"><?php echo $_POST['message']; ?></textarea>  
    <br/>  
    <input type="Submit" name="Submit" value="Submit"/>  
    <input type="Reset" name="Reset" value="Reset"/>

    </form>
         

     <!-- footer -->
<br/>
<br/>
<br/>


    <div id="footer">
    <div id="left_footer">© Copyright 2011<strong> Author </strong></div>
    <div id="right_footer">

<!-- Please do not change or delete this link. Read the license! Thanks. :-) -->
Design by <a href="http://www.realitysoftware.ca" title="Website Design">Reality Software</a>

<!-- end footer --></div>
<!-- end main --></div>
</body>
</html>




Link to comment
Share on other sites

Ok, I think I may have got it now.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Author: Reality Software
Website: http://www.realitysoftware.ca
Note: This is a free template released under the Creative Commons Attribution 3.0 license, 
which means you can use it in any way you want provided you keep the link to the author intact.
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact</title>
<link href="style.css" rel="stylesheet" type="text/css" /></head>
<body>
<!-- header -->
    <div id="header">
    	<div id="logo"><a href="#">Header</a></div>
        <div id="menu">
        	<ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Link 1</a></li>
            <li><a href="#">Link 2</a></li>
            <li><a href="#">Link 3</a></li>
            <li><a href="#">Contact</a></li>
    <li><a href="#">Guestbook</a></li>
            </ul>
      </div>
  </div>
    <!--end header -->
    <!-- main -->
    <div id="main">
    <div id="content">

   
<div id="text">
                <h1><strong>Contact</strong></h1>
</div>
<br/>
<br/>
<br/>
<br/>
<br/>

<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>

<?php  
      
        if (isset($_POST['Submit'])) {  
      
            if ($_POST['name'] != "") {  
                $_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);  
                if ($_POST['name'] == "") {  
                    $errors .= 'Please enter a valid name.<br/><br/>';  
                }  
            } else {  
                $errors .= 'Please enter your name.<br/>';  
            }  
      
            if ($_POST['email'] != "") {  
                $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);  
                if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {  
                    $errors .= "$email is <strong>NOT</strong> a valid email address.<br/><br/>";  
                }  
            } else {  
                $errors .= 'Please enter your email address.<br/>';  
            }  
      
            if ($_POST['message'] != "") {  
                $_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING);  
                if ($_POST['message'] == "") {  
                    $errors .= 'Please enter a message to send.<br/>';  
                }  
            } else {  
                $errors .= 'Please enter a message to send.<br/>';  
            }  
      
            if (!$errors) {  
                $first_name=$_POST['name'];
	$email_address=$_POST['email'];
	$subject = 'Email Submission'; 
	$message=$_POST['message'];

	mail("myemailaddress@gmail.com","$subject",
	$message,"From: $first_name <$email_address>"); 
      
                echo "Thank you for your email!<br/><br/>";  
            } else {  
                echo '<div style="color: red">' . $errors . '<br/></div>';  
            }  
        }  
    ?>  

<?PHP
header("Location:contact.php?thankyou");

//Then outside the processing script add 
If (isset($_GET['thankyou'])){
echo "Thank you for your email!<br/><br/>";
}
?>
      
    <form name="form1" method="post" action="contact.php">  
    Name: <br/>  
    <input type="text" name="name" value="<?php echo $_POST['name']; ?>" size="50" /><br/><br/>  
    Email Address: <br/>  
    <input type="text" name="email" value="<?php echo $_POST['email']; ?>" size="50"/> <br/><br/>  
    Message: <br/>  
    <textarea name="message" rows="5" cols="50"><?php echo $_POST['message']; ?></textarea>  
    <br/>  
    <input type="Submit" name="Submit" value="Submit"/>  
    <input type="Reset" name="Reset" value="Reset"/>

    </form>
         

     <!-- footer -->
<br/>
<br/>
<br/>


    <div id="footer">
    <div id="left_footer">© Copyright 2011<strong> Author </strong></div>
    <div id="right_footer">

<!-- Please do not change or delete this link. Read the license! Thanks. :-) -->
Design by <a href="http://www.realitysoftware.ca" title="Website Design">Reality Software</a>

<!-- end footer --></div>
<!-- end main --></div>
</body>
</html>

 

 

Link to comment
Share on other sites

How about this

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Author: Reality Software
Website: http://www.realitysoftware.ca
Note: This is a free template released under the Creative Commons Attribution 3.0 license, 
which means you can use it in any way you want provided you keep the link to the author intact.
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact</title>
<link href="style.css" rel="stylesheet" type="text/css" /></head>
<body>
<!-- header -->
    <div id="header">
    	<div id="logo"><a href="#">Header</a></div>
        <div id="menu">
        	<ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Link 1</a></li>
            <li><a href="#">Link 2</a></li>
            <li><a href="#">Link 3</a></li>
            <li><a href="#">Contact</a></li>
    <li><a href="#">Guestbook</a></li>
            </ul>
      </div>
  </div>
    <!--end header -->
    <!-- main -->
    <div id="main">
    <div id="content">

   
<div id="text">
                <h1><strong>Contact</strong></h1>
</div>
<br/>
<br/>
<br/>
<br/>
<br/>

<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>

<?php  
      
        if (isset($_POST['Submit'])) {  
      
            if ($_POST['name'] != "") {  
                $_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);  
                if ($_POST['name'] == "") {  
                    $errors .= 'Please enter a valid name.<br/><br/>';  
                }  
            } else {  
                $errors .= 'Please enter your name.<br/>';  
            }  
      
            if ($_POST['email'] != "") {  
                $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);  
                if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {  
                    $errors .= "$email is <strong>NOT</strong> a valid email address.<br/><br/>";  
                }  
            } else {  
                $errors .= 'Please enter your email address.<br/>';  
            }  
      
            if ($_POST['message'] != "") {  
                $_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING);  
                if ($_POST['message'] == "") {  
                    $errors .= 'Please enter a message to send.<br/>';  
                }  
            } else {  
                $errors .= 'Please enter a message to send.<br/>';  
            }  
      
            if (!$errors) {  
                $first_name=$_POST['name'];
	$email_address=$_POST['email'];
	$subject = 'Email Submission'; 
	$message=$_POST['message'];

	mail("myemailaddress@gmail.com","$subject",
	$message,"From: $first_name <$email_address>"); 
      
	header("Location:contact.php?thankyou");
            } else {  
                echo '<div style="color: red">' . $errors . '<br/></div>';  
            }  
        }  
    ?>  

<?PHP
//Then outside the processing script add 
If (isset($_GET['thankyou'])){
echo "Thank you for your email!<br/><br/>";
}
?>
      
    <form name="form1" method="post" action="contact.php"> 
    Name: <br/>  
    <input type="text" name="name" value="<?php if(isset($_POST['name'])){ echo $_POST['name'];} ?>" size="50" /><br/><br/>  
    Email Address: <br/>  
    <input type="text" name="email" value="<?php if(isset($_POST['email'])){ echo $_POST['email'];} ?>" size="50"/> <br/><br/>  
    Message: <br/>  
    <textarea name="message" rows="5" cols="50"><?php if(isset($_POST['message'])){ echo $_POST['message'];} ?></textarea>  
    <br/>  
    <input type="Submit" name="Submit" value="Submit"/>  
    <input type="Reset" name="Reset" value="Reset"/>

    </form>
         

     <!-- footer -->
<br/>
<br/>
<br/>


    <div id="footer">
    <div id="left_footer">© Copyright 2011<strong> Author </strong></div>
    <div id="right_footer">

<!-- Please do not change or delete this link. Read the license! Thanks. :-) -->
Design by <a href="http://www.realitysoftware.ca" title="Website Design">Reality Software</a>

<!-- end footer --></div>
<!-- end main --></div>
</body>
</html>

Link to comment
Share on other sites

Hey my bad.  I always have processing above any output.  I should have noticed that.

<?php  
      
        if (isset($_POST['Submit'])) {  
      
            if ($_POST['name'] != "") {  
                $_POST['name'] = filter_var($_POST['name'], FILTER_SANITIZE_STRING);  
                if ($_POST['name'] == "") {  
                    $errors .= 'Please enter a valid name.<br/><br/>';  
                }  
            } else {  
                $errors .= 'Please enter your name.<br/>';  
            }  
      
            if ($_POST['email'] != "") {  
                $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);  
                if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {  
                    $errors .= "$email is <strong>NOT</strong> a valid email address.<br/><br/>";  
                }  
            } else {  
                $errors .= 'Please enter your email address.<br/>';  
            }  
      
            if ($_POST['message'] != "") {  
                $_POST['message'] = filter_var($_POST['message'], FILTER_SANITIZE_STRING);  
                if ($_POST['message'] == "") {  
                    $errors .= 'Please enter a message to send.<br/>';  
                }  
            } else {  
                $errors .= 'Please enter a message to send.<br/>';  
            }  
      
            if (!$errors) {  
                $first_name=$_POST['name'];
	$email_address=$_POST['email'];
	$subject = 'Email Submission'; 
	$message=$_POST['message'];

	mail("myemailaddress@gmail.com","$subject",
	$message,"From: $first_name <$email_address>"); 
      
	header("Location:contact.php?thankyou");
            } else {  
                echo '<div style="color: red">' . $errors . '<br/></div>';  
            }  
        }  
    ?>  


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
Author: Reality Software
Website: http://www.realitysoftware.ca
Note: This is a free template released under the Creative Commons Attribution 3.0 license, 
which means you can use it in any way you want provided you keep the link to the author intact.
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact</title>
<link href="style.css" rel="stylesheet" type="text/css" /></head>
<body>
<!-- header -->
    <div id="header">
    	<div id="logo"><a href="#">Header</a></div>
        <div id="menu">
        	<ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">Link 1</a></li>
            <li><a href="#">Link 2</a></li>
            <li><a href="#">Link 3</a></li>
            <li><a href="#">Contact</a></li>
    <li><a href="#">Guestbook</a></li>
            </ul>
      </div>
  </div>
    <!--end header -->
    <!-- main -->
    <div id="main">
    <div id="content">

   
<div id="text">
                <h1><strong>Contact</strong></h1>
</div>
<br/>
<br/>
<br/>
<br/>
<br/>

<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>


<?PHP
//Then outside the processing script add 
If (isset($_GET['thankyou'])){
echo "Thank you for your email!<br/><br/>";
}
?>
      
    <form name="form1" method="post" action="contact.php"> 
    Name: <br/>  
    <input type="text" name="name" value="<?php if(isset($_POST['name'])){ echo $_POST['name'];} ?>" size="50" /><br/><br/>  
    Email Address: <br/>  
    <input type="text" name="email" value="<?php if(isset($_POST['email'])){ echo $_POST['email'];} ?>" size="50"/> <br/><br/>  
    Message: <br/>  
    <textarea name="message" rows="5" cols="50"><?php if(isset($_POST['message'])){ echo $_POST['message'];} ?></textarea>  
    <br/>  
    <input type="Submit" name="Submit" value="Submit"/>  
    <input type="Reset" name="Reset" value="Reset"/>

    </form>
         

     <!-- footer -->
<br/>
<br/>
<br/>


    <div id="footer">
    <div id="left_footer">© Copyright 2011<strong> Author </strong></div>
    <div id="right_footer">

<!-- Please do not change or delete this link. Read the license! Thanks. :-) -->
Design by <a href="http://www.realitysoftware.ca" title="Website Design">Reality Software</a>

<!-- end footer --></div>
<!-- end main --></div>
</body>
</html>

Link to comment
Share on other sites

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.