Need help with multiple selection

General discussions related to php

Moderators: egami, macek, gesf

Post Reply
User avatar
opencodez
New php-forum User
New php-forum User
Posts: 1
Joined: Mon May 28, 2018 2:31 pm

Mon May 28, 2018 3:05 pm

I have been stuck on this problems with the multi-selector on my website at www.opencodezllc.com
My check boxes aren't functional on my contact page which is coded in PHP
The data doesn't seem to be processed or submitted to my email no matter what code I put in
It is functional on the user's side as in it checks the boxes but when I get the email it doesn't tell me what the user put in the checkboxes
The link to the contact page is here:
https://www.opencodezllc.com/contact-opencodez.html
please help :help: :help: :help:

AdoptiveSolution
New php-forum User
New php-forum User
Posts: 167
Joined: Wed Jun 15, 2016 8:35 am

Tue May 29, 2018 10:42 am

Give the checkboxes in the form a name :

Code: Select all

<input type="checkbox" name="services[IT Design]" value="IT Design">IT Design
<input type="checkbox" name="services[App Design]" value="App Design">App Design
<input type="checkbox" name="services[Graphic Design]" value="Graphic Design">Graphic Design
<input type="checkbox" name="services[Web Design]" value="Web Design">Web Design
Then put this code in the contact.php file to see what's received from the form.
Process it further in your email message.

Code: Select all

<?php
echo '<pre>';
print_r($_POST);
echo '</pre>';
/*
[first_name] => First name
[last_name] => Last name
[email] => firstname@lastname.net
[phone] => 345 6789
[services] => Array
	(
	[IT Design] => IT Design
	[App Design] => App Design
	[Graphic Design] => Graphic Design
	[Web Design] => Web Design
	)
*/     
?>

<p>Name : <?php echo $_POST[first_name] . ' ' . $_POST[last_name]; ?><br />
Email :   <?php echo $_POST[email]; ?><br />
Phone :   <?php echo $_POST[phone]; ?><br />
Services :<br />
<ul>
	<li>IT Design      <?php echo ( $_POST[services]['IT Design']      == TRUE ? ' <b>&#10003;</b>' : '' ); ?></li>
	<li>App Design     <?php echo ( $_POST[services]['App Design']     == TRUE ? ' <b>&#10003;</b>' : '' ); ?></li>
	<li>Graphic Design <?php echo ( $_POST[services]['Graphic Design'] == TRUE ? ' <b>&#10003;</b>' : '' ); ?></li>
	<li>Web Design     <?php echo ( $_POST[services]['Web Design']     == TRUE ? ' <b>&#10003;</b>' : '' ); ?></li>
</ul>

<ul>
<?php
// or loop 
foreach ($_POST[services] as $name => $value) {
	echo ( $value == TRUE ? '<li><b>&#10003;</b> ' . $name . '</li>' : '' );
}
?>
</ul>
</p>

Post Reply