Help witrh PHP form code and drop down menu

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
DrGizmondo
Forum Newbie
Posts: 4
Joined: Sun Jun 17, 2007 2:27 pm

Help witrh PHP form code and drop down menu

Post by DrGizmondo »

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>
PHP Form Mail Code:[/syntax]

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 

Jason

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]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Firstly, you assume that the form is posted, and even if it isn't, it will attempt to send mail anyway.

What part of this code isn't working?
DrGizmondo
Forum Newbie
Posts: 4
Joined: Sun Jun 17, 2007 2:27 pm

Post by DrGizmondo »

hay superdezign

the form is posting to my email address and the email includes all the usual elements, name, phone number, email address of sender, and comment, but i dont know how to get the form/php script to send user selected input from the drop down ig wether they've selected "data backup", "repair" or "build a system".
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Everything is in the $_POST array. print_r($_POST) to see what's there.

And what I said is that at no point do you check id the posted variables exist.. You just assume that they do. If they don't, your bound to get errors in your mail() function.
DrGizmondo
Forum Newbie
Posts: 4
Joined: Sun Jun 17, 2007 2:27 pm

Post by DrGizmondo »

OK so i guess that i need to as $_POST array. print_r($_POST) to my code, is this right if so where do i put it. Also how would i go about checking if the posted variables exist. Thanks for helping as i said i am new to php so your help realy is appresiated.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Well, print_r($POST) displays the $_POST array for you to look at if you're not sure what it'll contain.

Post your form, and then print_r() the results so that you know what you're dealing with.
It should be a breeze from there.

And you check $_POST exists with isset() or empty().
yuva_web
Forum Newbie
Posts: 6
Joined: Thu May 17, 2007 3:45 am

given option value

Post by yuva_web »

hi

[s]u[/s] you given <option value="">select</option>

given like this then [s]u[/s] you can get the value <option value="select">select</option>


like this [s]u[/s] you give all values.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: given option value

Post by superdezign »

[s]u[/s] you have confused me. A lot of "like this" without any examples.
Post Reply