467,868 Members | 1,330 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,868 developers. It's quick & easy.

returning to signup form

hi

i have a basic signup POST form, with php on the same page. how do i
return to this page with all the entries still present, yet with a
message at the top, for when the user enters one invalid entry?

cheers
dave
Jul 17 '05 #1
  • viewed: 2023
Share:
3 Replies

"David" <da********@gmail.com> schreef in bericht
news:f3**************************@posting.google.c om...
hi

i have a basic signup POST form, with php on the same page. how do i
return to this page with all the entries still present, yet with a
message at the top, for when the user enters one invalid entry?

cheers
dave


I consider you will write to a database in the same php page and then
redirect to another page

Put this in the top of your page:

if($Submit) { // Submit is the name of your submit button

if(!$name || !$street) { # if for example name or street not filled in
# generate errormessage
if(!$name) {$err .= "Name not filled in";}
if(!$street) {$err .= "Street not filled in";}
} else {

# alle input ok, here you can put your sql queries to interact
with the database

header("Location: nextpage.php");
exit;
}

}

Marcel
Jul 17 '05 #2
While the city slept, David (da********@gmail.com) feverishly typed...
hi
Ay up,
i have a basic signup POST form, with php on the same page. how do i
return to this page with all the entries still present, yet with a
message at the top, for when the user enters one invalid entry?


If you are posting the results to the page, then write them into the default
values for the input elements. Something like;

<html>
<head>
<!-- head stuff here -->
</head>
<body>

<?php

$defaultName = "Enter your name here"
$defaultEmail = "Enter your email address here"
$formError = false;

if($_POST['update'] == 1) {
$name = $_POST['name'];
$email = $_POST['email'];
if(($name == "") || ($email == "")) {
$formError = true;
print("<p>Error on form.</p>");
if($name == "") {
print("<p>Please enter a value for Name</p>");
}
else {
$defaultName = $name;
}
if($email == "") {
print("<p>Please enter a value for Email Address</p>");
}
else {
$defaultEmail = $email;
}
}
else {
print("<p>Thanks for your input!</p>");
// write the form contents to your database, or whatever
}
}

if ((!isset($update)) || ($formError)) {
?>

<form action = "thispage.php?update=1" method="post">
<p>Name: <input type="text" name="name" value="<?=$defaultName?>"></p>
<p>Email Address: <input type="text" name="email"
value="<?=$defaultEmail?>"></p>
<input type = "submit" name="submit" value="Submit">
</form>
<?
}
?>

</body>
</html>

.... Note: This is straight off the top of my head! Not tested or anything!

Hope that helps,
Nige

--
Nigel Moss
http://www.nigenet.org.uk
Mail address not valid. ni***@DOG.nigenet.org.uk, take the DOG. out!
In the land of the blind, the one-eyed man is very, very busy!
Jul 17 '05 #3
think i get it now. cheers guys

dave
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Dustin | last post: by
2 posts views Thread by .Net Sports | last post: by
reply views Thread by jon | last post: by
2 posts views Thread by fredtbx | last post: by
2 posts views Thread by nazgul42 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.