Hi, I am using PHP to process a contact form and send the content by email. I have added a couple of radio buttons to the form so that the user can select whether they contact the northern branch or southern branch. Unfortunately, my 'if else' statements don't seem to be doing the job properly. The radio buttons on the contact page have the name set as "region" with values of "north" and "south" and I am pulling the selected value into a variable called "$reg" with: $reg = $_POST['region']; Code (markup): Here's the code that should put the correct email address into a variable called "$to": if ($reg=="north") { $to = "name1@domain.com <name1@domain.com>"; } elseif ($reg=="south") { $to = "name2@domain.com <name2@domain.com>"; } else { $to = "default@domain.com <default@domain.com>"; } Code (markup): Unfortunately, regardless of which radio button is selected the mail keeps being sent to the default address. Where am I going wrong? Any help much appreciated. T
echo $reg and see if it contains the expected content. Also note that the string comparison is case-sensitive. If you still need help, can you post your HTML form?
Do a print_r($_POST); PHP: ... near the top of your code to check to see if your "region" value is what you pressed on the form. Jay
Thanks for the suggestion. I tried it and discovered that the WYSYWIG view on my CMS was corrupting my HTML and the radio button values weren't being set. Once I switched to code view in the CMS to update the form page it worked perfectly! An important lesson learned. Thanks for your help. T
just a side note (and longtime question of mine). Why is everyone using _POST or _GET and not _REQUEST, that contains both?
Because $_REQUEST is more insecure in some cases. It's a bad practice using it without a good reason.
Values in the $_POST array are limited to the options you give the user in a form. So, for example, a drop down list or radio button list has a small array of acceptable values. $_GET on the other hand can contain anything a savvy user puts into the url when he accesses the page. So in most cases, it's wise to use the $_POST array to help cut down on the user's ability to mess around with the input. This in turn helps make your site slightly more secure. - Walkere