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

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
habeeb
Forum Newbie
Posts: 2
Joined: Thu Aug 14, 2003 2:37 pm

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

Post 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
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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
habeeb
Forum Newbie
Posts: 2
Joined: Thu Aug 14, 2003 2:37 pm

Post 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:
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
Coco
Forum Contributor
Posts: 339
Joined: Sat Sep 07, 2002 5:28 am
Location: Leeds, UK
Contact:

Post 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()) )
User avatar
genetix
Forum Contributor
Posts: 115
Joined: Fri Aug 01, 2003 7:40 pm
Location: Sask, Regina
Contact:

Post 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>
Post Reply