Jump to content

Archived

This topic is now archived and is closed to further replies.

JackJack

Form Troubles

Recommended Posts

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

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

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

Please help

JJ

Share this post


Link to post
Share on other sites
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

[code]
$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;
}
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.