Page 1 of 1

My form code isn't behaving as expected

Posted: Tue Sep 16, 2003 8:39 am
by Linkjames
Bad code ;)

Ok, the below code is supposed to either present the form, or if the form has been filled, just say "hello", but when I hit submit, it brings the form back up. Any ideas?

Code: Select all

<?php 
if ($c != 1)
{
?>
<form name="form1" action="search.php?=c">
  <input name="search" type="text" id="search" value="Enter search here" size="50">
  <input type="submit" value="Search!">
</form>
<?php
} else if ($c==1) {
echo ("hello");
};
?>
Cheers for any help guys.

Posted: Tue Sep 16, 2003 8:57 am
by JayBird
you arem't setting the value of $c to anything when you submit your form.

Try this

Code: Select all

<?php 
if ($_GET['c'] != 1) 
{ 
?> 
<form name="form1" action="search.php" method="GET">
   <input type="hidden" name="c" value="1">
  <input name="search" type="text" id="search" value="Enter search here" size="50"> 
  <input type="submit" value="Search!"> 
</form> 
<?php 
} else if ($_GET['c']==1) { 
echo ("hello"); 
}; 
?>

Posted: Tue Sep 16, 2003 9:00 am
by Linkjames
Thanks alot, that works great.

Cheers for your help - James

Re: My form code isn't behaving as expected

Posted: Tue Sep 16, 2003 3:37 pm
by m3rajk
althought your problem was solved, you should note that this is wrong:

<form name="form1" action="search.php?=c">



that sets an emtpy variable to c.


& is the seperator between parts of the get /post strings