PHP popup page with form

Hi I need to do a form with radio buttons and the user selects one option. When an option is selected and submit button is pressed the answer needs to be sent to a specific email. How can I do that? Please help me its quite urgent

Here is my HTML and javascript code of what I did till now.

this code in the main page related to how to launch the popup page when page loads:


<SCRIPT LANGUAGE="JavaScript">
<!--
myPopup = '';

function openPopup(url) {
    myPopup = window.open(url,'popupWindow','width=640,height=480');
    if (!myPopup.opener)
         myPopup.opener = self;
}
//--></SCRIPT>
</head>


<body bgColor="#808080" onLoad="javascript: openPopup('popupPage.html')">

popupPage.html - the popup page which needs the PHP code in it


<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript"><!--
function copyForm() {
    opener.document.hiddenForm.myTextField.value = document.popupForm.myTextField.value;
    opener.document.hiddenForm.submit();
    window.close();
    return false;
}
//--></SCRIPT>
<style type="text/css">
<!--
.style1 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
}
-->
</style>
</HEAD>
<BODY>
<FORM NAME="popupForm" onSubmit="return copyForm()" action="" method="post">
  <p>
    <INPUT TYPE="radio" NAME="group1" value="YellowPages">
    <span class="style1">    a) Yellow Pages<br>
    </span>
    <input type="radio" name="group1" value="other">
    <span class="style1">b) Other means of communication</span><br>
    <input type="radio" name="group1" value="friend">
    <span class="style1">c) By Friends</span><br>
    <input type="radio" name="group1" value="purchased" checked>
    <span class="style1">d) Purchased before</span></p>
  <p>
    <INPUT name="Submit" TYPE="submit" onClick="copyForm()" VALUE="Submit">
    </p>
</FORM>
</BODY>
</HTML>

Thanks. But how do I pass the selection from the radio buttons?

The PHP…

<?
if(isset($_POST['submit'])){
  $age = $_POST['age'];
  mail('you@yourdomain.com','subject here','Age Selected: '.$age);
}
?>

The HTML…

<form method="post">
<input type="radio" name="age" value="under 18" /> Under 18
<input type="radio" name="age" value="over 18" /> Over 18
<input type="submit" name="submit" value="Submit It" />
</form>

ok here is the php code I put in:

<?
if(isset($_POST['submit'])){
  $age = $_POST['group1'];
  mail('sharon.zahra@gmail.com','subject here','Answer Selected: '.$age);
}
?>

I put the code in between the HEAD tag of the html in the pop up page. I tried it but I did not receive anything in my email. Can you help me?

here is again the code of the popup page:

<HTML>
<HEAD>

<?
if(isset($_POST['submit'])){
  $age = $_POST['group1'];
  mail('sharon.zahra@gmail.com','subject here','Answer Selected: '.$age);
}
?>

<SCRIPT LANGUAGE="JavaScript"><!--
function copyForm() {
    opener.document.hiddenForm.myTextField.value = document.popupForm.myTextField.value;
    opener.document.hiddenForm.submit();
    window.close();
    return false;
}
//--></SCRIPT>
<style type="text/css">
<!--
.style1 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
}
.style2 {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 16px;
}
-->
</style>
</HEAD>
<BODY>

<FORM NAME="popupForm" onSubmit="return copyForm()" action="" method="post">
  <p>
  <h1 class="style2"> How did you get to know about us? </h1>
    <INPUT TYPE="radio" NAME="group1" value="YellowPages">
    <span class="style1">    a) Yellow Pages<br>
    </span>
    <input type="radio" name="group1" value="other">
    <span class="style1">b) Other means of communication</span><br>
    <input type="radio" name="group1" value="friend">
    <span class="style1">c) By Friends</span><br>
    <input type="radio" name="group1" value="purchased" checked>
    <span class="style1">d) Purchased before</span></p>
  <p align="right">
    <INPUT name="Submit" TYPE="submit" onClick="copyForm()" VALUE="Submit">
    </p>
</FORM>
</BODY>
</HTML>

You get the data from the radio buttons the same way you would get any data from a form. However, your script is insecure.

Your form may use a radio button, but there is nothing in that script that stops someone from submitting information from an altered form using a text field or using a bot to post to your page. That would enable them to alter your message using mail injection.

For yes/no or other exclusive choice situations using radio buttons, translate the values using an array of acceptable answers. This way the actual user input never reaches your mail message, database or whatever else you might be using to store or convey information.

For example, instead of using “yes” and “no” in the value attribute of a radio button for a yes/no answer to a question, use 1 and 0. Then construct an array like this


$answers('No','Yes');
$ynanswer = $answers[$_POST['yn']];
if(empty($ynanswer))
{
    $ynanswer = 'No';//default to no if input was not what was expected
}

Also sending mail with PHP is somewhat of dark art, especially due to spam filters. It isn’t enough to just use the mail function by itself anymore. You may need to send additional headers in order to get the mail to go through.

I would really recommend using a pre-written mail class such as PHPMailer for sending the mail instead.