Page 1 of 1

Re-enterant forms using php (redisplay vales entered by user

Posted: Thu Aug 14, 2003 2:37 pm
by habeeb
Hello!

I would appreciate if someone could post a complete example (html + php code) which tells how to re-display values entered by a user in a form without using javascript

Thanks in advance

Habeeb

Posted: Thu Aug 14, 2003 3:03 pm
by m3rajk
what version of php? 4.1 and after work differently than previous to 4.1.


what have you done to try this on your own? go find twig's link about questions. one thing that people here don't seem to like is when someone's done nothing. if you're asking for ideas sometimes they'll give you ideas, but when you ask for them to spend time to give you actual code, then you are liktley to be ignored at best

Posted: Mon Aug 18, 2003 11:09 am
by habeeb
I am using version 4.2.2.

Here is my code:

<html><body>

<?php

$myself = $_SERVER["PHP_SELF"];
echo ("myself: " . $myself);

?>

<form method="post" action= "<?php echo ("$myself"); ?>" > <div>

Name: <input type="text" name="myname" value="<?php echo ("$myname");?>" >

City: <input type="text" name="city" value="" >

<input type="hidden" name="os" value="ds">
<input type=submit value="Go!"></div>

<?php

$myname = $_POST["myname"];
echo ("myname: " . $myname);

$city = $_POST["CITY"];

$os = $_GET["os"];
if(!(isset($os))) {
$os = $_POST["os"];
}

$submit = $_POST["submit"];


?>

</form>



</html></body>


I am trying to re-display the name when user clicks on Go! again. It does not seem to work. Please help as it is a show stopper for me.

TIA habeeb :twisted:

Posted: Mon Aug 18, 2003 11:12 am
by JayBird
You code looks okay, but you have to stuff in the wrong order, i.e. using varaibles before you have set them

Try this

Code: Select all

<html><body> 

<?php 

$myname = $_POST["myname"]; 
echo ("myname: " . $myname); 

$city = $_POST["CITY"]; 

$os = $_GET["os"]; 
if(!(isset($os))) { 
$os = $_POST["os"]; 
} 

$submit = $_POST["submit"]; 

?> 

<form method="post" action= "<?php echo $PHP_SELF; ?>" > <div> 

Name: <input type="text" name="myname" value="<?php echo $myname; ?>" > 

City: <input type="text" name="city" value="" > 

<input type="hidden" name="os" value="ds"> 
<input type=submit value="Go!"></div> 

</form> 



</html></body>
I have changed your code slightly too :D

Mark

Posted: Mon Aug 18, 2003 6:14 pm
by Coco
i find that something along the lines of:

Code: Select all

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

?>
normally works well in a case like this (and if you have your error reporting turned off/down you can get rid of the if(isset()) )

Posted: Mon Aug 18, 2003 8:03 pm
by genetix
I dont think that one version will work. You have to either put the form before the process or make a loop dont you? ex:


Code: Select all

<html><body> 

<?php 
if($_POST['myname'])
{

$myname = $_POST["myname"]; 
echo ("myname: " . $myname); 

$city = $_POST["CITY"]; 

$os = $_GET["os"]; 
if(!(isset($os))) { 
$os = $_POST["os"]; 
} 

$submit = $_POST["submit"]; 

}
else
{

?> 

<form method="post" action= "<?php echo $PHP_SELF; ?>" > <div> 

Name: <input type="text" name="myname" value="<?php echo $myname; ?>" > 

City: <input type="text" name="city" value="" > 

<input type="hidden" name="os" value="ds"> 
<input type=submit value="Go!"></div> 

</form> 

<?
}
?>


</html></body>