Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Form data reposting

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Form data reposting

Postby ericaustin » Wed Feb 05, 2003 3:35 pm

I am having a problem with form data being wiped out when a page reloads itself. Below is a sample script as a trivial example. There is a checkbox named "true" and a text box named "saveme". If "true" is checked, the input is valid and all is great. If "true" is not checked, inform the user of the problem and allow them to alter and resubmit the form. My issue is that the text box named "saveme" is wiped clean when the script calls itself. I have a form with about 35 inputs on it. If there is just one error, the user must re-enter all 35 inputs. How can inform the user of the input validation error and repost the form for editing with all previously entered data in place?

Thanks,
Eric

Code: Select all
<?php
session_start();
if (!isset($_POST['submit'])) {
  if (isset($_SESSION['msg'])) {
    print $_SESSION['msg'];
  }
  ?>
  <form method=POST action=<?php $_SERVER['PHP_SELF']; ?>>
    True? <input name=true type=checkbox value=true />
    <input name=saveme type=text>
    <input type=submit name=submit value=Submit />
  </form>
  <?php
}
else {
  if ($_POST['true'] == 'true') {
    print "Success!";
    unset($_SESSION['msg']);
  }
  else {
    $_SESSION['msg'] = "Must Check True";
    header("Location: test.php");
  }
}
ericaustin
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Feb 05, 2003 3:25 pm

Postby Redcircle » Wed Feb 05, 2003 4:39 pm

you have to add values to the input tags

Code: Select all
<input type="text" name="form_field" value="<?php if(isset($_POST['form_field'])) echo $_POST['form_field']; ?>">


that way if they did not do something required it will put all the information back into the form.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.