8 Replies - 985 Views - Last Post: 04 August 2009 - 01:35 AM Rate Topic: -----

#1 raid01alpha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-August 09

Getting the value of checkboxes from HTML form to PHP

Posted 03 August 2009 - 09:27 PM

Hi Guys,

I am new to web developing. I found it fun and interesting so i start learning now. I created a Form using HTML with checkboxes and I managed to send it to email using PHP by creating one php file. Everything was fine but i noticed that i was not able to capture those values i selected within a checkboxes.

How can i get the value of my checkboxes from HTML Form to my PHP?

Thanks a lot in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: Getting the value of checkboxes from HTML form to PHP

#2 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5247
  • View blog
  • Posts: 27,070
  • Joined: 10-May 07

Re: Getting the value of checkboxes from HTML form to PHP

Posted 03 August 2009 - 09:28 PM

Can you post your code?

You will need to reference the input names in your $_POST or $_GET array. It's going to be hard to assist you with out seeing what you have thus far.
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Getting the value of checkboxes from HTML form to PHP

Posted 03 August 2009 - 09:28 PM

Why not start by showing us how you're attempting to do this (your code) then we can proceed from there :)
Was This Post Helpful? 0
  • +
  • -

#4 raid01alpha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-August 09

Re: Getting the value of checkboxes from HTML form to PHP

Posted 03 August 2009 - 11:01 PM

Thanks a lot for your response and sorry if i was not able to show my codes. Below are my codes.


//here are my PHP codes
<?php

  $motortype1		= $_POST['motortype1'];
  $motortype2		= $_POST['motortype2']; 
  $motortype3		= $_POST['motortype3']; 
  $motortype4		= $_POST['motortype4']; 
  $motortype5		= $_POST['motortype5']; 

  $company_email   = 'myemail@yahoo.com';
  $subject			   = 'Online Registration';
  $headers			 .= "Online Registration Request:\n";

  $msg  .= "If yes, what type?: \n   $motortype1\n";

  mail($company_email, $subject, $msg, $headers);

?>



  //and here are my HTML code for my Form

  <tr>
			<td height="32" class="style11">
	<div align="left">If yes, what type? </div></td>
				<td width="90" height="28" class="style11">
	<div align="left">			 
	   	<input type="checkbox" name="motortype1" value="Cruiser" /> Cruiser
				</div></td>
			
			<td width="84" class="style11">
	<div align="left">
				<input type="checkbox" name="motortype2" value="Tourer" /> Tourer 
				</div></td>
			
			<td height="28" class="style11">
	<div align="left">
				<input type="checkbox" name="motortype3" value="Sports Tourer" /> Sports Tourer 
				</div></td>
			
			 <td width="69" height="28" class="style11">
	<div align="left">
				<input type="checkbox" name="motortype4" value="Sport" /> Sport			
				</div></td>
			
			 <td width="81" height="32" class="style11">
				<div align="left">
				<input type="checkbox" name="motortype5" value="Other" /> Other			
	</div></td>
	   </tr>



If my visitor choose 1 or more motortype, on email sent from the form those selected checkboxes should also be included.

Thanks again!

Mod Edit: Please use code tags when posting your code. Code tags are used like so => :code:

Thanks,
PsychoCoder :)
Was This Post Helpful? 0
  • +
  • -

#5 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Getting the value of checkboxes from HTML form to PHP

Posted 04 August 2009 - 12:18 AM

change your PHP code
<?php

  $motortype1  = isset($_POST['motortype1']) ? $_POST['motortype1'] : 0;
  $motortype2  = isset($_POST['motortype2']) ? $_POST['motortype2'] : 0;
  $motortype3  = isset($_POST['motortype3']) ? $_POST['motortype3'] : 0;
  $motortype4  = isset($_POST['motortype4']) ? $_POST['motortype4'] : 0;
  $motortype5  = isset($_POST['motortype5']) ? $_POST['motortype5'] : 0;

  $company_email   = 'myemail@yahoo.com';
  $subject         = 'Online Registration';
  $headers         .= "Online Registration Request:\n";
  
  $msg  = "If yes, what type?: \n   $motortype1\n";
  mail($company_email, $subject, $msg, $headers);
?>

and also is this your all HTML code?

This post has been edited by noorahmad: 04 August 2009 - 12:47 AM

Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5247
  • View blog
  • Posts: 27,070
  • Joined: 10-May 07

Re: Getting the value of checkboxes from HTML form to PHP

Posted 04 August 2009 - 12:39 AM

The variable $MSG must exist before you can concatenate to it.
Was This Post Helpful? 1
  • +
  • -

#7 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: Getting the value of checkboxes from HTML form to PHP

Posted 04 August 2009 - 12:48 AM

Opps.!!!!!!!!!!!!!! changed.

This post has been edited by noorahmad: 04 August 2009 - 12:50 AM

Was This Post Helpful? 0
  • +
  • -

#8 raid01alpha  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-August 09

Re: Getting the value of checkboxes from HTML form to PHP

Posted 04 August 2009 - 01:05 AM

Project done. Thanks a lot guys! you are all helpful.
Was This Post Helpful? 0
  • +
  • -

#9 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5247
  • View blog
  • Posts: 27,070
  • Joined: 10-May 07

Re: Getting the value of checkboxes from HTML form to PHP

Posted 04 August 2009 - 01:35 AM

Glad to see that you got it working :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1