Retain Values in Filelds

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
User avatar
maskme
Forum Newbie
Posts: 6
Joined: Sun Jul 28, 2002 9:27 am

Retain Values in Filelds

Post by maskme »

Hi !

When a field (say textbox, checkbox) is not satisfying a condition. I set the variable $msg with the error msg & redirect to the form page where the field(s) are. The error shows but then if there is something in the text, or checkbox, or option button, the person has to re-fill the form again. Is there a way dat i can retain the values stored in the textbox as well as show my error msgs too with header function or with some other function (if available) or some other way dat i can do it :?:

Code: Select all

header(&quote;Location: register.php?error=&quote;.urlencode($msg));
thanx
Hoping 4 a postive response
Yusuf
User avatar
PaTTeR
Forum Commoner
Posts: 56
Joined: Wed Jul 10, 2002 7:39 am
Location: Bulgaria
Contact:

Post by PaTTeR »

Hi maskme,
you can use something like this simple example :

file form.inc:

Code: Select all

<form action="handle_form.php" method="POST">
<input type="hidden"  name="send" value="1">
<input type="text" name="name" value="<?php echo $HTTP_POST_VARS&#1111;name] ?>"><br>
<input type="text" name="email" value="<?php echo $HTTP_POST_VARS&#1111;email] ?>"><br>
<input type="submit">
</form>
file handle_form.php

Code: Select all

<?php

if (!isset($HTTP_POST_VARS&#1111;send]) &#123;
    include 'form.inc';
&#125;

// here is your code for error check
// if have error $msg is set

if (isset($msg)) &#123;
    echo $msg . '<br>';
    include 'form.inc';
&#125; else &#123;
    // do somethig with submited values
    echo 'You request is stored.';
&#125;

?>
And link to form is

Code: Select all

<a href="handle_form.php">Fill the form</a>
User avatar
maskme
Forum Newbie
Posts: 6
Joined: Sun Jul 28, 2002 9:27 am

Post by maskme »

Hi thanz for the tip

One more question:
How do u retain the values in the select list & option buttons

THank u in advance
Takecare bye
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

(hopefully getting the point of your question ;) )

Code: Select all

<select....>
   <option value="...">...</option>
   <option value="..." selected="true">...</option>
   <option value="...">...</option>
</select>
<input type="checkbox" name="..." checked="true" />
Post Reply