Page 1 of 1
Passing an array
Posted: Tue Jul 02, 2002 9:17 am
by llimllib
So here's my question to you guys: If you pass a registration form from one page to another, then find that the username is taken, what's the most efficient way to pass that array back to the referer so that the fields will be automagically filled in (by me)? Can you post without writing a curl script to do it? You don't want to use the URL because that information shouldn't be available in the history.
Alternatively, would you check the database from the original page before posting the data? I think that's what I'm leaning towards doing, as it makes everything simpler, but it doesn't seem very elegant to me. Let me know what you think.
Posted: Tue Jul 02, 2002 10:53 am
by mikeq
You don't really have a choice as you will need to post the page for PHP to do any kind of checking, PHP is server based.
You could do the check, if any errors then display a message that tells them to use the back button (values will still be in the form when they use the back button).
or
The php page calls itself, does the checks if any errors redisplays your form populating values that have been passed to it anyway, if no errors maybe call another page using
header("location:newpage.php");
Posted: Tue Jul 02, 2002 1:18 pm
by llimllib
Well, I know. What I wanted to do was to turn red the items that were incorrectly filled out. To do that, instead of using header, you can use CURL to send an array of post variables back to the original page, have it check which ones are erroneous, and display the labels in red. All I was wondering was if anyone knew a better way to do that than I could come up with.
Posted: Tue Jul 02, 2002 2:46 pm
by hob_goblin
ill try to write something to give you the correct idea..
Code: Select all
<?
$action = $_POSTї'action'];
$required = $_POSTї'required'];
if($action == "go"){
if($required != ""){
//execute registration
} else {
echo "<form action="$PHP_SELF" method="POST">
if($required == ""){
//display red input
} else {
echo "<input type="text" name="required" value="$required" />";
}
echo "<input type="hidden" name="action" value="go" />";
echo "<input type="submit" />";
echo "</form>";
}
} else {
?>
<form action="<?=$PHP_SELF;?>" method="POST">
<input type="text" name="required" />
<input type="hidden" name="action" value="go" />
<input type="submit" />
</form>
<?
}
?>
somebody will probably come along and write a more efficient one though
hmmm
Posted: Tue Jul 02, 2002 3:42 pm
by llimllib
Well, the problem is that that script gets really nasty when you're doing complex validation on 15 variables. I was shooting for separating the validation/database insertion into another file, making everything more elegant. To do that, I still don't see any way but using CURL to post the variables back to the original page, but that's a really ugly solution, as it requires me to go back through them again on the referring side.
Posted: Tue Jul 02, 2002 4:10 pm
by DSM
how about making them session variables
Java-Struts
Posted: Wed Jul 03, 2002 2:15 am
by ajaypatil
Java-Struts has a nice validation framework that automatically shows
the same form again if some values are incorrect.
In PHP, we can maybe pack all the input values into a PHP class
object and put it in session.
When form is shown, always fill in the form input fields from
the object in session. First time, when there is no object in session,
simply create a blank object i.e one with all fields blank.
Ajay
Posted: Wed Jul 03, 2002 7:34 am
by llimllib
no kidding, you can put an object in a session? that's hot...