Help - Search - Members - Calendar
Full Version: Submitting Forms
MSFN Forums > Coding, Scripting and Servers > Web Development (HTML, Java, PHP, ASP, XML, etc.)

   
Google Internet Forums Unattended CD/DVD Guide
gamehead200
Guys, let's say I have this form and when someone fills it out and they press 'submit', it gets sent to a certain e-mail address...What would be the code for the 'submit' button? unsure.gif And what code would I have to put so if someone doesn't fill out a text box, when they press 'submit', it tells them that they forgot to fill something out?
sedative
I guess you mean in PHP. Here's my old contact form. You'll have to modify it to your liking.

Note: I didn't make this, so I won't be able to help with this..

CODE
<?php
$target = "your@email.address";
if (($message) && ($from) && ($subject) && ($target) && ($fromname)) {
$message = stripslashes($message);
mail(" $target ", " $subject ", $message,
    "From: $fromname <$from>\r\n"
   ."Reply-To: $from\r\n"
   ."X-Mailer: PHP/" . phpversion());
echo "<br><br>Mail sent successfully, click <a href=\"$PHP_SELF\">here</a> to send another";
}
else {
echo "
<form name=\"mail\" method=\"post\" action=\"$PHP_SELF\">
<table border=0>
<tr>
<td>Name:</td>
<td><input class=\"editbox\" type=\"text\" name=\"fromname\"><br></td>
</tr>
<tr>
<tr>
<td>E-Mail:</td>
<td><input class=\"editbox\" type=\"text\" name=\"from\"><br></td>
</tr>
<tr>
<td>Subject:</td>
<td><input class=\"editbox\" type=\"text\" name=\"subject\"><br></td>
</tr>
<tr>
<td>Message:</td>
<td><br></td>
</tr>
<tr>
<td colspan=2>
<textarea class=\"editbox\" name=\"message\" cols=\"80\" rows=\"10\"></textarea>
</td>
</tr>
<tr>
<td></td>
<td><div align=\"right\"><input class=\"button\" type=\"submit\" name=\"Submit\" value=\"Send\"></div></td>
</table>
</form>
";
}
?>


As far as the "missing data" error, you'd use something like...

CODE
if ((empty($blah1)) || (empty($blah2)) || (empty($blah3))) {
               $error = "yes";
       }
if ($error == "yes") { echo "You forgot something, dumbass"; }
babis
Another method using formmail. (usually provided by most hosts)

Use the below template:

01. Create a table

Create a form using the below code

QUOTE
<form method = "post" action =
"http://www.ugrad.cs.jhu.edu/cgi-bin/cgiwrap/internet/FormMail.pl">
<input type = "hidden" name = "recipient" value = "blank@jhu.edu">
NOTE: usually your host has formmail installed, just go about doing a search, i know netfirms has it. (obviously the form mail i gave above is from my school, and that's my email)

02. Create all the form types you want
radio buttons, text fields, etc..

03. add the send/clear buttons using the following code

QUOTE
<input type = "submit" value = "Send"><br><input type = "reset" value = "Clear Form">


04. close the form
05. close the table
gamehead200
sedative, for yours, do I have to have anything installed other than PHP and a webserver?
Charles
Mine. Its very simple.

bugs.php (rename to your likings)
CODE
<BR><form method=post action="thanks.php"><table width="300" border="0" cellspacing="0" cellpadding="0"><font face="Verdana" size="1" color="Gray">
<tr>
<td width="108"><font face="Verdana" size="1" color="Gray">cUsername:</td>
<td width="192">
<input type="text" name="name">
</td>
</tr>
<tr>
<td width="108"><font face="Verdana" size="1" color="Gray">E-Mail Address:</td>
<td width="192">
<input type="text" name="thereemail">
</td>
</tr>
<tr>
<td width="108" valign="top"><font face="Verdana" size="1" color="Gray">Title:</td>
<td width="192">
<textarea name="message"></textarea>
</td>
</tr>
<tr>
<td width="108">&nbsp;</td>
<td width="192">
<input type="submit" name="Submit" value="Send Form">
</td>
</tr>
</table>
</form>


thanks.php
CODE
<?php  
if($sentemail == "2"){  
include("sorry.php");  

}else{  

$num = $sentmessage + 1;  
setcookie("sentemail","$num",time()+600); //set the cookie

$email = "Reported by:\t$name (\t$thereemail )\nMessage:\t$message\nIP Address:\t$REMOTE_ADDR\n\n";
$to = "gamehead@hisemail.com";
$subject = "Subject of submission u want";
$mailheaders = "From: $thereemail <> \n";
$mailheaders .= "Reply-To: $thereemail\n\n";
mail($to, $subject, $email, $mailheaders);
include("thanksecho.php");
}
?>


thanksecho.php
CODE
<form method=post action="thanks.php"><table width="300" border="0" cellspacing="0" cellpadding="0"><Center><center>Thank you for submitting the form.


sorry.php
CODE
(Copy code from thanksecho.php here)
gamehead200
Cool! I'll try it out...
gamehead200
Can someone find the problem w/ this code?
QUOTE
<?php  
if($sentemail == "2"){  
include("sorry.php");  

}else{  

$num = $sentmessage + 1;  
setcookie("sentemail","$num",time()+600); //set the cookie

$email = "Name of Applicant:\t$name (\t$thereemail )\nDaytime Phone Number:\t$number1\nNighttime Phone Number:\t$number2\nResume:\t$resume\nIP Address:\t$REMOTE_ADDR\n\n-----------------------------------------------------------------------------------------------------
This email was sent via the Altapex job application form.";
$to = "email@email.com";
$subject = "Altapex Job Application";
$mailheaders = "From: $thereemail <> \n";
$mailheaders .= "Reply-To: $thereemail\n\n";
mail($to, $subject, $email, $mailheaders);
include("thanksecho.php");
}
?>
Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.