Jump to content

Problem with a form


Wolverine68

Recommended Posts

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><br>

<tr><td><span class="text">Enter Last Name:</span></td><td><input type="text" name="lname" size="20"></td></tr><br>

<tr><td><span class="text">Enter E-mail Address:</span></td><td><input type="text" name="email" size="20"></td></tr><br>

<tr><td><span class="text">Enter Age:</span></td><td><input type="text" name="age" size="20"></td></tr><br>

<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<br>");

}

if(!$lname)

{

print("Your Last name<br>");

}

if(!$email)

{

print("Your e-mail address<br>");

}

if (strlen($email) < 7)

{

print("The e-mail address entered was only " . strlen($email) . " characters in length and needs to be at least 7<br>");

}

if(!strpos($email, "@"))

{

print("Your e-mail address is missing the @ symbol<br>");

}

if(!strpos($email, "."))

{

print("Your e-mail address is missing the period<br>");

}

if(!$age)

{

print("Your age<br>");

}

if (!is_numeric($age))

{

print("Your entry for age must be numeric<br>");

}

//Redisplay the form

{

print(<b>"Please make the necessary corrections and resubmit:<br>"</b>);

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>

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.