Jump to content

Need a little bit of code help


DonelleJenae

Recommended Posts

Can someone who knows php please help?

 

I am new to php. After a lot of research, I got my form to work by using some php code, however I know nothing about it and I am not sure what I need to add to make stuff work etc.

 

I have a form mailer script that I created in php and I have an option on my html form that I want users to be able to select multiple options using control+click, however, when I test the form only the first option selected comes to my email inbox. Everything else works how it should, except for that.

 

Here is my code. Do I need to add something in my php to make it work? If so what code to I need to add, where to I add it?

 

<?php

$property = $_POST['property'];

$cities = $_POST['cities'];

$other = $_POST['other'];

$min = $_POST['min'];

$max = $_POST['max'];

$feet = $_POST['feet'];

$type = $_POST['type'];

$rooms = $_POST['rooms'];

$bath = $_POST['bath'];

$comments = $_POST['comments'];

$email = $_POST['email'];

 

header( "Location: http://www.findourpad.com/thanks.htm" );

 

$to = "[email protected]";

$subject = ";Custom Home Search Results";

 

$eol="\r\n";

 

$headers = "From: ". $full_name ." <". $email .">".$eol;

$headers .= "Reply-To: ". $full_name." <". $email .">".$eol;

 

$message .= ";Property Type: ". $property . "\n";

$message .= ";Cities: ". $cities."\n";

$message .= ";Other Locations: ". $other . "\n";

$message .= ";Minimum Price: ". $min . "\n";

$message .= ";Maximum Price: ". $max . "\n";

$message .= ";Square Feet: ". $feet . "\n";

$message .= ";Home Type: ". $type . "\n";

$message .= ";Minimum Bedrooms: ". $rooms . "\n";

$message .= ";Minimum Bathrooms: ". $bath . "\n";

$message .= ";Additional Comments: ". $comments . "\n";

$message .= ";Email Address: ". $email . "\n";

 

foreach($_POST as $k => $v) {

        if ($v == '') continue; // skip empty fields

 

        if($htmlFormat) {

                $v = str_replace("\n","<br>\n",$v);

        }

        if (is_array($v)) {

                for ($z=0;$z<count($v);$z++) {

                        if($i) {

                                $msg .= "$bl0$k:$ld$v[$z]$el";

                        } else {

                                $msg .= "$bl1$k:$ld$v[$z]$el";

                        }

                        $i = !$i;

                }

        } else {

                if($i) {

                        $msg .= "$bl0$k:$ld$v$el";

                } else {

                        $msg .= "$bl1$k:$ld$v$el";

                }

                $i = !$i;

        }

}

 

if(mail("$to", "$subject", "$message", "$headers")){

 

echo "Mail Was Sent, Check Your Junk or Inbox.";

 

}else{

 

echo "There was an error delivering your message, please try again";

 

 

}

 

?>

Link to comment
https://forums.phpfreaks.com/topic/92946-need-a-little-bit-of-code-help/
Share on other sites

I don't know anything about php. What code to I need to add and where on the form do I need to add it.

 

I have my form set up, my variable for my option is named cities, I have 8 or so city selections on a drop down menu for a user to pick from. My php script works just fine, I get my results to my inbox, it directs the user to a thank you page, etc.

 

But when a user selects multiple options, only the first on selected is listed in my results. I don't know what code to add, where to add it, etc.

 

I am a total php newbie and it took me a while to even understand it enough to get this much of it working.

 

Step 1. Format your <select> as

 

<select name="field_name[]" size="##" multiple>

 

The [] says your submitting an array,

 

Step 2. Your not going to want to see an ugly array line so

 

$field_name = implode(', ', $_POST['field_name']);

 

Therefor if some one selects

 

This option

That option

Oh and the other option

 

The string will be produced

 

This option, That option, On and the other option

Okay in your form html what I said above change the <select> so the name tag's contents ends with []

 

In the php script

 

change whatever that from was from

 

$_POST['name']

 

to

 

implode(', ', $_POST['name']);

 

replacing name with whatever the form element name was.

Okay, I tried that, hopefully I did it right, I will test it and see if it works. Thank you very much.

 

I have asked a ton of people I know how to get this to work and I don't know anyone who knows php that got back to me, I signed up here and posted and I have got more help here so far than anywhere or with anyone else.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.