Jump to content

[SOLVED] Setting array to one variable to display later


ratgurrl

Recommended Posts

I'd like to preface by saying that arrays and regex are not my fortes....  This time I am having issues with an array, and I can't wrap my brain around how to do what I need to do, even after looking at many examples...

 

I have a multiple select field in a form...

<select name="propExterior[]" size="5" multiple="multiple" id="propExterior">
    <option value="Aluminum/Vinyl">Aluminum/Vinyl</option>
    <option value="Brick">Brick</option>
    <option value="Cedar">Cedar</option>
    <option value="Concrete">Concrete</option>
    <option value="Dryvit">Dryvit</option>
    <option value="Hardiboard">Hardiboard</option>
    <option value="Stucco">Stucco</option>
    <option value="Steel/Glass">Steel/Glass</option>
    <option value="Other">Other</option>
</select>

 

I (think) this should pass the array of selected items...

if (isset($_POST['pricingSubmit'])) {
    $propExterior = $_POST['propExterior'];
...
}

 

Then, after all the variables are set from the posted form, I am formatting an email...

...
    $body = "\n\nProperty Information\n\n";
    $body .= "Property Type: $propType\n";
    $body .= "Property Address: $propAddress\n";
    $body .= "Subdivision/Neighborhood: $propHood\n";
    $body .= "Bedrooms: $numBedroom\n";
    $body .= "Exterior: $propExterior\n";
...

 

So basically I need '$propExterior = Brick, Concrete, Stucco' (or whatever items are selected), so the line in the email will look like this...

 

Exterior: Brick, Concrete, Stucco (or whatever items are selected). 

 

Any help would be much appreciated.  I've officially hit a brick wall, and I'm getting more confused the more I look.

 

???

 

Many Thanks,

Jennifer

Link to comment
Share on other sites

add me to MSN I actively help most of the people on my friends list with PHP and MySQL so you would fit in nicely..

 

I also have done few tutor jobs for money but I prefer to help for free.

 

My name is Russell and my MSN is RussellonMSN [AT] hotmail.com

 

also: try <?php print_r($_POST); ?> to see if your values r being sent, and the construct of the print_r will tell you how you should reference the values

Link to comment
Share on other sites

<?php
if(isset($_POST['pricingSubmit'])) {
   foreach($_POST['propExterior'] as $key => $value) {
      $propExterior .= $value . ", ";
   }
  echo $propExterior;
}
?>

 

Or just implode() :)

 

<?php
if(is_array($_POST['propExterior']))
$propExterior = implode(', ',$_POST['propExterior']);
else
$propExterior = $_POST['propExterior'];
echo $propExterior
?>

 

Link to comment
Share on other sites

Maq, I love you!

 

Thank you so much... you have prevented me from going completely bald.

 

King, Thanks too!  I had tried the implode (based on an example I had seen), but was messing it up somehow...

 

I appreciate both of your suggestions and help!  It is working now.

 

Jennifer <3

Link to comment
Share on other sites

Maq, I love you!

 

Thank you so much... you have prevented me from going completely bald.

 

Jennifer

 

You're welcome  :P

 

Although, you may want to use KingPhilip's solution because it will eliminate the last comma with the least amount of code.

Link to comment
Share on other sites

I was tryna help her figure it out on her own :)

 

I appreciate Russell, but I had already spent all of last night pulling my hair out - I usually wait until I get uber frustrated before asking for help.  I had gotten so close (based on the examples above), but wasn't getting it to work.

 

Appreciate all the help...

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.