Help witrh PHP form code and drop down menu
Posted: Sun Jun 17, 2007 2:40 pm
feyd | Please use
PHP Form Mail Code:[/syntax]
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
hi all im new here and also new to the implementation of php, so i hope that you can help as i dont know where else to turn. Im using a simple HTML contact form with a PHP form mail scipt, all elements of the form are email to appart form what is selected from the drop down service select element. please could you help me to get this element of the form to work.
HTML Cotact form code:
[syntax="html"] <div id="devis"><img src="../../img/estimate.png" alt="presentation" />
<form method="post" action="simplescript.php" >
<div id="demandedevis">
<label style="height:30px; padding:0">Please fill in the form below:</label>
<label>
<input type="text" name="name" />
Name</label>
<label>
<input type="text" name="telephone" />
Telephone</label>
<label>
<input type="text" name="email" id="email" />
Email</label>
<label>
<select name="service">
<option value="">Please select...</option>
<option value="">Repair</option>
<option value="">Backup & Data recovery</option>
<option value="">PC health Check</option>
<option value="">Child safety</option>
<option value="">Online Security</option>
<option value="">Networking</option>
<option value="">Peripheral Install</option>
<option value="">New Build PC</option>
<option value="">Networking</option>
</select>
Type of service</label>
<label style="height: 100px;">Comments<br />
<textarea name="commentaires"></textarea>
</label>
<label>
<input type="submit" name="button" id="button" value="Submit" />
</label>
<br />
</div>
</form>
Code: Select all
<?php
$subject = 'Form Submission'; // Subject of email sent to you.
$emailadd = 'info@openwidemedia.co.uk'; // Your email address. This is where the form information will be sent.
$url = 'http://www.yahoo.com'; // Where to redirect after form is processed.
$req = '0'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$text = "Results from form:\n\n";
$space = ' ';
$line = '
';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
if ($value == '')
{echo "$key is empty";die;}
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\n', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
?>Code: Select all
please can you spot where i have gone wrong or tell me what needs to be added to get all the elements of the code to work.
Thanks in advanced
Jasonfeyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]