Hi,
I'm completely new to PHP so go easy.
I took a look at "A Beginning Forms Tutorial -- by Sean Driscoll"
but got lost.
Does all code go on one page, several pages, how should the pages be labelled?
Regards,
Herman
need help with simple script
Moderator: General Moderators
It go's to where you specify the action attribute in the form tag to direct it to, or if non is specified it will use the current page.
If you want to use the current page, you can just check the variables before showing data, if a variable is set then show content, if not show form, e.g.
Although you can do my prefered multi-part page method
If you want to use the current page, you can just check the variables before showing data, if a variable is set then show content, if not show form, e.g.
Code: Select all
<?php
if(!empty($name))
{
print "Thanks for submitting, <b>$name</b>";
}
else
{
print "<form method=post>";
print "Name: <input type=text name=name><br>";
print "<input type=submit value="Go Go Go">
print "</form>";
}
?>Code: Select all
<?php
function thank()
{
global $GLOBALS;
extract($GLOBALS);
print "Thanks for submitting, ".$f_name." ".$l_name;
}
function getlastname()
{
global $GLOBALS;
extract($GLOBALS);
print "<form method=post>";
print "<input type=hidden name=action value=thank>";
print "<input type=hidden name=f_name value="$f_name">";
print "Name: $f_name <input type=text name=l_name"><br>";
print "<input type=submit value="Go Go Go"></form>";
}
function getfirstname()
{
print "<form method=post>";
print "<input type=hidden name=action value=getlast>";
print "Name: <input type=text name=f_name><br>";
print "<input type=submit value="Continue"></form>";
}
switch($action)
{
case "thank":
thank();
break;
case "getlast":
getlastname();
break;
default:
getfirstname();
}
?>