Forum Moderators: open

Message Too Old, No Replies

Register Forms and Information

Keeping Info in forms on changes

         

Mcadieux

1:06 am on Jan 16, 2005 (gmt 0)

10+ Year Member



Hi everybody,

This is probably a very simple question but it has me going nuts. I have a Form on my website that takes all the fields and on submission sends them to a PHP script. If some of the information is wrong it reshows the page and says what info needs to be changed. When it does this though it erases all the forms entrys. My registration is fairly long and I personally think this is one of the most annoying things a site can do. I have researched this everywhere and can't find any hints, can anybody help me?

txbakers

2:30 am on Jan 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What you can do is set the value attribute of each form text box to the corresponding Request object.

I'm not sure how in PHP but in ASP is looks like this:

<input type="text" name="fname" size="20" value="<%=Request("fname")%>">

If the Request object is blank, then the object will be blank.

Mcadieux

3:39 am on Jan 16, 2005 (gmt 0)

10+ Year Member



I don't think ASP is like what the PHP code could be but it gives me something else to search for thanks. This is truly going to drive me insane.

Mcadieux

3:50 am on Jan 16, 2005 (gmt 0)

10+ Year Member



Ok, I figured out that if I add "<?php echo $name;?>" to the name field that it will return the data. The problem is that when you first load the form it shows "<?php echo $name;?>" in the form field. So how do I make that invisible the first time they load the form when there's no data in the field.

txbakers

4:32 am on Jan 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I take it the page itself is not a PHP page.

You can make it a .PHP instead of .HTML and it will hide it (I think)

or there must be some kind of ternary operator for PHP like the IIF in VBScript.

Mcadieux

5:55 am on Jan 16, 2005 (gmt 0)

10+ Year Member



Made the page .php and it worked perfect thanks alot for the help.

CanadianChris

6:20 am on Jan 16, 2005 (gmt 0)

10+ Year Member



It's really easy to do this in php. The following code is an example of form data that I typically use. The form uses php to check and see if the form data has been declared, and if so it fills the textbox with that data automatically. It takes a fair bit of coding for this to work properly, but it works very very well:


<form method=post action="">
<?PHP
print "<input type=text name=\"textfield1\"";
if($_POST['textfield1']) print " value=\"" . $_POST['textfield1'] . "\"";
print ">";
?>
</form>