Conceptual ?: using 'multi-purpose' form for validation
| From: | Whil Hentzen | Date: | Sun, 26 Sep 2004 03:22:31 +0000 |
| Subject: | Conceptual ?: using 'multi-purpose' form for validation | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-197851@lists.php.net to get a copy of this message | ||
I can get a single form to call itself again if there's nothing fancy going
on. This code will prompt the user for their mail if it doesn't already
exist, and if the email does exist, provides some data out of database.
<?php if ( !isset($_POST['email']) ): ?>
<!-- No email, so prompt the user for one.-->
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
Login: <input type="text" name="email" />
<input type="submit" value="GO" />
</form>
<?php else: ?>
<p>Data for email: <?=$_GET['email']?></p>
// do some database stuff and display the results
<?php endif; ?>
I'd like to validate the email that was entered against a database - if the
email address is found, continue on with the ELSE code. If not found, though,
run the IF section again.
Conceptually I'm missing how to do that. I've done it in two pages, where the
form action calls a second PHP page, and the code in that second page looks
for the address and displays one result or another depending on if it's
found.
How do I do this in one page, if it's appropriate and practical (i.e. good
coding) to do so?
Thanks,
Whil