Jump to content

I'm being really dim here but can someone advise the code for form memory


bladechob

Recommended Posts

I need to get a submit form to 'remember the registration details so that if a visitor is filling in a form and misses a required field or puts in a malformed e-mail address that when they return to the form it has retained their earlier inputted stuff i.e. they don't have to go through the process of re-entering stuff all over again.

Thanks :-*
Link to comment
Share on other sites

if you mean for form validation then what you need to do is start the forms with values that are null and ERROR=FALSE. then after a form is submitted run through it and check for errors then return ie ERROR=TRUE if there is an error. Here you will get the values from your post information and then set the values in the form as these.
Link to comment
Share on other sites

My first post -- yay! :)

It sounds like you want a sticky form, a kind of form that will alert the user that they did something wrong (like not filling in a form element) upon submission, without bringing them to an error page.  I made a simple one in my own attempts at learning PHP that seems to work well.  Of course, you'll need to modify it for your specific purpose, but it's simple enough to modify easily.  I recommend using regular expressions in the test statements, though.  I was using JavaScript to do it as a test exercise, but that's not a secure method of validation.  The files I include in my code (header.inc and footer.inc) are just basic XHTML.  They only contain the header info (like page title, any CSS, that sort of thing) and the closing tags for the footer (</body> and </html>).  Hope this helps!

[code]<?php

$page_title = 'Sticky Form Test';
include('header.inc');

$message = NULL;

if(isset($_POST['submit'])){
  if(empty($_POST['username'])){
      $u = FALSE;
      $message .= "Please input your username!<br />";
  }

  else {
      $u = $_POST['username'];
  }

  if(empty($_POST['password'])){
      $p = FALSE;
      $message .= "Please input your password!<br />";
  }

  else {
      $p = $_POST['password'];
  }

  if(empty($_POST['email'])){
      $e = FALSE;
      $message .= "Please input your e-mail address!";
  }

  else {
      $e = $_POST['email'];
  }

  if($u && $p && $e){
      echo "You correctly submitted everything!";
  }
}

?>

<form id="inputform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  <fieldset class="narrow"><legend>Please input your information</legend>
      <p><label for="username">Name:</label><input name="username" id="username" type="text" class="txt" value="<?php if(isset($_POST['username'])) echo $_POST['username']; ?>" /></p>
      <p><label for="password">Password:</label><input name="password" id="password" type="password" class="txt" /></p>
      <p><label for="email">E-mail Address:</label><input name="email" id="email" type="text" class="txt" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>"/></p>
      <p><input type="submit" name="submit" id="submit" value="Submit" /></p>
  </fieldset>
</form>

<?php
if(isset($message)){
  echo "<div style='color: #FF0000;'>$message</div>";
}

include('footer.inc');
?>[/code]
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.