Click to See Complete Forum and Search --> : converting HTML form to PHP


longshot
01-14-2008, 10:10 AM
im a newbie at this one and through all the research i have done i still can't seem to get it right. Im hoping someone out there can help.:confused:

i need to convert an HTML for to php and have it submit to an e-mail address. I am able to create the html form but thats where my knowledge ends. below is the HTML form

<table width="384" border="0" cellpadding="2" cellspacing="0" bordercolor="#E6E6E6" id="contact form">
<tr>
<td><div align="right" class="style14">
<div align="left"><span class="style15">NAME</span></div>
</div></td>
<td><label>
<input name="name" type="text" class="style13" size="35" id="name">
</label></td>
</tr>
<tr>
<td class="style2">E-MAIL ADDRESS</td>
<td><input name="email" type="text" class="style13" size="35" id="email"></td>
</tr>
<tr>
<td><div align="right" class="style14">
<div align="left" class="style15">ADDRESS</div>
</div></td>
<td><label>
<input name="street address" type="text" class="style13" size="35" id="street address">
</label></td>
</tr>
<tr>
<td class="style2">PHONE</td>
<td valign="middle"><label>
<input name="phone" type="text" class="style13" size="35" id="phone">
</label></td>
</tr>
<tr>
<td class="style2">&nbsp;</td>
<td><label>
<textarea name="job description" cols="36" rows="4" class="lineheight" id="job description">Briefly describe job</textarea>
</label></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><textarea name="how did you hear about us" cols="36" rows="2" class="lineheight" id="how did you hear about us">How did you hear about us?</textarea></td>
</tr>
<tr>
<td width="96">&nbsp;</td>
<td width="280"><label>
<input name="reset" type="reset" class="style16" value="RESET" id="reset">
<input name="Submit" type="submit" class="style16" value="SUBMIT">
<input type="hidden" name="hiddenField">
</label></td>
</tr>
</table>

sleven
01-14-2008, 07:15 PM
Yes , php , just put the code between the table.

<form action="mail.php" method="post">
</form>

Sheldon
01-14-2008, 08:17 PM
@ Sleven, What are you trying to say here?

@ Long Shot
( Please post your code between [ php] ...code... [ /php]

<?php

/* Edit these next Lines */
// Set your email address.
$owner = "email@domain.com";
// Email Subject
$subject = "Email From Domain.com";
$message = "Your email has been received, Thanks!";
/* No more editing! */



if(!empty($_POST['submit'])){
// set required form fields
$required = array("name","email","jobDescription");
// run a check on each form field and make sure it is not required, but empty.
foreach($_POST as $key => $value){
if(in_array($key, $required) and empty($value)){
// we will build a string of fields that are empty. No Good!
$status .= "<p><strong>Error: </strong>The \"{$key}\" field is required.</p>";
}
}
// Check to see if no error has been found,
if(empty($status)){
// No errors found, continue to send the mail!
// The TO address for the email
$to = $_POST['email']; // We will send this to who submitted the form.
$headers = "FROM: {$owner}\nBCC: {$owner}";
$message .= "\n\n";
$message .= "Name: {$_POST['name']}\n";
$message .= "Email: {$_POST['email']}\n";
$message .= "Address: {$_POST['address']}\n";
$message .= "Phone: {$_POST['phone']}\n\n";
$message .= "Job Description:\n{$_POST['jobDescription']}\n\n\n";
$message .= "______________________________________\n\n";
$message .= "How you found us: {$_POST['howDidYouHearAboutUs']}\n";
$message .= date("r"). "\n";

// the message is formed, send the email.
if(mail($to, $subject, $message, $headers)){
// mail sent!
$status = "<p><strong>Success: </strong>Your email has been recieved.</p>";
}else{
// For some reason PHP and Mail are not working together? Shold never happen
$status = "<p><strong>Error: </strong>A fatal Error has occured, Contact <a href=\"mailto:{$owner}\">{$owner}</a>.</p>";
}
}
echo($status);
}
?>
<form action="<?php echo(htmlentities(basename($_SERVER['PHP_SELF']))); ?>" method="post" accept-charset="utf-8">
<table width="384" border="0" cellpadding="2" cellspacing="0" bordercolor="#E6E6E6" id="contact form">
<tr>
<td><div align="right" class="style14">
<div align="left"><span class="style15">NAME</span></div>
</div></td>
<td><label>
<input name="name" type="text" class="style13" size="35" id="name"<?php if(!empty($name)){ echo(" value=\"{$name}\""); } ?>>
</label></td>
</tr>
<tr>
<td class="style2">E-MAIL ADDRESS</td>
<td><input name="email" type="text" class="style13" size="35" id="email"<?php if(!empty($email)){ echo(" value=\"{$email}\""); } ?>></td>
</tr>
<tr>
<td><div align="right" class="style14">
<div align="left" class="style15">ADDRESS</div>
</div></td>
<td><label>
<input name="streetAddress" type="text" class="style13" size="35" id="streetAddress"<?php if(!empty($streetAddress)){ echo(" value=\"{$streetAddress}\""); } ?>>
</label></td>
</tr>
<tr>
<td class="style2">PHONE</td>
<td valign="middle"><label>
<input name="phone" type="text" class="style13" size="35" id="phone"<?php if(!empty($phone)){ echo(" value=\"{$phone}\""); } ?>>
</label></td>
</tr>
<tr>
<td class="style2">&nbsp;</td>
<td><label>
<textarea name="jobDescription" cols="36" rows="4" class="lineheight" id="jobDescription"><?php if(!empty($jobDescription)){ echo($jobDescription); }else{ echo("Briefly describe job"); } ?></textarea>
</label></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><textarea name="howDidYouHearAboutUs" cols="36" rows="2" class="lineheight" id="howDidYouHearAboutUs"<?php if(!empty($howDidYouHearAboutUs)){ echo(" value=\"{$howDidYouHearAboutUs}\""); } ?>>How did you hear about us?</textarea></td>
</tr>
<tr>
<td width="96">&nbsp;</td>
<td width="280"><label>
<input name="reset" type="reset" class="style16" value="RESET" id="reset">
<input name="Submit" type="submit" class="style16" value="SUBMIT">
<input type="hidden" name="hiddenField">
</label></td>
</tr>
</table>
</form>

Sheldon
01-14-2008, 08:20 PM
LongShot, Your name and ID variables can not have spaces in them.

for example <input type="text" name="this field" id="this id" /> is bad and will not function correctly or be valid.

You should tie the two word together, by _ or by secondWordCapitalization.

<input type="text" name="thisField" id="thisId" />