Jump to content

Submitting Forms


Recommended Posts

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? :) 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?

Link to comment
Share on other sites


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

<?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...

if ((empty($blah1)) || (empty($blah2)) || (empty($blah3))) {
               $error = "yes";
       }
if ($error == "yes") { echo "You forgot something, dumbass"; }

Link to comment
Share on other sites

Another method using formmail. (usually provided by most hosts)

Use the below template:

01. Create a table

Create a form using the below code

<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

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

04. close the form

05. close the table

Link to comment
Share on other sites

Mine. Its very simple.

bugs.php (rename to your likings)

<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"> </td>
<td width="192">
<input type="submit" name="Submit" value="Send Form">
</td>
</tr>
</table>
</form>

thanks.php

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

<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

(Copy code from thanksecho.php here)

Link to comment
Share on other sites

Can someone find the problem w/ this code?

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

}

?>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...