Page 1 of 1

need help with simple script

Posted: Thu Aug 29, 2002 9:52 pm
by vision2003
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

depends

Posted: Thu Aug 29, 2002 11:11 pm
by AVATAr
where code goes, depends on what do you want to do...

Often you use many pages to modularize the scripts, or make units... so you can do what you want..

:wink:

Posted: Thu Aug 29, 2002 11:50 pm
by ReDucTor
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.

Code: Select all

<?php
if(!empty($name))
&#123;
print "Thanks for submitting, <b>$name</b>";
&#125;
else
&#123;
print "<form method=post>";
print "Name: <input type=text name=name><br>";
print "<input type=submit value="Go Go Go">
print "</form>";
&#125;
?>
Although you can do my prefered multi-part page method

Code: Select all

<?php
function thank()
&#123;
global $GLOBALS;
extract($GLOBALS);
print "Thanks for submitting, ".$f_name." ".$l_name;
&#125;

function getlastname()
&#123;
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>";
&#125;

function getfirstname()
&#123;
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>";
&#125;

switch($action)
&#123;
case "thank":
   thank();
   break;
case "getlast":
   getlastname();
   break;
default:
   getfirstname();
&#125;
?>