|
Posted by Pedro Graca on 01/21/06 01:17
chris_fieldhouse@hotmail.com wrote:
> is it possible for a php script which is used to
> validate values submitted in a form, to then post these values onto
> another script/page or even back to the calling form?
>
> i.e. the application I have in question is a login.htm page with a
> verify.php script
> The login.htm has a Form which captures login_id and password which are
> posted to verify.php
>
> verify.php checks the id and password against the database.
> if the check succeeds I use $_SESSION to track the logged in user into
> the page.
> if the check fails, I use $_SESSION["error"] to set an error message
> and then jump to login.htm, but I've lost the userid.
use $_SESSION to save the userid and the error message
<?php
if ($check_failed) {
$_SESSION["error"] = "Check failed. Please try again.";
$_SESSION["userid"] = $userid;
}
?>
> The only way I can see of transferring the userid (and some other data)
> is by calling header ("Location: login.htm?id=$uid");
> and then have some php code in login.htm to $GET['uid'] and pop that
> into the user field on the form.
>
> Is there any easy way I can post this data back without using a <FORM>
> or at least a form that can be auto-submitted?
With the $_SESSION array.
If your web server isn't set up to call PHP for htm pages (it shouldn't)
change your login.htm to login.php first.
The first time a user calls login.php, $_SESSION is empty.
After a login failure $_SESSION has the error message *and* the userid
<?php // login.php
if (isset($_SESSION["error"])) {
echo '<p class="error">', $_SESSION["error"], '</p>';
}
// ...
echo '<input type="text" name="userid"';
if (isset($_SESSION["userid"])) {
echo ' value="', $_SESSION["userid"], '"';
}
echo '/>';
?>
--
If you're posting through Google read <http://cfaj.freeshell.org/google>
Navigation:
[Reply to this message]
|