Jump to content

Problem sending form results to form owner


Recommended Posts

I have a form located at

 

http://www.nativeone.net/site_selection

 

The field that has checkbox choices is giving me a problem.  No matter what choices my customer makes, whether they choose all, none or only some, I get in my email that is returned to me all the choices as if they were all checked.  My code is attached.  Can anyone help me here. I have gone over it a hundred times.  Maybe I am missing something.  You can see the form code from the link.  Attached is my PHP Code.

 

Thanks.

 

[attachment deleted by admin]

Sure, I did it that way to keep it short but here goes with the code tags.

 

First, here is the HTML code:

 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>N1::Contact Us</title>
<link rel="stylesheet" type="text/css" href="n1-01.css" />
</head>
<body>

<form method="post" action="site_form.php" enctype="multipart/form-data">


  <table>
    <tr>

      <td>Name:</td>
      <td><input name="name" type="text" size="25" maxlength="30" /></td>
    </tr>
    <tr>
      <td>E-mail address:</td>
      <td><input name="email" type="text" size="25" maxlength="30" /></td>
    </tr>

    <tr>
      <td>What is your number</td>
      	<td>
      	<select size="4" name="numbeeerr[]" multiple>
	<option selected>number1</option>
	<option>number2</option>
	<option>number3</option>

	<option>number4</option>
	</select>
        </td>
    </tr>

  	<tr>
    <td colspan="2"> </td>
  	</tr>

  



<tr>
  <td>Check a color<br />
      from the check boxes:</td>
<td>

<label><input type="checkbox" name="choice[0]" value="choice1waschosen" />red</label>
<br />
<label><input type="checkbox" name="choice[0]" value="choice2waschosen" />blue</label>
<br />

<label><input type="checkbox" name="choice[0]" value="choice3waschosen" />green</label>
<br />
<label><input type="checkbox" name="choice[0]" value="choice4waschosen" />black</label></td>	
</tr>


  <tr>
    <td> </td>
    <td><p>
      <label>
        <input type="radio" name="RadioGroup1" value="radio1" id="RadioGroup1_0" />

        
        Radio1</label>
      <br />
      <label>
        <input type="radio" name="RadioGroup1" value="radio2" id="RadioGroup1_1" />
        Radio2</label>
      <br />
    </p></td>
  </tr>

  <tr>
    <td colspan="2">
    <input name="submit" type="submit" value="Submit"/></td>
  </tr>
  </table>
</form>
</body>
</html>



 

Now the PHP Code

 


<?php
# ----------------------------------------------------
# -----
# ----- This script was generated by PHP-Form Wizard 1.2.5 on 7/6/2008 at 11:31:48 PM
# -----
# ----- http://www.tools4php.com
# -----
# ----------------------------------------------------


// Receiving variables
@$pfw_ip= $_SERVER['REMOTE_ADDR'];
@$name = addslashes($_POST['name']);
@$email = addslashes($_POST['email']);
@$numbeeerr = $_POST['numbeeerr[]'];
@$numbeeerr = @implode("&" , $numbeeerr);
@$choice[0] = addslashes($_POST['choice[0]']);
@$RadioGroup1 = addslashes($_POST['RadioGroup1']);

// Validation
//Sending Email to form owner
$pfw_header = "From: $email\n"
  . "Reply-To: $email\n";
$pfw_subject = "Form submission to N1";
$pfw_email_to = "[email protected]";
$pfw_message = "Visitor's IP: $pfw_ip\n"
. "name: $name\n"
. "email: $email\n"
. "numbeeerr: $numbeeerr\n"
. "choice[0]: $choice[0]\n"
. "RadioGroup1: $RadioGroup1\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

//Sending auto respond Email to visitor
$pfw_header = "From: [email protected]\n"
  . "Reply-To: [email protected]\n";
$pfw_subject = "Your form submission";
$pfw_email_to = "$email";
$pfw_message = "Thanks for your request";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

echo("<p align='center'><font face='Arial' size='3' color='#FF0000'>Sent</font></p>");
?>


 

 

Thank you very much for any help anyone can give.

 

 

Shouldn't it be:

<input type="checkbox" name="choice[]" value="choice1waschosen" />red</label>
.
.
.

 

$choice = $_POST['choice'];
.
.
.

$selected = '';

foreach($choice as $value)
{
  $selected .= "$value, ";
}

$selected = substr($selected, 0, -2); //get rid of the trailing ", "

 

EDIT: small syntax error

No no no :)

 

Using '[]' in an element's name will be converted into an array by php

 

<input type="text" name="test[]" />

 

Will populate $_POST['test'][0]

 

Try doing it with checkboxes and print_r'ing the result.

 

Are you talking to me or the OP?  Because I showed them how to do it using an array.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.