tags:

views:

91

answers:

1

Hello Gurus I created this layout of successive text input fields, 1- Enter data into empty fields 2- Click on button which submits to a php page that updates into database

Now the problem is that i want when i return to the main page again the empty field is replaced with data just added but there are still other empty fields to enter new data. How can i establish that?

Thanks in advance.

+1  A: 

You haven't given a lot of detail but here goes!

You could build your inputs like this:

<input type="text" name="age"  value="<?php echo $age;  ?>">

When the form first loads, it won't have values for variables like $age, so the input will appear empty. Have the form submit via POST to the same PHP file, run your validation checks, and if everything passes, insert into to your database. (Is it required that you write to the database at this point, or should it wait until the second section is filled out?)

You'll need to use some kind of conditional statement to display the second part of the form. Depending on how complex this is, or whether users will be returning later, you could:

  1. Read the data back out of the database to check for completeness, and then display the second part.
  2. Set a variable to track what stage of the form you're in, and based on that, display different sections to be completed.


If you have a way of tracking what stage of the process you're in, you could do something like this:

$formStage = 2;
function isReadOnly($formStage='')
{
    if ($formStage == 2) {echo 'READONLY';}
}

and then in your HTML:

<INPUT NAME="realname" VALUE="Hi There" <?php isReadOnly($formStage)?>>
Kyle Ridolfo
Very nice answer Kyle i added it and it worked but if i want to return the field disabled to prevent editing how can this be done?
Sarah
You need to set the HTML attribute to "readonly" or "disabled". It's slightly different if you are using XHTML for the doctype. See this link:http://www.htmlcodetutorial.com/forms/_INPUT_DISABLED.htmlIf you use readonly on the input, it will still be submitted with the second form. A malicious user could still modify the form and resubmit, so make sure you're ignoring these values in your PHP code for the second step.
Kyle Ridolfo
I don't understand Kyle ,I just want when i submit and data retrieved i want it to return in disabled field
Sarah