John Davidson

Get selected data from checkbox in a PHP contact form

0 comments
Message:


I'm using PHPmailer which is working.


But since I'm working with some checkboxes in the contact form I'm running into a problem.


I gave all of the checkboxes the same name which = type[] And they all have different values.
I want to target the selected values and turn that into a variable which I can then target to send in the mail.


This is the code I'm using:


$name = $_POST['name'];
$lastname = $_POST['lastname'];
$type = $_POST['type'];
if(!empty($_POST['type'])) {
foreach($_POST['type'] as $value){
$type = $value;
}
}

$message = "Name: $name<br> lastname: $lastname<br> Type: $type";

This will give me only the last selected value. So if multiple are selected it doesn't show me.
I don't want to use a database to store the values before getting it.



My Answer:
"Name: $name\nLastname: $lastname\nSelected Type: $type\n";

Rate this post

3 of 5 based on 4011 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us