5 Replies - 2422 Views - Last Post: 30 November 2011 - 07:37 PM Rate Topic: -----

#1 kiad_198  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 128
  • Joined: 19-November 08

multiple selected checkbox send to email problem...

Posted 31 August 2011 - 12:12 PM

Hi guyz,

Here's what I'm saying, there is a 3 checkbox that can select 1, 2 or 3. But my code can only get 1 value out of 3 if I'm going to select all 3.

Here's the code:

Form Page 1

<input type="checkbox" name="cb[]" value="1" />
 <input type="checkbox" name="cb[]" value="2" />
 <input type="checkbox" name="cb[]" value="3" />






PHP Page 2 - this side working accordingly.
<?php
if(isset($_POST['email'])) {
	
	// EDIT THE 2 LINES BELOW AS REQUIRED
	$email_to = "sample@gmail.com";
	$email_subject = "Sample Application";	
	
		
	$fname = $_POST['fname']; // required
	$mname = $_POST['mname']; // required
	$lname = $_POST['lname']; // required
        $lname = $_POST['cb[]']; // required

        function clean_string($string) {
	  $bad = array("content-type","bcc:","to:","cc:","href");
	  return str_replace($bad,"",$string);
	}

        $email_message .= "Name: ".clean_string($fname)." ".clean_string($mname).". " .clean_string($lname)."\n";
        $email_message .= "Select ".clean_string($cb[])."\n";[quote]this result got one(1) value only[/quote]

$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  ;}
?>



I need help in this area.

How can I create an array in this type of code?
Where can I put the array?

I've try this one but I don't know where this code to be place.

$ids =  $this->input->get_post('cb');
   if(!empty($ids)){
     foreach($ids as $id){
        // get email id from database or directly give email address to check box value 
    }
  } 


I need help in this problem...

thanks

kiad

This post has been edited by kiad_198: 31 August 2011 - 12:12 PM


Is This A Good Question/Topic? 0
  • +

Replies To: multiple selected checkbox send to email problem...

#2 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1004
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: multiple selected checkbox send to email problem...

Posted 31 August 2011 - 12:24 PM

Your code makes no sense:
<?php
if(isset($_POST['email'])) {

        // ...

	$lname = $_POST['lname']; // required
        $lname = $_POST['cb[]']; // required

        // ...

        $email_message .= "Select ".clean_string($cb[])."\n";



$_POST['cb'] is an array which you use accordingly. What you've done makes no sense, I think what you're looking for is something along the lines of:
echo 'User Selected: ' . implode(', ', $_POST['cb']);


That should put you on the right track to place it into "your" code.
Was This Post Helpful? 1
  • +
  • -

#3 kiad_198  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 128
  • Joined: 19-November 08

Re: multiple selected checkbox send to email problem...

Posted 31 August 2011 - 06:16 PM

View PostRudiVisser, on 31 August 2011 - 12:24 PM, said:

Your code makes no sense:
<?php
if(isset($_POST['email'])) {

        // ...

	$lname = $_POST['lname']; // required
        $lname = $_POST['cb[]']; // required

        // ...

        $email_message .= "Select ".clean_string($cb[])."\n";



$_POST['cb'] is an array which you use accordingly. What you've done makes no sense, I think what you're looking for is something along the lines of:
echo 'User Selected: ' . implode(', ', $_POST['cb']);


That should put you on the right track to place it into "your" code.



Thanks for the reply...

Where should put that code or what code I will replace that?

Thanks...
Was This Post Helpful? 1
  • +
  • -

#4 kiad_198  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 128
  • Joined: 19-November 08

Re: multiple selected checkbox send to email problem...

Posted 31 August 2011 - 08:17 PM

Got it now thanks

Here's the code :

	<?php
if(isset($_POST['email'])) {
	     
	    // EDIT THE 2 LINES BELOW AS REQUIRED
	    $email_to = "sample@gmail.com";
	    $email_subject = "Sample Application"; 
	     
	         
	    $fname = $_POST['fname']; // required
	    $mname = $_POST['mname']; // required
	    $lname = $_POST['lname']; // required
            $allcd = implode(", ", $_POST['cb']);// required
	 
	        function clean_string($string) {
	      $bad = array("content-type","bcc:","to:","cc:","href");
        return str_replace($bad,"",$string);
	    }
	 
	        $email_message .= "Name: ".clean_string($fname)." ".clean_string($mname).". " .clean_string($lname)."\n";
	        $email_message .= "Select ".clean_string($allcd)."\n";[quote]this result got one(1) value only[/quote]
	 
	$headers = 'From: '.$email_from."\r\n".
	'Reply-To: '.$email_from."\r\n" .
	'X-Mailer: PHP/' . phpversion();
	@mail($email_to, $email_subject, $email_message, $headers);  ;}
	?>


Was This Post Helpful? 1
  • +
  • -

#5 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1004
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: multiple selected checkbox send to email problem...

Posted 31 August 2011 - 11:05 PM

Glad you got it sorted - I wasn't going to give you full code so that you could actually learn something from it :D
Was This Post Helpful? 0
  • +
  • -

#6 Shaz3e  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-November 11

Re: multiple selected checkbox send to email problem...

Posted 30 November 2011 - 07:37 PM

You both save me thank you guys,
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1