|
Posted by J.O. Aho on 12/15/05 11:37
number1.email@gmail.com wrote:
> I have a Web Page in which the user inputs their name, then fills out a
> questionairre.
>
> When they hit the "Submit" Button, the user is taken to another Web
> page which provides the responses of other users to the same
> questionairre. They are then given the option to click on a "Submit"
> Button on this Second Web Page and go back to the original
> questionairre to fill out some further details. The problem is:
>
> 1) When the user first visits the questionairre, I would like to
> provide a text field so that they can enter in their name.
if(empty($_REQUEST['username']) {
/* We don't have an username */
echo "Your name: <input type='text' value='' name='username'>";
} else {
echo "Welcome back ".$_REQUEST['username']."you can fill out further details
now<br>\n";
echo "<input type='hidden' value='".$_REQUEST['username']."' name='username'>";
}
> 2) I would like to save this name in a hidden field or something
> similar, and when they go to the second page say something like "Thanks
> <username> for filling out the survey".
if(!empty($_REQUEST['username']) {
/* We have an username */
echo "Thanks ".$_REQUEST['username']."for filling out the survey<br>\n";
echo "<input type='hidden' value='".$_REQUEST['username']."' name='username'>";
} else {
/* no username here, then they shouldn't be here */
header("Location: http://www.example.com/");
exit;
}
> 3) When they click on the Submit Button on the Second Web Page (ie:
> taking them back to the Original Questionairre to fill out more
> details), I would like to not provide the text field they saw when they
> first visited this page, but rather say something like "Welcome back
> <username> you can fill out further details now".
See #1.
> Seems pretty simple, but I'm having a problem getting the hidden fields
> in my HTML and php code to work and not give me error messages that the
> variables don't exist, etc. Maybe there is a better way than hidden
> fields. Can someone provide me with some code that will work for this?
Hidden fields has to be inside the <form> tags, if you have more than one
submit button, then you need to create a wrapper page that checks which button
has been pushed and redirects the request to the right page (or includes the
right page code, of has both codes in it already and selects which part to use
with if-statement).
Today PHP comes with global variables turned off, this for security reasons,
so you have to move the variables manually
$username=$_REQUEST['username'];
A good thing to do, is to check that the value in the $_REQUEST array is
valide before populating the variable, specially if you are using it directly
into the mail() function, as otherwise spammers can use your form to spam the
world even if you have set a fixed TO: address.
//Aho
Navigation:
[Reply to this message]
|