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 2 of 2
  1. #1
    Regular Coder Andy92's Avatar
    Join Date
    Nov 2005
    Location
    Horsham, West Sussex, UK
    Posts
    363
    Thanks
    7
    Thanked 1 Time in 1 Post

    Redirect in javascript, but save the form data that you submitted?

    Hi there,

    I have 2 files. Index.php and send.php.

    In the index.php i have in the middle...

    PHP Code:
    <?php
          $sent 
    $_GET['sent'];
          if (
    $sent == 1) { echo "<div class='text_bold'>Thank you $name for contacting Will. I will reply to your email asap!</div><br />";
          } else {
          echo 
    "";
          }
          
    $error $_GET['error'];
          if (
    $error == 1) { echo "<span class='n_error'>You have not entered a name!</span><br /><br />";
          } else if (
    $error == 2) { echo "<span class='n_error'>You have not entered a email address!</span><br /><br />";
          } else if (
    $error == 3) { echo "<span class='n_error'>You have not entered a subject!</span><br /><br />";
          } else if (
    $error == 4) { echo "<span class='n_error'>You have not entered a message!</span><br /><br />";
          } else {
          echo 
    "";
          }
          
    ?>
          <div class="large_col">
        <div class="large_top_header">Contact Will  Form:</div>
        <div class="large_bottom_text">
        <form action="/contact/will/send.php" method="post" name="will" id="will">
        <table width="100%">
          <tr>
            <td><div><div class="text_bold">Name: <span class="text_link_colour">*</span></div></div></td>
            <td width="83%"><input name="name" type="text" id="name" style="width: 475px;" maxlength="100" /></td>
          </tr>
          <tr>
            <td><div><div class="text_bold">Email: <span class="text_link_colour">*</span></div></div></td>
            <td><input name="email" type="text" id="email" style="width: 475px;" maxlength="100" /></td>
          </tr>
          <tr>
            <td><div><div class="text_bold">Subject: <span class="text_link_colour">*</span></div></div></td>
            <td><input name="subject" type="text" id="subject" style="width: 475px;" maxlength="200" /></td>
          </tr>
          <tr>
            <td width="17%" height="17"><div><div class="text_bold">Message: <span class="text_link_colour">*</span></div></div>          </td>
            <td rowspan="2"><textarea name="message" rows="10" id="message" style="width: 475px;"></textarea></td>
          </tr>
          <tr>
            <td height="50">&nbsp;</td>
          </tr>
          <tr>
            <td height="17" colspan="2"><span class="text_link_colour">*</span> = Required Field</td>
            </tr>
          <tr>
            <td height="23" colspan="2"><div align="center">
              <input name="Send" type="submit" id="Send" value="Send!" />
            </div></td>
          </tr>
        </table>
        </form>
        </div>
        </div>
    Then in the send.php page i have the form processing...

    PHP Code:
    <?php
    @extract($_POST);
    $name stripslashes($name);
    $email stripslashes($email);
    $subject stripslashes($subject);
    $message stripslashes($message);
    if (!
    $name) {echo
    "<script language='JavaScript' type='text/javascript'>
      <!--
      window.location.href = '/contact/will/index.php?error=1'
      //-->
      </script>"
    ;
     } else {
    if (!
    $email) {echo
    "<script language='JavaScript' type='text/javascript'>
      <!--
      window.location.href = '/contact/will/index.php?error=2'
      //-->
      </script>"
    ;
     } else {
    if (!
    $subject) {echo
     
    "<script language='JavaScript' type='text/javascript'>
      <!--
      window.location.href = '/contact/will/index.php?error=3'
      //-->
      </script>"
    ;
     } else {
    if (!
    $message) {echo
     
    "<script language='JavaScript' type='text/javascript'>
      <!--
      window.location.href = '/contact/will/index.php?error=4'
      //-->
      </script>"
    ;
     } else {

    mail("will@allsortshop.com",$subject,$message,"From: $name <$email>");
    echo 
    "<script language='JavaScript' type='text/javascript'>
      <!--
      window.location.href = '/contact/will/index.php?sent=1'
      //-->
      </script>"
    ;
    }
    }
    }
    }
    ?>
    Basically, if you forget to type in a subject on the form, it wil redirect you to http://www.allsortshop.com/contact/w...ex.php?error=3

    Then the error message will show up. But the form data would be lost?

    If it would have just displayed an error message on the send.php page and then if you would have clicked back on your mouse all the form data would be there.

    So my question is, is there anyway to save the form data only for about 10 minutes in a cookie or something so that when they click submitt and if there is an error message and it redirects them, the form data would still be there? (but the data would only be saved in a cookie of something for a short period of time)?

    Is there any way to do this with javascript?

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    That's a rather unique way to validate a form.
    Why did you choose this design?

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

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