php contact form not sending radio info

sonyfero

New Member
I have this php contact form and it works great but when I try to add some radio code in it; it does not work. Meaning sends the email but not the radio part. How can I code it to work. index.html\[code\]<body onLoad="randomNums();"> <div class="contactForm"><br> <table width="42%"> <tr> <td width="12%"><strong>Name</strong></td> </tr> <tr> <td width="88%"><input type="text" name="first_name" id="first_name" style="width:374px;"></td> </tr> </table><br><table width="63%"> <tr> <td width="9%"><strong>Email</strong></td> <td width="26%"><strong>Phone</strong> (Optional)</td> </tr> <tr> <td width="32%"><input type="text" id="email" name="email"></td> <td width="33%"><input type="text" id="phone" name="phone"></td> </tr> </table> <br /> <strong>Message</strong> <br /> <textarea name="message" id="message" rows="12" cols="64"></textarea> <br />I'm a: <input type="radio" name="type" value="http://stackoverflow.com/questions/13857730/Other" checked="checked" /> Other <input type="radio" name="type" value="http://stackoverflow.com/questions/13857730/Student" /> Student <input type="radio" name="type" value="http://stackoverflow.com/questions/13857730/Faculty" /> Faculty/Staff Member<br /> <br /> <strong>Please add these numbers:</strong> <span id="digit1"></span> + <span id="digit2"></span> = <input type="text" id="answer" size="2"> <br /> <br /> <div id="status"><button type="button" id="myBtn" onClick="ajax_postContact();">Send Now</button></div></div></body>\[/code\]Contact.js\[code\]function ajax_postContact(){ var msg = document.getElementById("message").value; var answer = document.getElementById("answer").value; var fn = document.getElementById("first_name").value; var ph = document.getElementById("phone").value; var em = document.getElementById("email").value; var digit1 = parseInt(document.getElementById("digit1").innerHTML); var digit2 = parseInt(document.getElementById("digit2").innerHTML); ///// error checking //// var sum = digit1 + digit2; if(answer == null || answer == ""){ alert("Please add the numbers"); return false; } else if(answer != sum){ alert("Your answer to the math problem is wrong. Please try again."); return false; } else if(fn == null || fn == ""){ alert("Please type your name"); return false; } else if(em == null || em == ""){ alert("Please type your email address"); return false; } else if(msg == null || msg == ""){ alert("Please leave a message"); return false; } else{ var hr = new XMLHttpRequest(); var url = "parse_contact.php"; var vars = "first_name="+fn+"&phone="+ph+"&email="+em+"&message="+msg; hr.open("POST", url, true); hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); hr.onreadystatechange = function() { if(hr.readyState == 4 && hr.status == 200){ var return_data = http://stackoverflow.com/questions/13857730/hr.responseText; document.getElementById("status").innerHTML = return_data; }} hr.send(vars); document.getElementById("status").innerHTML = "<img src='http://stackoverflow.com/questions/13857730/images/loaderblue.gif' alt='Loader'>"; document.getElementById("first_name").valuehttp://stackoverflow.com/questions/13857730/= ""; document.getElementById("phone").valuehttp://stackoverflow.com/questions/13857730/= ""; document.getElementById("email").valuehttp://stackoverflow.com/questions/13857730/= ""; document.getElementById("message").valuehttp://stackoverflow.com/questions/13857730/= ""; document.getElementById("answer").valuehttp://stackoverflow.com/questions/13857730/= ""; }}\[/code\]parse_contact.php\[code\]<?phpif(isset($_POST['first_name'])) { $first_name = $_POST['first_name']; $phone = $_POST['phone']; $email = $_POST['email']; $msg = $_POST['message']; $type = $_POST['type']; $regex = '/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.a-zA-Z0-9_-]+)*\.([a-zA-Z]{2,6})$/'; if((!$first_name) || (!$email) || (!$msg)){ echo 'Oops! Please fill in all fields to submit the form'; exit(); }else if(!preg_match($regex, $email)){ echo 'Sorry, that is not a valid email address, please try using another'; exit(); }else{ $first_name = strip_tags(stripslashes($first_name)); $msg = strip_tags(stripslashes($msg)); $phone = preg_replace('/^0-9.-/','',$phone); $to = "[email protected]"; $from = $email; $subject = "You have a message from your website"; ///email body /// $message = " Name:$first_name Phone:$phone Email:$email Feedback Comment: $msg $type"; //// set headers //// $headers = 'MIME-Version: 1.0' . "/r/n"; $headers .= 'Content-type: text' . "/r/n"; $headers .= 'From: $from'. "\r\n"; /// send email now /// mail($to, $subject, $message, $headers, '-f [email protected]'); echo "Thanks, for your feedback"; exit(); } }?>\[/code\]
 
Back
Top