Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Simple php form help, I think (checkboxes)

LEGEND ,
Jun 04, 2009 Jun 04, 2009

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?

TOPICS
Server side applications
890
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 04, 2009 Jun 04, 2009

Moved to the Dreamweaver Application Development forum.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 04, 2009 Jun 04, 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";

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 04, 2009 Jun 04, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 04, 2009 Jun 04, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 04, 2009 Jun 04, 2009

Hi David,

I did try 'implode' when 'explode' didn't seem to work but the result still returns as just 'Array' in the email rather than the actual 'value' associated with the checkboxes.

Hummmm......its baffling me. The line of php below should get the colours from the 'value' of each check box with the name 'colours[ ]' array and then pass it through to the email?

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

Os

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 04, 2009 Jun 04, 2009

Wait a minute I think this may be working now!

I have no idea why at all. Been trying all combinations for a couple of hours and it seems to have suddenly started working I think.

It's worked twice while testing but my emails gone down now so I need to test a few more times before I can convince myself.

Will report back soon.

Os

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 04, 2009 Jun 04, 2009
LATEST

Ya! its working!

Thanks for your help David.

Not sure why it has just started to work, possibly because I was getting a bit confused as to why it wasn't and all the tinkering around I'd probably upset something in the php code.

Certainly needed the input from someone like you who knows his php. I wouldn't of got there in a zillion years without. I'd been looking around on the net for a simple solution but the ones I found were all beyond my capabilities.

Now to do some more tweaking, lol, hope I don't upset anything again. I'll do some stage by stage back-up files.

Thanks

Os

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines