html form with checkboxes run with php

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
cutie525
Forum Newbie
Posts: 4
Joined: Wed Jul 07, 2010 1:30 pm

html form with checkboxes run with php

Post by cutie525 »

I have a form with a question that people can answered by clicking multiple checkboxes, I am trying to get the value of each checkbox they selected sent to my email, this is what I have for the html code and php code just for this sent of check boxes. The php code that I have for this set of checkboxes is causing my form not to process.
[text] <td width="25%"><input type="checkbox" name="search[]" value="Google" ><font size="2"> Google</font></td>
<td width="25%"><input type="checkbox" name="search[]" value="Yahoo"><font size="2"> Yahoo</font></td>
<td width="25%"><input type="checkbox" name="search[]" value="MSN Search"><font size="2"> MSN Search</font></td>
<td width="25%"><input type="checkbox" name="search[]" value="Ask"><font size="2"> Ask</font></td>
</tr>
<tr>
<td width="25%"><input type="checkbox" name="search[]" value="Globalspec"><font size="2">Globalspec</font></td>
<td width="25%"><input type="checkbox" name="search[]" value="Thomas Register"><font size="2"> Thomas Register</font></td>
<td width="50%" colspan="2"><input type="checkbox" name="search[]" value="Other"><font size="2"> Other&nbsp;
</font><input name="Search[]" type="text" size="30"></td>[/text]

Code: Select all

search : '.( empty($_POST['search'] ) ? 'None selected' : implode( ', ', $_POST['search'].'<br />' 
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: html form with checkboxes run with php

Post by Jonah Bron »

Missing parentheses. Needs to be

[text]search : '.( empty($_POST['search'] ) ? 'None selected' : implode( ', ', $_POST['search'] ).'<br />' [/text]
cutie525
Forum Newbie
Posts: 4
Joined: Wed Jul 07, 2010 1:30 pm

Re: html form with checkboxes run with php

Post by cutie525 »

That still didnt work here is the full form and php. :(
[text]<form name="form2" action="captcha3.php","http://www.mark-10.com/cgi-bin/mailto" method="post" onsubmit="return ErrorCheck();">
<INPUT TYPE="hidden" NAME="RECIPIENT" VALUE="dm@mark-10.com">
<INPUT TYPE="hidden" NAME="subject" VALUE="Mark-10 Warranty Registration Form">
<INPUT TYPE="hidden" NAME="THANKURL" VALUE="http://www.mark-10.com/thankyou-warranty.html">
<input type="hidden" name="identicalfields" value="email,email2">

<table border="0" cellspacing="0" cellpadding="2" id="righthand" width="586" style="border-collapse: collapse" bordercolor="#111111" height="619">
<tr>
<td align="left" width="627" colspan="4" height="28"><b>
<font size="3" face="Verdana" color="#0E4AA0">Contact Information</font></b><hr size="2" color="#666666">

</td>
</tr>


<tr>
<td align="right" width="584" height="1" colspan="2"><font size="2">*Name:</font></td>
<td width="570" height="1" colspan="2">
<input name="Name" type="text" id="Name" size="41"></td>
</tr>


<tr>
<td align="right" width="584" height="1" colspan="2"><font size="2">Title:</font></td>
<td colspan="2" width="570" height="1">
<input name="Title" type="text" size="41"></td>
</tr>

<tr>
<td align="right" width="584" height="12" colspan="2"><font size="2">*Email
Address:</font></td>
<td colspan="2" width="570" height="12">
<input name="email" type="text" id="email" size="41"></td>
</tr>

<tr>
<td align="right" height="22" colspan="2">*Confirm Email:</td>
<td colspan="2" height="22"><input name="email2" type="text" id="email2" size="41"></td>
</tr>
<tr>
<td align="right" width="584" height="22" colspan="2"><font size="2">Company:
</font></td>
<td colspan="2" width="570" height="22">
<input name="Company" type="text" size="41"></td>
</tr>

<tr>
<td align="right" width="584" height="22" colspan="2">
<p align="left" style="text-align: right; margin-top: 0; margin-bottom: 0">
Industry: </td>
<td colspan="2" width="570" height="22">
<input name="Industry" type="text" size="41"></td>
</tr>

<tr>
<td align="right" width="584" height="22" colspan="2"><font size="2">*Address:</font></td>
<td colspan="2" width="570" height="22">
<input name="Address1" type="text" id="Address1" size="53"></td>
</tr>

<tr>
<td align="right" width="584" height="22" colspan="2">&nbsp;</td>
<td colspan="2" width="570" height="22">
<input name="Address2" type="text" size="53"></td>
</tr>

<tr>
<td align="right" width="584" height="22" colspan="2"><font size="2">*City:</font></td>
<td colspan="2" width="570" height="22">
<input name="City" type="text" id="City" size="30"></td>
</tr>

<tr>
<td align="right" width="584" height="22" colspan="2"><font size="2">*State/Province:</font></td>
<td colspan="2" width="570" height="22">
<input name="State" type="text" id="State" size="30"></td>
</tr>

<tr>
<td align="right" width="584" height="5" colspan="2"><font size="2">*Zip / Postal
Code:</font></td>
<td colspan="2" width="570" height="5">
<input name="Zip" type="text" id="Zip" size="30"></td>
</tr>

<tr>
<td align="right" width="584" height="22" colspan="2"><font size="2">Country:</font></td>
<td colspan="2" width="570" height="22">
<input name="Country" type="text" size="30"></td>
</tr>

<tr>
<td align="right" width="584" height="1" colspan="2"><font size="2">*Telephone:</font></td>
<td width="244" height="1"><input name="Tel" type="text" id="Tel" size="30"></td>
<td width="326" height="1"><font size="2">Ext: </font>
<input name="Ext" type="text" size="9"></td>
</tr>

<tr>
<td align="right" width="584" height="1" colspan="2"><font size="2">Fax:</font></td>
<td colspan="2" width="570" height="1">
<input name="Fax" type="text" size="30"></td>
</tr>

<tr>
<td align="right" width="1154" height="27" colspan="4">&nbsp;</td>
</tr>

<tr>
<td align="left" width="627" colspan="4" height="29"><b>
<font face="Verdana" size="3" color="#0E4AA0">Product Information </font></b>

<hr size="2" color="#666666">

</td>
</tr>

<tr>
<td align="right" width="584" height="16" colspan="2"><font size="2">*Model No:</font></td>
<td colspan="2" width="570" height="16">
<input name="ModelNo" type="text" id="ModelNo" size="15"></td>
</tr>

<tr>
<td align="right" width="584" height="1" colspan="2"><font size="2">*Serial No.</font></td>
<td colspan="2" width="570" height="1">
<input name="SerialNo" type="text" id="SerialNo" size="15"></td>
</tr>

<tr>
<td align="right" width="584" height="12" colspan="2"><font size="2">*Purchase
Date:</font></td>
<td colspan="2" width="570" height="12">
<input name="PurchDate" type="text" id="PurchDate" size="15"></td>
</tr>

<tr>
<td align="right" width="584" height="16" colspan="2">
<p align="left" style="text-align: right; margin-top: 0; margin-bottom: 0">
<font size="2">Distributor </font></p>
<p style="text-align: right; margin-top: 0; margin-bottom: 0"><font size="2">(if
applicable):</font></td>
<td colspan="2" width="570" height="16">
<input name="Distributor" type="text" size="41"></td>
</tr>

<tr>
<td align="right" width="584" height="16" colspan="2">
<p style="text-align: right; margin-top: 0; margin-bottom: 0"><font size="2">
Application </font></p>
<p style="text-align: right; margin-top: 0; margin-bottom: 0"><font size="2">
(please describe):</font></td>
<td colspan="2" width="570" height="16">
<textarea name="Application" style="width:425px; height: 75px;" rows="1" cols="20"></textarea></td>
</tr>

<tr>
<td align="right" width="100" height="16"></td>
<td width="484" height="16"></td>
<td colspan="2" width="570" height="16"></td>
</tr>

<tr>
<td align="right" width="627" height="16" colspan="4">
<p align="left" style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
<p align="left" style="margin-top: 0; margin-bottom: 0"><b>
<font face="Verdana" size="3" color="#0E4AA0">Questionnaire </font></b></p>

<hr size="2" color="#666666">

</td>
</tr>

<tr>
<td align="left" width="627" height="16" colspan="4"><font size="2">1. How did
you first become aware of Mark-10 products?</font></td>
</tr>

<tr>
<td align="left" width="627" height="16" colspan="4">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
<tr>
<td><input type="checkbox" name="Internet" value="Internet"><font size="2">Internet</font></td><td width="75%" colspan="3">
<input type="checkbox" name="Internet" value="Magazine"><font size="2"> Magazine</font><input name="magazine" type="text" size="36"></td></tr>
<tr><td><input type="checkbox" name="Internet" value="Colleague"><font size="2"> Colleague</font></td>
<td><input type="checkbox" name="Internet" value="Exhibition"><font size="2"> Exhibition</font></td>
<td><input type="checkbox" name="Internet" value="Distributor"><font size="2"> Distributor</font></td>
<td><input type="checkbox" name="Internet" value="Mailing"><font size="2"> Mark-10 mailing</font></td>
</tr>
</table>
</td>
</tr>

<tr>
<td align="left" width="627" height="16" colspan="4"></td>
</tr>

<tr>
<td align="left" width="627" height="16" colspan="4"><font size="2">2. Which
search engine(s) do you most commonly use when searching for equipment? Check up
to two choices.</font></td>
</tr>

<tr>
<td align="left" width="627" height="16" colspan="4">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
<tr>
<td width="25%"><input type="checkbox" name="search[]" value="Google" ><font size="2"> Google</font></td>
<td width="25%"><input type="checkbox" name="search[]" value="Yahoo"><font size="2"> Yahoo</font></td>
<td width="25%"><input type="checkbox" name="search[]" value="MSN Search"><font size="2"> MSN Search</font></td>
<td width="25%"><input type="checkbox" name="search[]" value="Ask"><font size="2"> Ask</font></td>
</tr>
<tr>
<td width="25%"><input type="checkbox" name="search[]" value="Globalspec"><font size="2">Globalspec</font></td>
<td width="25%"><input type="checkbox" name="search[]" value="Thomas Register"><font size="2"> Thomas Register</font></td>
<td width="50%" colspan="2"><input type="checkbox" name="search[]" value="Other"><font size="2"> Other&nbsp;
</font><input name="Search[]" type="text" size="30"></td>
</tr>
</table>
</td>
</tr>

<tr>
<td align="left" width="627" height="16" colspan="4"></td>
</tr>

<tr>
<td align="left" width="627" height="16" colspan="4"><font size="2">3. Which of
the following best describes the primary reason for purchasing this Mark-10
product? Check all that apply.</font></td>
</tr>

<tr>
<td align="left" width="627" height="16" colspan="4">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
<tr>
<td width="25%"><input type="checkbox" name="Q3Size" value="Yes"><font size="2">
Size</font></td>
<td width="25%"><input type="checkbox" name="Q3Price" value="Yes"><font size="2">
Price</font></td>
<td width="25%"><input type="checkbox" name="Q3Reputation" value="Yes"><font size="2">
Brand reputation</font></td>
<td width="25%"><input type="checkbox" name="Q3Warranty" value="Yes"><font size="2">
Warranty</font></td>
</tr>
<tr>
<td width="25%"><input type="checkbox" name="Q3Features" value="Yes"><font size="2">
Features</font></td>
<td width="50%" colspan="2">
<input type="checkbox" name="Q3Versatility" value="Yes"><font size="2"> Versatility
/ Modularity</font></td>
<td width="25%"><input type="checkbox" name="Q3Recommendation" value="Yes"><font size="2">
Recommendation</font></td>
</tr>
</table>
</td>
</tr>

<tr>
<td align="left" width="627" height="16" colspan="4"></td>
</tr>

<tr>
<td align="left" width="627" height="16" colspan="4"><font size="2">4. How would
you rate the service you received from Mark-10 or your distributor?</font></td>
</tr>

<tr>
<td align="left" width="627" height="16" colspan="4">
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
<tr>
<td width="25%"><input type="checkbox" name="Q4Poor" value="Yes"><font size="2">
Poor</font></td>
<td width="25%"><input type="checkbox" name="Q4Satisfactory" value="Yes"><font size="2">
Satisfactory</font></td>
<td width="25%"><input type="checkbox" name="Q4Good" value="Yes"><font size="2">
Good</font></td>
<td width="25%"><input type="checkbox" name="Q4Outstanding" value="Yes"><font size="2">
Outstanding</font></td>
</tr>
</table>
</td>
</tr>

<tr>
<td align="right" width="627" height="16" colspan="4"></td>
</tr>

<tr>
<td align="right" width="627" height="5" colspan="4">
<p align="left">5. Please suggest any improvements to existing Mark-10 products
or new product ideas.</td>
</tr>

<tr>
<td align="right" width="627" height="16" colspan="4">
<p align="left">
<textarea name="Q5Improvements" style="width:425px; height: 75px;" rows="1" cols="20"></textarea></td>
</tr>

<tr>
<td height="16" colspan="4"></span>*Please Enter Code-><img src="captcha_image.php" alt="" />:
</div>
<input name="Security_Code1" type="text" id="Security_Code1" size="15"></td>
</tr>
<tr>
<td align="right" width="627" height="16" colspan="4">
<p align="left"><input name="submit" type="submit" id="scratch_submit" onClick="MM_validateForm('Name','','R','Email','','RisEmail','Address1','','R','City','','R','State','','R','Zip','','R','Tel','','R','ModelNo','','R','SerialNo','','R','PurchDate','','R');return document.MM_returnValue" value="Submit">
<input type="reset" value="Clear" name="Reset"></td>
</tr>

</table>



<table cellspacing="2" width=525 border=0 celpadding="3">



</table>
</form></td>[/text]

Code: Select all

<?


session_start();


if ($_POST['Security_Code1'] == $_SESSION["pass"])
{
	header("Location: http://www.mark-10.com/thankyou-warranty.html");
               
       
//sends email via php to the following address
$mailuser = "dm@mark-10.com";

//echo 'default chosen address: '.$mailuser;
		
	$header = "Return-Path: ".$mailuser."\r\n"; 
	$header .= "From: Mark-10 Warranty Registration Form<".$mailuser.">\r\n"; 
	$header .= "Content-Type: text/html;"; 

$mail_body = 
'The User: '.$_POST[company].' has sent his input.
	Name: '. $_POST[Name] . '<br>
	Title: '. $_POST[Title] . '<br>
	email: '. $_POST[email] . '<br>
	confirm email: '. $_POST[email2] . '<br>
	Company: '. $_POST[Company] . '<br>
	Address: '. $_POST[Address1] . '<br>
	Address: '. $_POST[Address2] . '<br>
	City: '. $_POST[City] . '<br>
	State: '. $_POST[State] . '<br>
	Zip: '. $_POST[Zip] . '<br>
	Country: '. $_POST[Country] . '<br>
	Telephone: '. $_POST[Tel] . '<br>
	Extention: '. $_POST[Ext] . '<br>
	fax: '. $_POST[Fax] . '<br>
	Model NO: '. $_POST[ModelNo] . '<br>
	Serial NO: '. $_POST[SerialNo] . '<br>
	Purchase Date: '. $_POST[PurchDate] . '<br>
	Distributor: '. $_POST[Distributor] . '<br>
	Comments: '. $_POST[Application] . '<br>
	Q1:' . $_POST[Internet] .'<br>
	search : '.( empty($_POST['search'] ) ? 'None selected' : implode( ', ', $_POST['search'] ).'<br />' 
;
	mail ($mailuser, 'Mark-10 Warranty Registration', $mail_body, $header);
         echo 'THANKS ';   
       

} else {
	  header( "Location:http://www.mark-10.com/tryagain2.html" ) ;
	  exit;
}
?>
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: html form with checkboxes run with php

Post by Jonah Bron »

Oops, two missing parentheses.

[text]search : '.( empty($_POST['search'] ) ? 'None selected' : implode( ', ', $_POST['search'] )).'<br />' [/text]

If that doesn't work I'll have a look at the rest of your code.
cutie525
Forum Newbie
Posts: 4
Joined: Wed Jul 07, 2010 1:30 pm

Re: html form with checkboxes run with php

Post by cutie525 »

THANK YOU SO MUCh!! You do not know how much that was bugging me. from the beginning, and its always something small, i guess i have just been looking at it too long. lol
cutie525
Forum Newbie
Posts: 4
Joined: Wed Jul 07, 2010 1:30 pm

Re: html form with checkboxes run with php

Post by cutie525 »

one more thing lol on that line of code can you put a limit on how many they can check?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: html form with checkboxes run with php

Post by Jonah Bron »

Do you mean to redirect them to tryagain2.html if they checked too many? Replace

Code: Select all

if ($_POST['Security_Code1'] == $_SESSION["pass"])
With

Code: Select all

if ($_POST['Security_Code1'] == $_SESSION["pass"] && count($_POST['search']) <= 5)
That would limit them to 5 or less.
Post Reply