Skip to main content
Legend
June 4, 2009
Question

Simple php form help, I think (checkboxes)

  • June 4, 2009
  • 2 replies
  • 886 views

Hey php gurus!

I need to handle some checkboxs in my form to return colour choices.

I'm using an array to collect the colour information from the checboxes:

<input type="checkbox" name="colours[ ]" value="Red">Red<br />

<input type="checkbox" name="colours[ ]" value="Blue">Blue<br />

<input type="checkbox" name="colours[ ]" value="Green">Green<br />

<input type="checkbox" name="colours[ ]" value="Yellow">Yellow<br />

Then I want the selected choice of colours to be mailed to an email address. All the other information works but when the data is sent through all I get for the colour selection is:

I'm interested in these colours: Array

Here's the php for the $body of the mesage:

$body = "Please contact me regarding the following:\r\n\r\n";
$body .= "Name: ".stripslashes($_POST['name'])."\r\n";
$body .= "Address: ".stripslashes($_POST['address'])."\r\n";
$body .= "Postcode: ".stripslashes($_POST['postcode'])."\r\n";
$body .= "Telephone: ".stripslashes($_POST['telephone'])."\r\n";
$body .= "Email: ".stripslashes($_POST['email'])."\r\n";
$body .= "I'm interested in these colours: ".$_POST['colours']."\r\n";

Humm....... I'm guessing I need a bit more php to acomplish this?

This topic has been closed for replies.

2 replies

David_Powers
Inspiring
June 4, 2009

$_POST['colours'] is an array, so you need to expand it with explode().

$body .= "I'm interested in these colours: ".explode(', ', $_POST['colours'])."\r\n";

osgood_Author
Legend
June 4, 2009

Hi David,

Copied and pasted that code but I'm still getting:

I'm interested in these colours: Array

Any other thoughts??

Thanks

Os

David_Powers
Inspiring
June 4, 2009

Sorry, it should be implode().

$body .= "I'm interested in these colours: ".implode(', ', $_POST['colours'])."\r\n";

explode() converts a string into an array; implode() converts an array into a string.

David_Powers
Inspiring
June 4, 2009

Moved to the Dreamweaver Application Development forum.