need help with simple script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vision2003
Forum Newbie
Posts: 1
Joined: Thu Aug 29, 2002 9:52 pm

need help with simple script

Post 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
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

depends

Post 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:
ReDucTor
Forum Commoner
Posts: 90
Joined: Thu Aug 15, 2002 6:13 am

Post 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;
?>
Post Reply