Page 1 of 1

Retain Values in Filelds

Posted: Sun Jul 28, 2002 9:27 am
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

Posted: Sun Jul 28, 2002 10:49 am
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>

Posted: Sun Jul 28, 2002 12:21 pm
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

Posted: Wed Oct 16, 2002 1:11 am
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" />