Jump to content


Photo

Form Troubles


  • Please log in to reply
1 reply to this topic

#1 JackJack

JackJack
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 14 May 2006 - 09:17 AM

I want to create a form (sounds easy). When there is an error like

<?
if($username){
echo "Please type a username";
}
?>

But i want this to appear on the top of the signup page not the next page.

Please help

JJ

#2 alpine

alpine
  • Members
  • PipPipPip
  • Advanced Member
  • 756 posts
  • LocationNorway

Posted 14 May 2006 - 09:40 AM

target your form to itself
set the value of the form elements to contain the respective variable

It's many ways of doing this, here is one example

$show_form = 1;

if(isset($_POST['submit']))
{
$show_form = 0;
$name = $_POST['name'];

if(empty($_POST['name']))
{
  print "Name is missing";
  $show_form = 1;
}
else
{
  // prossess posted name
}
}

if($show_form == 1)
{
echo <<<__HTML_END

<form action="this.php" method="post">

<input type="text" name="name" value="$name" maxlenght="30" />

<input type="submit" name="submit" value="Send Form" />

</form>

__HTML_END;
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users