0

I need a bit of advice. I've tried searching on here and Google but I've had no luck.

I have created a form in PHP. It has 32 fields containing a variety of text boxes and select boxes. When the user clicks submit they're taken to a new page where they can see the data they have entered. If they have made a mistake they have to click back to the form. Then they have to re-enter all of their data rather than just changing the incorrect field.

I'm a newbie and willing to try new things.

Thanks for any advice,

Dave

Robert K
  • 30,064
  • 12
  • 61
  • 79
  • 1
    Client-side validation, it's [helpful](http://stackoverflow.com/questions/162159/javascript-client-side-vs-server-side-validation). – raina77ow Mar 29 '13 at 18:17
  • 1
    I agree with @raina77ow but it should be only used for making the website look more fancy and helping the user. The php always need to check it before it goes into a database or such. – JochemQuery Mar 29 '13 at 18:29

1 Answers1

1

When the form is posted you can save it in the session like so:

$_SESSION['form'] = $_POST['form'];

And then when on the fill-out-the-form page, you can set the default values of the inputs:

<input type="text" name="form[name]" value="<?php echo isset($_SESSION['form']['name']) ? $_SESSION['form']['name'] : ''; ?>">
Michael
  • 11,912
  • 6
  • 49
  • 64
  • This does assume that you've [started](http://php.net/session_start) the session though. – Robert K Mar 29 '13 at 18:25
  • when you say ['name'] do you mean the name of the field. sorry for being not very inteligent – David Roberts Mar 30 '13 at 22:21
  • Yes, the name of the field. So if it's a username you'll do `name="form[username]"`, get it with `$_POST['form']['username']` and set the session as `$_SESSION['form']['username']`. (I prefixed them all with `form` to avoid possible clashes with other `$_SESSION` variables.) – Michael Mar 30 '13 at 22:22
  • Im trying to do this with out be a Nag and keep asking questions. I'm not sure why this is not working from what i can gather from the answers Iv been given. so this is what i have in one of my txt boxes is this right?? – David Roberts Mar 30 '13 at 22:45
  • Change `$_SESSION['form']['Game'])` to `$_SESSION['form']['game'])`. It's case-sensitive. – Michael Mar 30 '13 at 22:49