php form

garrensilverwing

New Member
Messages
148
Reaction score
0
Points
0
After reading a few tutorials I wanted to give PHP a try. I want to write a php code that will verify the contents of a form submited (http://www.brianwallchess.x10hosting.com/advertise.htm)
and then mail them to me at my email address. I do not want the form emailed to me if it is not valid however here is the code that I have already but all I get is a blank page when I run it.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Advertising Application Validation</title>
</head>
<body>
<p style="color: red;">
<?php
$firstname = $_REQUEST['firstname'] ;
$lastname = $_REQUEST['lastname'] ;
$email = $_REQUEST['email'] ;
$emailchk = $_REQUEST['verifyemail'] ;
$business = $_REQUEST['business'] ;
$text = $_REQUEST['text'] ;
$graphic = $_REQUEST['graphic'] ;
$yes = $_REQUEST['yes'] ;
$no = $_REQUEST['no'] ;
$dlink = $_REQUEST['dlink'] ;
$impress = $_REQUEST['impress'] ;

if ($firstname == "")
{echo("Please enter your first name.");}
if ($lastname == "")
{echo ("Please enter your last name.");}
if ($email == "")
{echo ("Please enter your email address.");}
if ($isValid == "false")
{echo ("The email address you have entered is not valid.");}
if ($email ==! $emailchk)
{echo ("The email addresses you have entered do not match.");}
if ($business == "")
{echo ("Please enter the name of your business or website.");}
if ($yes == "0")
{echo ("Only authorized people may submit this application.");}
else{
mail( "garrensilverwing@yahoo.com", "$business Advertising Application",
"Name: $firstname $lastname Email: $email Website or Business: $business Authorized: $yes $no Text: $text Graphic: $graphic Type: $dlink $impress", "From: $email" );
echo ("Thank you for submitting your application");}
?>
</p>
</body>
</html>
 
Last edited:

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
you can use the [ code ]code goes here[ /code ] (remove spaces to use)

the very last curly brace } doesn't match up with anything.
 

garrensilverwing

New Member
Messages
148
Reaction score
0
Points
0
i added an else at the end but still only get a blank page. I want it to display the error message for whichever if statement comes back false but just a blank page i think i am missing something important
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
it works for me on my test server:

Please enter your first name.Please enter your last name.Please enter your email address.Please enter the name of your business or website.
Thank you for submitting your application
 

driveflexfuel

New Member
Messages
159
Reaction score
0
Points
0
I just thought i would add my two cents. I personally use javascript to verify the contents of the form before submission is sent.

Example

Code:
function checkForm(frm){
msg = "";
   if(!frm.Name.value){
      msg += "- Please fill in your full name\n";
   }
   if(!frm.Email.value){
      msg += "- Please fill in your email address\n";\
   }
   if(msg != ""){
      alert(msg);
      return false;
   }
}

add this to form tag
Code:
onsubmit='return checkForm(this)'
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
pure html page reload adds very little to server load, but it is much faster for the user if javascript pops up an error right away. It's not that easy to learn another programming language though, especially one as tricky as JS DOM.
 

garrensilverwing

New Member
Messages
148
Reaction score
0
Points
0
well the main reason why i am doing it with php is so i can get some hands-on experience with it because i want to evolve my website into one that uses php for log in and stuff like that
anyway -- i put it onto my webserver and it works by showing the text that i put in however it still isnt mailing :'( i put in the new mail to code leafypiggy suggested so i will see if it mails to me now
Code:
<p style="color: red;">
<?php
$firstname = $_REQUEST['firstname'] ;
$lastname = $_REQUEST['lastname'] ;
$email = $_REQUEST['email'] ;
$emailchk = $_REQUEST['verifyemail'] ;
$business = $_REQUEST['business'] ;
$text = $_REQUEST['text'] ;
$graphic = $_REQUEST['graphic'] ;
$yes = $_REQUEST['yes'] ;
$no = $_REQUEST['no'] ;
$dlink = $_REQUEST['dlink'] ;
$impress = $_REQUEST['impress'] ;
if ($firstname == "")
{echo("Please enter your first name.");}
if ($lastname == "")
{echo ("Please enter your last name.");}
if ($email == "")
{echo ("Please enter your email address.");}
if ($isValid == "false")
{echo ("The email address you have entered is not valid.");}
if ($email ==! $emailchk)
{echo ("The email addresses you have entered do not match.");}
if ($business == "")
{echo ("Please enter the name of your business or website.");}
if ($yes == "1")
 {$to = "[EMAIL="garrensilverwing@yahoo.com"]garrensilverwing@yahoo.com[/EMAIL]";
 $subject = "$business Advertising Application";
 $message = "$firstname $lastname from $business: $text, $graphic, $dlink, $impress";
 $from = "$email";
 $headers = "From: $from";
 mail($to,$subject,$message,$headers);
 echo "Thank you for submitted your applicatoin.";}
 else{echo ("Only authorized people may submit this application.");}
?>
</p>
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
You can also use filter_var_array to validate and sanitize user input. A loop (such as a for or foreach loop) will help cut down on repeated code (all the "if" branches).

The return value of mail() might be helpful. If mail() returns false, the message was never accepted for delivery. Be aware that if it returns true, the mail won't necessarily be received. Others have been having problems with spam filters; it appears x10 was exploited in the past by spammers.

A well designed form will be validated both client- and server-side: client side so the user gets immediate feedback and server side to protect your site. The best forms use inline validation feedback on the client side (the link doesn't cover changing the error message or choosing where to place the message; accessibility requirements might make you put the message in the <label> element).

A note about field names: there is no 'no' input in your form ($_REQUEST['no'] won't be defined), and the 'dlink' and 'impress' fields are named 'directlink' and 'impression' in the form.
 

garrensilverwing

New Member
Messages
148
Reaction score
0
Points
0
You can also use filter_var_array to validate and sanitize user input. A loop (such as a for or foreach loop) will help cut down on repeated code (all the "if" branches).

The return value of mail() might be helpful. If mail() returns false, the message was never accepted for delivery. Be aware that if it returns true, the mail won't necessarily be received. Others have been having problems with spam filters; it appears x10 was exploited in the past by spammers.

A well designed form will be validated both client- and server-side: client side so the user gets immediate feedback and server side to protect your site. The best forms use inline validation feedback on the client side (the link doesn't cover changing the error message or choosing where to place the message; accessibility requirements might make you put the message in the <label> element).

A note about field names: there is no 'no' input in your form ($_REQUEST['no'] won't be defined), and the 'dlink' and 'impress' fields are named 'directlink' and 'impression' in the form.

thanks for all the input, once i get the validation thing working i can tweak the form a little. (im kind of using this as a learning experience both for html forms and php i will probably do javascript validation also) i've already received an email from a test form that i filled out so i think its working just waiting on some other test ones ive filled out. field names: i just redid the form and forgot to take that part of the php code out :( i will continue my work tomorrow and fix everything up but i just want it to work haha
Edit:
yay it works thanks everyone for your help :) here is the finished product:

http://www.brianwallchess.x10hosting.com/advertise.php
 
Last edited:
Top