Retain value of a html form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
unplugs
Forum Newbie
Posts: 2
Joined: Mon Oct 10, 2005 11:48 am

Retain value of a html form

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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'] : ''); ?>">
unplugs
Forum Newbie
Posts: 2
Joined: Mon Oct 10, 2005 11:48 am

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you have to involve php in some way in the html.
Post Reply