Re: PHP_SELF (code snip)

From: Date: Tue, 31 Jul 2001 16:48:24 +0000
Subject: Re: PHP_SELF (code snip)
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-60449@lists.php.net to get a copy of this message
HI You can figure this out so you can work with one file. It's much easier to maintain. Here is an example. It's a simple RSVP form. ***Change line 100 to use your own email address to receive the information. I wrote this a while back so I'm not bragging about the html format or coding but it works. It uses a more primitive series of IF's to test the input rather than the IF - ELSEIF - ELSE series I described earlier. In this example, remember the first time through, pg is blank (which is <2). Good Luck. <HTML> <HEAD> <TITLE> RSVP </TITLE> </HEAD> <BODY BGCOLOR="WHITE" LINK="BLUE" VLINK="BLUE" ALINK="ORANGE" text=BLACK> <BASEFONT SIZE=3> <DIV ALIGN=CENTER> <TABLE WIDTH=60% BGCOLOR="#0099FF"> <TR><TD> <BR><BR><BR> <? IF($pg=="1")
        {  if ($fi!='' and $last!='' and $em!="")
        {	$pg="2" ;  }
else
        {
if($fi=="")
        { echo "<BR><H3 ALIGN=CENTER><FONT FACE=Sans-serif COLOR=WHITE SIZE=3>Please fill-in your first name.</FONT></H3>" ; } ;
if($last=="")
        { echo "<BR><H3 ALIGN=CENTER><FONT FACE=Sans-serif COLOR=WHITE SIZE=3>Please fill-in your family name.</FONT></H3>" ; } ;
if($em=="")
        { echo "<BR><H3 ALIGN=CENTER><FONT FACE=Sans-serif COLOR=WHITE SIZE=3>Please fill-in your email address.</FONT></H3>" ; } ;
        }
        }
?> <? IF($pg<"2") { ?> <form action="<?echo $PHP_SELF?>" method="POST"> <DIV ALIGN=CENTER> <TABLE width=60% CELLPADDING=3> <TR><TD VALIGN=TOP COLSPAN=3> <FONT FACE="comic sans ms, Sans-serif" COLOR=WHITE SIZE=4><B> Member RSVP </FONT> <BR><BR> <FONT FACE="comic sans ms, Sans-serif" COLOR=BLACK SIZE=3><B> Please fill-in each line. </B></FONT><BR> </TD></TR> <TR><TD align=right width 30%><FONT FACE="comic sans ms, Sans-serif" COLOR=BLACK SIZE=3><B> Name</B></FONT></TD> <TD align=left width 70%><FONT FACE="comic sans ms, Sans-serif" COLOR=BLACK SIZE=2><B>First</B><BR><FONT SIZE=4><INPUT NAME="fi" size=20 VALUE="<? Echo $fi?>"></TD> <TD align=left><FONT FACE="comic sans ms, Sans-serif" COLOR=BLACK SIZE=2><B>Family</B><BR><FONT SIZE=4><INPUT NAME="last" size=20 VALUE="<? Echo $last?>"></TD></TR> <TR><TD align=right ><FONT FACE="comic sans ms, Sans-serif" COLOR=BLACK SIZE=3><B>E-Mail Address</B></FONT></TD><TD COLSPAN=2 align=left><FONT SIZE=4><INPUT NAME="em" size=44 VALUE="<? Echo $em?>"></TD></TR> </TABLE> <BR> <HR> <INPUT TYPE=HIDDEN NAME=pg VALUE=1> <BR><INPUT TYPE="submit" VALUE=" Next "> </FORM> <DIV> <BR><BR>
<?       }?>  <! End of pg1.!>
<? IF($pg=="2") { ?> <FONT FACE="comic sans ms, Sans-serif" COLOR=BLUE SIZE=3> <B>Is this correct? <BR>Use Back-Button to make a change or Send It! <BR><BR> </B></FONT> <DIV ALIGN=CENTER> <TABLE border=0 CELLPADDING=0 CELLSPACING=0 WIDTH="65%"> <tr><TD BGCOLOR="#FFF8DC" WIDTH=12> &#160; </TD> <TD BGCOLOR="#FFF8DC"> <BR><BR><FONT FACE="comic sans ms, Sans-serif" COLOR=BLUE><FONT SIZE=4><B><DIV ALIGN=CENTER> RSVP </B> <?echo "<BR><HR>"; echo "<FONT SIZE=2>Name:<B><FONT SIZE=4> $fi $last </B><BR><HR>"; echo "<FONT SIZE=2>Email:<B><FONT SIZE=4> $em </B><BR><HR>"; echo "<BR><BR>"; ?> </TD> <TD BGCOLOR="#FFF8DC" WIDTH=12> &#160; </TD></TR> </TABLE> <DIV ALIGN=center> <form action="<?echo $PHP_SELF?>?" method="POST"> <input type="hidden" name="em" value="<?echo $em?>"> <input type="hidden" name="fi" value="<?echo $fi?>"> <input type="hidden" name="last" value="<?echo $last?>"> <input type="hidden" name="pg" value="3"> <input type="submit" value=" Send It! "> </DIV></FORM> <BR><BR>
<?       }?>  <! End of pg2.!>
<? IF($pg=="3") { ?> <? /* Mail results to this address */ $mailTo = "you@yourURL.com"; /* set the subject*/ $mailSubject = "RSVP"; /* Add From Header*/ $mailHeaders = "From: User Group Web Server/n"; /* Message */ $mailBody = "Name : $fi $last\n"; $mailBody .= "E-mail : $em\n\n"; /* send mail*/ mail ($mailTo, $mailSubject, $mailBody, $mailHeaders); ?> <BR><BR><BR><BR><BR><DIV ALIGN=CENTER> <FONT FACE="comic sans ms, Sans-serif" COLOR=WHITE SIZE=4><BR><B>Your RSVP Was Sent! - - Thank You! <BR><BR> <BR><BR> </B></FONT> </TD></TR></TABLE> <BR><BR>
<?       }?>  <! End of pg3.!>
</TD></TR> </TABLE> </BODY> </HTML>
Thanks for your input, but I still dont really understand your logic/technique. If you may, please send me a basic one textarea form, as too how you use this logic. I guess my main stumbling block is how you move from a blank form ($pg=1) to $pg=2. I may have to go back to a 2 file format to get this done. Thanks for listening.... Gerard Michael J. Seely wrote:
Yes... I like using pg=1, 2, 3, ... to keep track of where I want the page to go next. It seems easy that way. Good Luck.
So far this message and another who mentioned $HTTP_POST_VARS[] made a small light go off in my head. Not enough to get the script woriking, but it made me think. Its not clear, but I sort of came up with another way, but I dont know if its doable . In my form I have a hidden element called 'post' with a value of 1. After the end of the form I echo $post. If its a first time view, there is nothing to output, thats normal. If I submitted the form it echoes 1, thats to be expected. Now, Im able to tell if the form has been posted or not. Enter some logic...... if ($post = "1" && $Age = " ") {echo "NO";} else {echo "YES";} Now here is what happens. On a first time view of the page it outputs 'NO' (Good). If I dont enter anything in the age field and submit the form it outputs 'NO' (Good). If I enter a value into the age field and submit, it outputs 'NO' (Not Good). Am I heading in the right direction with this?? Michael J. Seely wrote:
I do this sort of thing all the time. The format I use typically follows this logic. The PHP file has four IF-ELSEIF-ELSE sections. pg=1 or blank is the initial form pg=2 is the error check looking at input values.
    If it passes, pg is set to 3.
    If not, set to 1. The advantage of this is the original input values can be saved and displayed with Value=<? ECHO..?> sequences so the use doesn't have to input everything if they make a mistake. The error can be highlighted with a color or text!!!.
   pg=3 shows a visual verification page. The user can scan the input and use the back button to make changes or click OK to proceed.
   pg=4 is the action step - send an e-mail including the input, post input to a database or ???
The sections are written in this order - 2, 4, 3, 1. IF($pg="2")
    { do the error checking
    e.g., if fields A, B, and C are not blank = OK
    e.g., if a value is > 100 = not OK
       IF OK, $pg=3;  IF not OK, $pg=1;
    }
ELSEIF($pg="4")
    { do the action stuff.
    }
ELSEIF($pg="3")
    { show an html page in a nice format showing the input values
       IF they like it, the form submit button sets pg=4, and uses hidden fields to copy all of the input values to pg 4.
    }
ELSE
    { Show the initial input form.
    use <INPUT TYPE="HIDDEN" NAME="pg" VALUE="2">
    }
The form can include error check and input tags like this: <? IF(($pg="1") and ($val3==""))
    { ECHO"<FONT COLOR=RED>Required.</FONT><BR>"; } ?>
<TEXTAREA WRAP="SOFT" NAME="val3" COLS="50" ROWS="5"><? ECHO "$val3"; ?></TEXTAREA>
<INPUT TYPE="RADIO" NAME="v2" VALUE="6" <?IF($v2=="6") { ECHO "CHECKED"; } ?> >6 <INPUT TYPE="RADIO" NAME="v2" VALUE="7" <?IF($v2=="7") { ECHO "CHECKED"; } ?> >7 and so on. Hope this is useful...
Im trying to introduce some logic into a form.I am unsing $PHP_SELF as the target. <form action=\"$PHP_SELF\" method=\"POST\" type=\"multipart/form-data\"> I have a text area that the user inputs their age. What I want is that if the field is blank, to stop the script and send the user back to fill in their age. My problem now is that if I go to the blank application form, The script interprets the form as being blank and spits out the error. Ideal scenario, a blank form is presented to the user, and when the form is submitted, do the logic check and act accordingly. Is it possible using $PHP_SELF as the target, or do I have to use 2 files: a form 'front end' with the php logic in the 'backend'?? if ($Age = " ") {
        echo "Please go back and enter your age."; } exit();
Thanks Gerard -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net
-- _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ Michael Seely 408-777-9949

« previous php.general (#60449) next »