0

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.

2
  • 1
    Can explain a bit more in Detail.. Commented Oct 18, 2009 at 10:29
  • I want to add an image for elaboration but i don't know how? Commented Oct 18, 2009 at 11:57

1 Answer 1

1

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)?>>
Sign up to request clarification or add additional context in comments.

3 Comments

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?
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:htmlcodetutorial.com/forms/_INPUT_DISABLED.html If 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.
I don't understand Kyle ,I just want when i submit and data retrieved i want it to return in disabled field

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.