Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Dec 2009
    Posts
    155
    Thanks
    34
    Thanked 1 Time in 1 Post

    disable form refresh after submit

    Hello everyone. I'm very new to php and have actually used a tutorial on youtube to create my php document. I am using client side form validation using Spry validation in dreamweaver which is very nice. One thing I would like to add is validation for server side or rather in my php document. I only need to validate my Name, email and Comments form fields. The other problem I'm having is after a user submits the form they can just hit refresh and submit the form multiple times with the previous entered data. I'm just trying to find the code and where to put it in to disable this from happening. In the lesson he included the results within the php but that may be what is causing this. I am interested in a redirect but unsure of the coding needed. Detailed descriptions would be very appreciated as again I'm just starting out with php. Here is where my form results are sent and the code of the
    customersupportprocess.php


    PHP Code:
    <?PHP
    /* Subject and Email Variables */
        
    $emailSubject 'Businessname Customer Support';
        
    $webMaster 'myemail@address.com';
        
    /* Gathering Data Variables */
             
    $Name $_POST ['Name'];
         
    $email $_POST ['email'];
         
    $Phone $_POST ['Phone'];
         
    $Comments $_POST ['Comments'];


         
    $body = <<<EOD
    <br><hr><br>
    Name: $Name <br>
    Email: $email <br>
    Phone: $Phone <br>
    Comments: $Comments <br>
    EOD;


        
    $headers "From: $email\r\n";
        
    $headers .= "Content-type: text/html\r\n";
        
    $success =mail($webMaster$emailSubject$body$headers);
        
    /* Results rendered as HTML */

        
    $theResults = <<<EOD
        
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <!-- TemplateBeginEditable name="doctitle" -->
    <title>Our Business Support form</title>
    <!-- TemplateEndEditable -->
    <!-- TemplateBeginEditable name="head" -->
    <!-- TemplateEndEditable -->
    <style type="text/css">
    <!--
    body {
        font: 14px "Times New Roman", Times, serif;
        background: #666666;
        margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
        padding: 0;
        text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
        color: #000000;
        background-color: #F2EFFA;
    }
    .oneColFixCtr #container {
        width: 930px;  /* using 20px less than a full 800px width allows for browser chrome and avoids a horizontal scroll bar */
        background: #F2EFFA; /* the auto margins (in conjunction with a width) center the page */
        border: 20px ridge #A598C9;
        text-align: left; /* this overrides the text-align: center on the body element. */
        margin-top: 0;
        margin-right: auto;
        margin-bottom: 0;
        margin-left: auto;
        clip: rect(auto,auto,auto,auto);
        z-index: auto;
    }
    .oneColFixCtr #mainContent {
        background: #F2EFFA;
        padding-top: 0;
        padding-bottom: 0;
        font: bold 14px "Times New Roman", Times, serif;
    }
    -->
    </style>
    <script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
    <link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
    <!--
    a:link {
        color: #400080;
        text-decoration: none;
    }
    a:hover {
        text-decoration: none;
    }
    p {
        color: #000;
        font-weight: normal;
    }
    -->
    </style></head>

    <body class="oneColFixCtr">

    <div id="container">
      <div id="mainContent">
        <ul id="MenuBar1" class="MenuBarHorizontal">
            <li> <a class="MenuBarItemSubmenu" href="index.htm">HOME</a>
              <ul>
                <li><a href="patch_pal.htm">PATCHING PAL PROGRAM</a></li>
                <li><a href="appliques.htm">APPLIQUES</a></li>
                <li><a href="http://www.business.blogspot.com" target="_blank">BLOG</a></li>
                <li><a href="#" class="MenuBarItemSubmenu">HELPFUL LINKS</a>
                  <ul>
                    <li><a href="testimonials.htm">Business TESTIMONIALS</a></li>
                    <li><a href="http://www.business.com/2009/05/amblyopia-kids-are-business-fans.html" target="_blank"> KIDS</a></li>
                    <li><a href="http://www.business.com" target="_blank">EYES</a></li>
                    <li><a href="http://www.business.org" target="_blank">PREVENT</a></li>
                  </ul>
                </li>
              </ul>
      </li>
            <li><a href="#" class="MenuBarItemSubmenu">SUPPORT</a>
              <ul>
                <li><a href="Customer Support.htm">CONTACT US</a></li>
                <li><a href="Pricing Information.htm">PRICING INFORMATION</a></li>
              </ul>
      </li>
            <li><a href="Order Form.htm" class="MenuBarItemSubmenu">ORDER FORM</a>
              <ul>
                <li><a href="money_order_form.htm">CHECK/MONEY ORDER </a></li>
                <li><a href="#" class="MenuBarItemSubmenu">PAYPAL/CREDIT CARD</a>
                  <ul>
                    <li><a href="Paypal Order Form.htm">USA ORDER FORM</a></li>
                    <li><a href="International order form.htm">INTERNATIONAL ORDER FORM</a></li>
                  </ul>
                </li>
                <li><a href="wholesale.htm">WHOLESALE REQUEST</a></li>
              </ul>
      </li>
            <li><a class="MenuBarItemSubmenu" href="#">PHOTOS</a>
              <ul>
                <li><a href="photo_gallery.htm">PAGE 1</a></li>
                <li><a href="photo_gallery2.htm">PAGE 2</a></li>
                <li><a href="http://www.flickr.com/search/show/">FLICKR SLIDESHOW</a></li>
              </ul>
            </li>
          <li><a href="#" class="MenuBarItemSubmenu">FAQ</a>
              <ul>
                <li><a href="faq.htm">FREQUENTLY ASKED QUESTIONS</a></li>
                <li><a href="learn more about us.htm">LEARN MORE ABOUT US</a></li>
                <li><a href="instruction for use.htm">INSTRUCTIONS FOR USE</a></li>
                <li><a href="privacy_policy.htm">PRIVACY POLICY</a></li>
              </ul>
          </li>
        </ul>
        <h1>&nbsp;</h1>
        <h2 align="left">&nbsp;</h2>
        <blockquote>
          <p align="left"><img src="/images/thankyou.jpg" width="200" height="75" /></p>
        </blockquote>
      &nbsp;</p>
      <blockquote>
        <p align="left">Thank you for your time! 
          We is dedicated to our customers needs and appreciate any 
          comments or questions you may have.</p>
        <p align="left">We will contact you <u> asap</u>.</font></b></i></font></p>
    <p align="center"><img src="/images/banner2.jpg" width="728" height="90" alt="banner2" /></p>
        <p align="left">&nbsp;</p>
      </blockquote>
      <p align="center"><em>Copyright © 2005-2009 [<span lang="en-us" xml:lang="en-us">www.</span>framehuggers.com] All 
          rights reserved.</em> </font></b> </i></p>
        <p align="center"><i>Revised:
          <!--webbot bot="TimeStamp" s-format="%m/%d/%y" s-type="EDITED" startspan -->
          12/11/09</font></i></p>
        <p>&nbsp;</p>
        <!-- end #mainContent --></div>
    <!-- end #container --></div>
    <script type="text/javascript">
    <!--
    var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
    //-->
    </script>
    </body>
    </html>

    EOD;
    echo 
    "$theResults";     
    ?>
    Last edited by 24seven; 12-20-2009 at 01:22 AM.

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Forward them to a results page (thank you, etc):
    PHP Code:
    if ( ! empty( $_POST ) )
    {
        
    // do your form processing here
        
    header'Location: page.php?thank-you' );
        exit;


  • Users who have thanked kbluhm for this post:

    24seven (12-20-2009)

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Posts
    155
    Thanks
    34
    Thanked 1 Time in 1 Post
    Thank you so much for your reply. I know I am seconds away from solving this with your help.. but one last question and I know it's total noob but .. Where exactly do I place that code to get it to work right? And does it replace some of my code in the process? If you could copy and paste it into mine would help tremendously.
    Thanks again I really appreciate this.

  • #4
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Ok, this is a very basic example. From here, you could add stuff like error checking, where you only redirect to `?sent` if, for instance, the email address is validly formatted (because there is no chance of it being delivered if the email address is `blah blah blah`). So if no errors exist, send the email and redirect, otherwise let it fall through right back to the form where you could tell them there are errors in their submission and repopulate the form values with what they'd previously submitted.

    Anyhow, here's the basic setup:
    PHP Code:
    <?php

    /* - - - - - - - - - -
     * Grab this file path for form processing and redirecting
     */

    $this_file './' basename__FILE__ );

    /* - - - - - - - - - -
     * Was the form submitted?
     */

    if ( ! empty( $_POST ) )
    {

        
    // Do stuff here, send email, etc

        // Return to the page, relaying that an email has been sent
        
    header'Location: ' $this_file '?sent' );
        exit;

    }

    /* - - - - - - - - - -
     * Was the form received?
     */

    $sent = isset( $_GET['sent'] );

    /* - - - - - - - - - -
     * Display the page
     * If $sent === TRUE, display a `thank you` message
     * Otherwise, display the form.
     */

    ?>

    <html>
        <head>
            <title>
                My Contact Page
            </title>
        </head>
        <body>

        <?php if ( $sent ): ?>
            Thanks for the message.

        <?php else: ?>
            <form action="<?php echo $this_file?>" method="post">
                <input type="text" name="subject" value="" />
                [ ... additional form field here ... ]
                <input type="submit" value="Send" />
            </form>

        <?php endif; ?>

        </body>
    </html>
    Last edited by kbluhm; 12-20-2009 at 02:19 PM.

  • #5
    Regular Coder
    Join Date
    Dec 2009
    Posts
    155
    Thanks
    34
    Thanked 1 Time in 1 Post
    I hate to say it but you lost me completely. Like I said.. I'm a total beginner to PHP so whatever you wrote in your second comment makes even less sence than before. I felt like I was grasping it some with what you wrote the first time but you might as well have wrote me Chinese lol. It seems that no one does php the same as the next guy. Every you tube article or Google search I do comes up with a whole different coding than the next guy. I can't find consistency in PHP at all so it's getting a little frustrating. For instance one guy will do a if statement like validation for instance. I've seen like 4 or 5 different ways to do the same thing. I plan on taking a college coarse as I'm really liking this but thought I'd take my shot at a quick email form for the wifes website. Definitely challenging but worth while when working properly. After watching youtube all day I was able to add server side validation as well as disable a double click on submit. Here is my final php code for my contact form. The submit button is very handy for anyone looking to stop double emails being sent from click happy customers :P (value= whatever you want the button to say)
    <input name="submit" type="submit" value="Submit Form" onclick="document.form1.submit.disabled=true;doc ument.form1.submit();">

    PHP Code:
    <?php
    /* Email Variables */
        
    $to 'myemail@charter.net';
        
    $Subject 'business Customer Support';
        
    $header "From: $email\r\n";

    if (
    $_POST['submit'])
    {
        
    //get form data
        
    $name $_POST['Name'];
        
    $email $_POST['email'];
        
    $phone $_POST['Phone'];
        
    $comments $_POST['Comments'];
        
        
    $errorstring "";  //default value of error string
        
        
    if (!$Name)
        
    $errorstring $errorstring."*Name<br>";
        
        if (!
    $email)
        
    $errorstring $errorstring."*Email<br>";
        
        if (!
    $Comments)
         
    $errorstring $errorstring."*Comments<br>";
         

            else
            {
                
        
    $body = <<<EOD
    <br><hr><br>
    Name: $Name <br>
    Email: $email <br>
    Phone: $Phone <br>
    Comments: $Comments <br>
    EOD;


        
    $headers "From: $email\r\n";
        
    $headers .= "Content-type: text/html\r\n";
        
    $success =mail($to$Subject$body$headers);
            
    header"Location: http://www.business.com/Support Confirmation.htm" );
            
            }
    }
                                                                                                                                            
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"><head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <!-- TemplateBeginEditable name="doctitle" -->
    <title>Business customer support form</title>
    <!-- TemplateEndEditable -->
    <!-- TemplateBeginEditable name="head" -->
    <!-- TemplateEndEditable -->
    <style type="text/css">
    <!--
    body {
        font: 100% Verdana, Arial, Helvetica, sans-serif;
        background: #666666;
        margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
        padding: 0;
        text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
        color: #000000;
        background-color: #F2EFFA;
    }
    .oneColFixCtr #container {
        width: 930px;  /* using 20px less than a full 800px width allows for browser chrome and avoids a horizontal scroll bar */
        background: #F2EFFA; /* the auto margins (in conjunction with a width) center the page */
        border: 20px ridge #A598C9;
        text-align: left; /* this overrides the text-align: center on the body element. */
        margin-top: 0;
        margin-right: auto;
        margin-bottom: 0;
        margin-left: auto;
        clip: rect(auto,auto,auto,auto);
        z-index: auto;
    }
    .oneColFixCtr #mainContent {
        font-family: Verdana, Arial, Helvetica, sans-serif;
        background: #F2EFFA;
        padding-top: 0;
        padding-bottom: 0;
        margin-right: auto;
        margin-left: auto;
    }
    -->
    </style>
    <script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
    <script src="/SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
    <script src="/SpryAssets/SpryValidationTextarea.js" type="text/javascript"></script>
    <link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
    <!--
    a:link {
        color: #400080;
        text-decoration: none;
    }
    a:hover {
        text-decoration: none;
    }
    p {
        color: #F00;
    }
    -->
    </style>
    <link href="/SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
    <link href="/SpryAssets/SpryValidationTextarea.css" rel="stylesheet" type="text/css" />
    </head>

    <body class="oneColFixCtr">

    <div id="container">
      <div id="mainContent"><ul id="MenuBar1" class="MenuBarHorizontal">
            <li> <a class="MenuBarItemSubmenu" href="index.htm">HOME</a>
              <ul>
                <li><a href="Patch Pal.htm">PATCHING PAL PROGRAM</a></li>
                <li><a href="Appliques.htm">APPLIQUES</a></li>
                <li><a href="http://www.business.blogspot.com" target="_blank">BLOG</a></li>
                <li><a href="#" class="MenuBarItemSubmenu">HELPFUL LINKS</a>
                  <ul>
                    <li><a href="Testimonials.htm">business TESTIMONIALS</a></li>
                    <li><a href="http://www.business/2009/05/amblyopia-kids-are-business-fans.html" target="_blank">business</a></li>
                    <li><a href="http://www.business.com" target="_blank">business</a></li>
                    <li><a href="http://www.business.org" target="_blank">business</a></li>
                  </ul>
                </li>
              </ul>
      </li>
            <li><a href="#" class="MenuBarItemSubmenu">SUPPORT</a>
              <ul>
                <li><a href="Customer Support.htm">CONTACT US</a></li>
                <li><a href="Pricing Information.htm">PRICING INFORMATION</a></li>
              </ul>
      </li>
            <li><a href="Order Form.htm" class="MenuBarItemSubmenu">ORDER FORM</a>
              <ul>
                <li><a href="Money Order Form.htm">CHECK/MONEY ORDER </a></li>
                <li><a href="#" class="MenuBarItemSubmenu">PAYPAL/CREDIT CARD</a>
                  <ul>
                    <li><a href="Paypal Order Form.htm">USA ORDER FORM</a></li>
                    <li><a href="International Order Form.htm">INTERNATIONAL ORDER FORM</a></li>
                  </ul>
                </li>
                <li><a href="Wholesale.htm">WHOLESALE REQUEST</a></li>
              </ul>
      </li>
            <li><a class="MenuBarItemSubmenu" href="#">PHOTOS</a>
              <ul>
                <li><a href="Photo Gallery.htm">PAGE 1</a></li>
                <li><a href="Photo Gallery2.htm">PAGE 2</a></li>
                <li><a href="http://www.flickr.com/search/show/?q=business">FLICKR SLIDESHOW</a></li>
              </ul>
            </li>
          <li><a href="#" class="MenuBarItemSubmenu">FAQ</a>
              <ul>
                <li><a href="Faq.htm">FREQUENTLY ASKED QUESTIONS</a></li>
                <li><a href="About Me.htm">LEARN MORE ABOUT US</a></li>
                <li><a href="Instructions.htm">INSTRUCTIONS FOR USE</a></li>
                <li><a href="Privacy Policy.htm">PRIVACY POLICY</a></li>
              </ul>
          </li>
        </ul>
        <h1 align="center">&nbsp;</h1>
        <p align="center">&nbsp;</p>
        <blockquote>
          <p align="left">&nbsp;</p>
        </blockquote>
        <p align="left"><img src="images/customer-support.jpg" width="200" height="75" alt="cs" /></p>
    <p align="left"><a href="test.php">test</a></p>
        <form action="test.php" method="post" enctype="application/x-www-form-urlencoded" target="_self" id="Customer Support Form"><table width="562" height="277" border="6"><tbody style="font-size: 12px;"><tr><td width="554"><blockquote>
          <p>*<font color=black>Name</font><br/>
            <span id="sprytextfield1">
            <input type="text" id="Name" name="Name" value='<?php echo $Name?>' />
            <span class="textfieldMinCharsMsg">Minimum number of characters (3) not met.</span><span class="textfieldRequiredMsg">A name is required.</span></span></p>
        </blockquote></td>
        </tr><tr><td><blockquote>
          <p>*<font color=black>Email</font><br/>
            <span id="sprytextfield2">
            <input type="text" id="email" name="email" value='<?php echo $email?>'/>
            <span class="textfieldInvalidFormatMsg">A valid email is required.</span><span class="textfieldRequiredMsg">An email address is required.</span></span></p>
        </blockquote></td>
        </tr><tr><td><blockquote>
          <p><font color=black>Phone</font> (not required)<br/>
            <span id="sprytextfield3">
            <input type="text" id="Phone" name="Phone" value='<?php echo $Phone?>'/>
            <span class="textfieldInvalidFormatMsg">valid format = (123) 456-7890</span></span></p>
        </blockquote></td>
        </tr><tr><td><blockquote>
          <p>*<font color=black>Comments</font><br/>
            <span id="sprytextarea1">
            <textarea name="Comments"><?php echo $Comments?></textarea>
            <span class="textareaMinCharsMsg"><br />
            Minimum number of characters (10) not met.</span><br />
            <span class="textareaRequiredMsg">A comment or question is required.</span></span></p>
        </blockquote></td>
        </tr><tr><td><blockquote>
          <p>

        <input name="submit" type="submit" value="Submit Form" onclick="document.form1.submit.disabled=true;doc ument.form1.submit();">
          * - Required fields</p>
        </blockquote></td>
        </tr></tbody></table></form> &nbsp;</p>
        <font color=red>
        <?php      if ($errorstring!="")
    echo
    "*Please fill out the following fields:<br>$errorstring";
    ?></font>
    <p align="center">&nbsp;</p>
    <p align="center"><img src="/images/customerbanner.jpg" alt="customerbanner" width="728" height="90" border="8" /></p>
    <p align="center"><em><font color=black>Copyright © 2005-2008[www.business.com] All 
      rights reserved.</font></em> </i></p>
        <p align="center"><i><font color=black>Revised: 12/18/09</font></i></p>
        <p>&nbsp;</p>
        <!-- end #mainContent --></div>
    <!-- end #container --></div>
    <script type="text/javascript">
    <!--
    var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"SpryAssets/SpryMenuBarDownHover.gif", imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "none", {validateOn:["blur", "change"], minChars:3});
    var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "email", {validateOn:["blur", "change"]});
    var sprytextarea1 = new Spry.Widget.ValidationTextarea("sprytextarea1", {validateOn:["blur", "change"], minChars:10});
    var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "phone_number", {isRequired:false, validateOn:["blur"], hint:"(123) 456-7890"});
    //-->
    </script>
    </body>
    </html>
    Last edited by 24seven; 12-21-2009 at 07:00 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •