Wolverine68 Posted July 8, 2007 Share Posted July 8, 2007 I'm trying to create a basic form. The user fills in the information and submits. If all the required info is submitted, it gives a thank you message. If not, it gives an error stating what info needs to be submitted. I uploaded the php file to my web server. When trying to view the url via the web, it just give a blank white screen. Here's the coding: <html> <head> <title>Submitting a Form PHP</title> <style type="text/css"> .text { color: #000077; font-weight: bold;} </style> </head> <body bgcolor="#DDDDDD"> <? //Create function to display form when called function display_form() { //Create global variables global $fname; global $lname; global $email; global $age; $theForm=<<<EndForm <form action="$PHP_SELF" method="post"> <table> <tr><td><span class="text">Enter First Name:</span></td><td><input type="text" name="fname" size="20"></td></tr> <tr><td><span class="text">Enter Last Name:</span></td><td><input type="text" name="lname" size="20"></td></tr> <tr><td><span class="text">Enter E-mail Address:</span></td><td><input type="text" name="email" size="20"></td></tr> <tr><td><span class="text">Enter Age:</span></td><td><input type="text" name="age" size="20"></td></tr> <tr><td><input type="submit" value="Submit Information" name="submit"></td></tr> </table> </form> </body> </html> EndForm; return $theForm; } //check if this is the first time form is called if((!$fname) || (!$lname) || (!$email) || (!$age)) { print(display_form($theForm)); exit(); } //Check to make sure required info has been entered if((!$fname) || (!$lname) || (!$email) || (!$age)) { $message=<<<EndMessage <h2 align="center">Error- Your registration cannot be processed because some information was missing or incorrectly entered:</h2> EndMessage; //Display the error print($message); } //Show user what info was missing if(!$fname) { print("Your First name "); } if(!$lname) { print("Your Last name "); } if(!$email) { print("Your e-mail address "); } if (strlen($email) < 7) { print("The e-mail address entered was only " . strlen($email) . " characters in length and needs to be at least 7 "); } if(!strpos($email, "@")) { print("Your e-mail address is missing the @ symbol "); } if(!strpos($email, ".")) { print("Your e-mail address is missing the period "); } if(!$age) { print("Your age "); } if (!is_numeric($age)) { print("Your entry for age must be numeric "); } //Redisplay the form { print("Please make the necessary corrections and resubmit: "); print(display_form($theForm)); } //If all the required info is in there, give a thank you message else { $message=<<<EndMessage <h2>Thank you $fname, your order should be processed within the next 24 hours</h2> EndMessage; print($message); } ?> </body> </html> Please use CODE tags for code. Link to comment https://forums.phpfreaks.com/topic/58903-still-having-problems-with-a-form/ Share on other sites More sharing options...
sinisake Posted July 8, 2007 Share Posted July 8, 2007 Ok, here is the right code: <html> <head> <title>Submitting a Form PHP</title> <style type="text/css"> .text { color: #000077; font-weight: bold;} </style> </head> <body bgcolor="#DDDDDD"> <?php //Create function to display form when called function display_form() { //Create global variables global $fname; global $lname; global $email; global $age; $theForm=<<<EndForm <form action="$PHP_SELF" method="post"> <table> <tr><td><span class="text">Enter First Name:</span></td><td><input type="text" name="fname" size="20"></td></tr> <tr><td><span class="text">Enter Last Name:</span></td><td><input type="text" name="lname" size="20"></td></tr> <tr><td><span class="text">Enter E-mail Address:</span></td><td><input type="text" name="email" size="20"></td></tr> <tr><td><span class="text">Enter Age:</span></td><td><input type="text" name="age" size="20"></td></tr> <tr><td><input type="submit" value="Submit Information" name="submit"></td></tr> </table> </form> </body> </html> EndForm; return $theForm; } extract($_POST); //check if this is the first time form is called if(!$submit) if((!$fname) || (!$lname) || (!$email) || (!$age)) { print(display_form()); exit(); } //Check to make sure required info has been entered if($submit) { if((!$fname) || (!$lname) || (!$email) || (!$age)) { $message=<<<EndMessage <h2 align="center">Error- Your registration cannot be processed because some information was missing or incorrectly entered:</h2> EndMessage; //Display the error print($message); } //Show user what info was missing if(!$fname) { $errors=true; print("Your First name "); } if(!$lname) { $errors=true; print("Your Last name "); } if(!$email) { $errors=true; print("Your e-mail address "); } if (strlen($email) < 7) { $errors=true; print("The e-mail address entered was only " . strlen($email) . " characters in length and needs to be at least 7 "); } if(!strpos($email, "@")) { $errors=true; print("Your e-mail address is missing the @ symbol "); } if(!strpos($email, ".")) { $errors=true; print("Your e-mail address is missing the period "); } if(!$age) { $errors=true; print("Your age "); } if (!is_numeric($age)) {$errors=true; print("Your entry for age must be numeric "); } //Redisplay the form if($errors){ print(display_form()); } //If all the required info is in there, give a thank you message //else if(!$errors){ $message=<<<EndMessage <h2>Thank you $fname, your order should be processed within the next 24 hours</h2> EndMessage; print($message); } } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/58903-still-having-problems-with-a-form/#findComment-292265 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.