Jump to content

Select & checkbox values don’t show up in submitted form


ThatGuyRay

Recommended Posts

Pulling my hair out trying to get checkbox and a selector values into my email.

The only email results I recieve are: Name/Email/Website/Message

 

I dont know what Im missing to get the Checkbox values submitted.

Ive included a link and attached the files for reference.

http://iinobe.com/formTest/contact.html

 

Any insight, assistance or resources that would help solve this issue would be greatly appreciated.

Thanks

Ray

 

 

BASIC CODE:
 
<input type="checkbox" id="b1" name="vehicle[]" value="Bike">I have a bike<br>
<input type="checkbox" id="b1" name="vehicle[]" value="Car">I have a car 
<input type="checkbox" id="b1" name="vehicle[]" value="Walk">I walk 
 
<select  id="choose">
 <option>1</option>
 <option>2</option>
 <option>3</option>
</select>
 
 
My additions to PHP:
$b1 = implode(', ', $_POST['b1'] );
$choose = $_POST['choose'];
 
\n\nType: $b1
\n\nChoice: $choose
 
 
 
Link to comment
Share on other sites

To add to benanamen's response, it is not valid HTML markup to have multiple elements with the same id as you have with the checkboxes. The id for each element must be unique.

 

 

<select  id="choose" name="choose">

 

 

$vehicles = implode(', ', $_POST['vehicles'] );
$choose = $_POST['choose'];
Link to comment
Share on other sites

Thanks for the response.

I am a definitely a novice.

 

Im using a pre-existing form from a template and the template developer made the following suggestion:

"  Give unique ids to the inputs and use the ids on global variable (for ex. $_POST['your_id']).  "

 

 

Ive made the id edits as suggested, but still no results in email:

 

<input type="checkbox" id="b1" name="vehicle[]" value="Bike">I have a bike<br>

<input type="checkbox" id="b2" name="vehicle[]" value="Car">I have a car 
<input type="checkbox" id="b3" name="vehicle[]" value="Walk">I walk 
 
<select class="form-control" name="choose" id="choose">
 <option>1</option>
 <option>2</option>
 <option>3</option>
</select>
 
 
PHP:
 
<?php
 
if(empty($_POST['name'])   ||
   empty($_POST['email']) ||
   empty($_POST['message']) ||
   !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
   {
echo "No arguments Provided!";
return false;
   }
 
 
$vehicles = implode(', ', $_POST['vehicles'] );
$choose = $_POST['choose'];
 
$name = $_POST['name'];
$email_address = $_POST['email'];
$website = $_POST['website'];
$message = $_POST['message'];
 
// Create the email and send the message
$to = 'biz@iinobe.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form:  $name";
$email_body = "You have received a new message from your website contact form.
 
\n\n"."Here are the details:
\n\nName: $name
\n\nType: $vehicles
\n\nChoice: $choose
\n\nEmail: $email_address
\n\nWebsite: $website
\n\nMessage:\n$message";
 
 
$headers = "From: noreply@gmail.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
 
 
 
 
Thanks for your help.
Link to comment
Share on other sites

“vehicles” isn't the same as “vehicle”. Yes, you have to be exact.

 

In any case, it's time for you to learn basic debugging steps.

  • Forget about the e-mails. Right now, you cannot even assemble the message correctly, so it's nonsensical to add complex mail sending logic which may introduce even more errors. Remove the mail() call for now.
  • Learn how to inspect variables with var_dump(). For example, var_dump($_POST) will tell you exactly what the $_POST array contains (and what it doesn't contain).
  • When you're more experienced, check out professional debuggers like XDebug. This will save you a lot of time.
Link to comment
Share on other sites

Thanks.

I have actually updated the code - but no results:

 
<input type="checkbox" id="b1" name="vehicle[]" value="Bike">I have a bike<br>
<input type="checkbox" id="b2" name="vehicle[]" value="Car">I have a car 
<input type="checkbox" id="b3" name="vehicle[]" value="Walk">I walk 
 
<select class="form-control" name="choose" id="choose" form="sentMessage">
 <option value="uno">1</option>
 <option value="dos">2</option>
 <option value="tres">3</option>
</select>
 
 
This may be over my head at this point.
Thanks for your 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.