Forum Moderators: coopster

Message Too Old, No Replies

maintaining data in a form

         

bablu

8:38 am on Mar 16, 2011 (gmt 0)

10+ Year Member



i want to upload a file,i have form and whenever i click upload button and upload file..the data written in a form is lost..i have to fill the data again..how to maintain the data in a form?whenever i go 2 one form 2 another form....

Matthew1980

3:02 pm on Mar 16, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there bablu,

This is something that can only be done IF the form has been submitted and the $_POST or even $_GET arrays have state & value, once you have made sure that is the case, you can then assign those values to your form so that it looks like the form has 'remembered' the data entered - you could use $_SESSION data too, especially if you want to move the information over sets of pages. You can make this a complex as you like, but that's up to you ;)

The simplest example is this:

<input type="text" name="first_name" value="<?php echo (isset($_POST['first_name']) ? strip_tags($_POST['first_name']) : '' );?>" />


Again, this checks to see if the array has state, then uses the data from the form to populate it, but if nothing is set, nothing is echoed out...

Hope that makes sense.

Cheers,
MRb

usmc wlh1975

1:59 pm on Mar 17, 2011 (gmt 0)

10+ Year Member



When you go to the post php you can generate a set of hidden fields on the next dhtml page which will keep the data for you until your final post where you are ready to use it.

There is almost always more than one answer to any problem.

Matthew1980

3:18 pm on Mar 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




When you go to the post php you can generate a set of hidden fields on the next dhtml page which will keep the data for you until your final post where you are ready to use it.


Only if it's set! Hidden fields can cause problems too, having data stored in $_SESSION would be better.

But as you correctly state - there is more than one way of doing this.

Cheers,
MRb

usmc wlh1975

3:40 pm on Mar 17, 2011 (gmt 0)

10+ Year Member



No disagreement with that.

rocknbil

4:03 pm on Mar 17, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



whenever i go 2 one form 2 another form....


Depending on the complexity,

A few fields - data persistence as mentioned using post, or hidden data as mentioned (if set), or cookies, or session variables.

lots of data - I prefer a database but you can use temporary plain text files, which remain connected to the client via cookies or sessions. Sessions can also be used for this too, but for reasons of logging and debugging, storing the data in a database is often helpful.