Page 1 of 1

Retain value of a html form

Posted: Mon Oct 10, 2005 12:19 pm
by unplugs
Hi,

I'm facing a problem as regarding to the topic above.


Currently, I have a registration.html and registration.php. Registration.html will receive user input and will submit to registration.php when user clicks on "submit" button. The validation will perform in the registration.php file.

The problem that I encountered is, when there is error in the form, it will redirect back the user to the registration.html, and all the values in the form gone! Any idea on how to solve this?

Thanks.

Posted: Mon Oct 10, 2005 12:31 pm
by John Cartwright
Just have your processing page and form on the same page (simplest way to do it)
and in each field have along along the lines of

Code: Select all

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

Posted: Mon Oct 10, 2005 8:52 pm
by unplugs
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


hi Jcart,

           yup... I know how to do it when html and php in 1 page. Anyway, I would like to split the html and php into 2 separate files so that I can modify the html easily in future.

          My code is currently like below.

eg:

register.html

Code: Select all

<html>
...
...
<form method="post" action="register.php">
<input type='text' name='username' size='25' maxlength='50'>
<input type='text' name='email' size='25' maxlength='50'>
...
<input type="submit" name="submit" value="Submit">
</form>
</html>

register.php

Code: Select all

<?
    Perform validation.
    chek username, if username=''
              redirect back to register.html;
    else if email=''
              redirect back to regster.html;

    if every fields valid and filled, proceed to register_complete.php
?>


The scenario here is, when user key in their username, and they left email field blank, then when they click "submit" button in register.html, it will bring them to register.php. In register.php, since the email does not fill in, it will redirect the user back to register.html, and the register.html should retain the username data that they key in.

How can i solve this?

Thanks.


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Mon Oct 10, 2005 9:09 pm
by feyd
you have to involve php in some way in the html.