This question already has an answer here:
- Getting checkbox values on submit 10 answers
I was building a PHP form and added checkboxes with multiples values and i don't know how to adding the array code for POST into the PHP target page. I also have display into the table the results separated with free space. I already resolve the radio section but i don't know how to add the checkboxes codes and display them in the HTML table sent by email.
Here are the HTML form
<form id="i-recaptcha" class="form-horizontal" method="post" action="envoi_soumission-pour-fournitures-fr.php" data-toggle="validator">
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<div class="control-group"><label for="nom_compagnie" class="col-sm-4 control-label">Nom de la compagnie</label></div>
<div class="col-sm-8">
<div class="controls"><input type="text" name="nom_compagnie" class="form-control" id="nom_compagnie" placeholder="Nom de votre compagnie (optionnel)" data-validation-optional="true"></div>
</div>
</div>
<div class="form-group">
<div class="control-group"><label for="nom_complet" class="col-sm-4 control-label">Votre nom <sup><i class="fa fa-asterisk" style="font-size: 10px; color:tomato;"></i></sup></label></div>
<div class="col-sm-8">
<div class="text"><input type="nom_complet" name="nom_complet" class="form-control required" id="nom_complet" placeholder="Votre Nom et Prénom" data-validation="length" data-validation-length="min2" data-validation-error-msg="Veuillez au minimum fournir votre prénom !"></div>
</div>
</div>
<div class="form-group">
<div class="control-group"><label for="telephone" class="col-sm-4 control-label">Téléphone <sup><i class="fa fa-asterisk" style="font-size: 10px; color:tomato;"></i></sup></label></div>
<div class="col-xs-8 col-sm-4">
<input type="text" name="telephone" class="form-control" id="telephone" placeholder="XXX XXX-XXXX" data-validation="length" data-validation-length="min7" data-validation-error-msg="Veuillez inscrire un numéro de téléphone !">
</div>
<div class="col-xs-4 col-sm-2">
<input type="text" name="poste" class="form-control required" id="poste" placeholder="Poste">
</div>
</div>
<div class="form-group">
<div class="control-group"><label for="email" class="col-sm-4 control-label">Adresse courriel <sup><i class="fa fa-asterisk" style="font-size: 10px; color:tomato;"></i></sup></label></div>
<div class="col-sm-6">
<div class="controls"><input type="email" name="email" class="form-control required" id="email" placeholder="Adresse courriel existante" data-validation="email" data-validation-error-msg="Veuillez SVP fournir une adresse courriel valide !"></div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="well well-sm" style="background-color: #11519F; color: #FFFFFF">
<span class="fa fa-print"> </span> Informations sur le produit
</div>
<div class="form-horizontal">
<div class="form-group">
<label for="marque" class="col-sm-4 control-label">Marque <sup><i class="fa fa-asterisk" style="font-size: 10px; color:tomato;"></i></sup></label>
<div class="col-sm-5">
<input type="text" name="marque" class="form-control" id="" placeholder="Marque de votre imprimante" data-validation-error-msg="Veuillez SVP inscrire la marque de votre imprimante !" required>
</div>
</div>
<div class="form-group">
<label for="modele" class="col-sm-4 control-label">Modèle de l'imprimante <sup><i class="fa fa-asterisk" style="font-size: 10px; color:tomato;"></i></sup></label>
<div class="col-sm-5">
<input type="text" name="modele" class="form-control" id="" placeholder="Modèle exact de votre imprimante" data-validation-error-msg="Veuillez SVP fournir le modèle de votre imprimante !" required>
</div>
</div>
<div class="form-group">
<label for="toners" class="col-sm-4 control-label col-xs-12" required>Cartouche recherché <sup><i class="fa fa-asterisk" style="font-size: 10px; color:tomato;"></i></sup></label>
<div class="col-sm-2 col-xs-3" style="padding-top: 7px !important;">
<input type="checkbox" name="toners[]" value="NOIR"> <span class="badge badge-b txt-wbs">Noir</span>
</div>
<div class="col-sm-2 col-xs-3" style="padding-top: 7px !important;">
<input type="checkbox" name="toners[]" value="CYAN"> <span class="badge badge-c txt-wbs">Cyan</span>
</div>
<div class="col-sm-2 col-xs-3" style="padding-top: 7px !important;">
<input type="checkbox" name="toners[]" value="MAGENTA"> <span class="badge badge-m txt-wbs">Magenta</span>
</div>
<div class="col-sm-2 col-xs-3" style="padding-top: 7px !important;">
<input type="checkbox" name="toners[]" value="YELLOW"> <span class="badge badge-y txt-bws">Yellow</span>
</div>
</div>
<div class="form-group">
<label for="drums" class="col-sm-4 control-label col-xs-12">Drum/Tambour</label>
<div class="col-sm-2 col-xs-3" style="padding-top: 7px !important;">
<input type="checkbox" id="drum_noir" name="drums[]" value="NOIR"> <span class="badge badge-b txt-wbs">Noir</span>
</div>
<div class="col-sm-2 col-xs-3" style="padding-top: 7px !important;">
<input type="checkbox" id="drum_cyan" name="drums[]" value="CYAN"> <span class="badge badge-c txt-wbs">Cyan</span>
</div>
<div class="col-sm-2 col-xs-3" style="padding-top: 7px !important;">
<input type="checkbox" id="drum_magenta" name="drums[]" value="MAGENTA"> <span class="badge badge-m txt-wbs">Magenta</span>
</div>
<div class="col-sm-2 col-xs-3" style="padding-top: 7px !important;">
<input type="checkbox" id="drum_yellow" name="drums[]" value="JAUNE"> <span class="badge badge-y txt-bws">Yellow</span>
</div>
</div>
<div class="form-group radio">
<label for="capacite" class="col-sm-4 control-label col-xs-12">Capacité <sup><i class="fa fa-asterisk" style="font-size: 10px; color:tomato;"></i></sup></label>
<div class="col-sm-2 col-xs-12" style="padding-top: 7px !important; font-size: 15px;">
<input type="radio" id="capacite_standard" name="capacite" value="STANDARD CAPACITE" checked> Standard
</div>
<div class="col-sm-3 col-xs-12" style="padding-top: 7px !important; font-size: 15px;">
<input type="radio" id="haute_capacite" name="capacite" value="HAUTE CAPACITÉ"> Haute Capacité
</div>
<div class="col-sm-3 col-xs-12" style="padding-top: 7px !important; font-size: 15px;">
<input type="radio" id="extra_haute_capacite" name="capacite" value="EXTRA HAUTE CAPACITÉ"> Extra Haute Capacité
</div>
</div>
<div class="form-group radio">
<label for="qualite" class="col-sm-4 control-label col-xs-12">Qualité <sup><i class="fa fa-asterisk" style="font-size: 10px; color:tomato;"></i></sup></label>
<div class="col-sm-2 col-xs-6" style="padding-top: 7px !important; font-size: 15px;">
<input type="radio" id="qualite_oem" name="qualite" value="QUALITÉ ORIGINE" checked> Authentique
</div>
<div class="col-sm-3 col-xs-6" style="padding-top: 7px !important; font-size: 15px;">
<input type="radio" id="qualite_generique" name="qualite" value="GÉNÉRIQUE"> Générique
</div>
</div>
<div class="form-group">
<label for="no_ref" class="col-sm-4 control-label">Numéro(s) de référence</label>
<div class="col-sm-8">
<input type="text" name="no_ref" class="form-control" placeholder="Si vous avez le numéro de produit exact, entrez-les ici.">
</div>
</div>
<div class="form-group">
<label for="commentaire" class="col-sm-4 control-label">Notes ou commentaires?</label>
<div class="col-sm-8">
<textarea rows="4" type="commentaire" name="commentaire" class="form-control" placeholder=""></textarea>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button class="g-recaptcha" data-sitekey="MASKED" data-callback="onSubmit" data-badge="inline" type="submit">Soumettre</button>
</div>
</div>
<script src="https://www.google.com/recaptcha/api.js?onload=onLoad&render=explicit" async defer></script>
</div><!-- col-sm-12 main area -->
</div>
</form>
Here are the PHP file:
<?php
function post_captcha($user_response) {
$fields_string = '';
$fields = array(
'secret' => 'MASKED',
'response' => $user_response
);
foreach($fields as $key=>$value)
$fields_string .= $key . '=' . $value . '&';
$fields_string = rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}
$res = post_captcha($_POST['g-recaptcha-response']);
if (!$res['success']) {
// What happens when the reCAPTCHA is not properly set up
echo 'reCAPTCHA error: Check to make sure your keys match the registered domain and are in the correct locations. You may also want to doublecheck your code for typos or syntax errors.';
} else {
// If CAPTCHA is successful...
// Paste mail function or whatever else you want to happen here!
$to = "PRIVATE";
$subject = "PRIVATE - Demande de prix pour consommables";
$nom_compagnie = $_POST['nom_compagnie'];
$nom_complet = $_POST['nom_complet'];
$poste = $_POST['poste'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$marque = $_POST['marque'];
$modele = $_POST['modele'];
$toner_noir = $_POST['toner_noir'];
$toner_cyan = $_POST['toner_cyan'];
$toner_magenta = $_POST['toner_mangenta'];
$toner_yellow = $_POST['toner_yellow'];
$drum_noir = $_POST['drum_noir'];
$drum_cyan = $_POST['drum_cyan'];
$drum_magenta = $_POST['drum_magenta'];
$drum_yellow = $_POST['drum_yellow'];
$capacite = $_POST['capacite'];
$qualite = $_POST['qualite'];
$capacite_standard = $_POST['capacite_standard'];
$haute_capacite = $_POST['haute_capacite'];
$extra_haute_capacite = $_POST['extra_haute_capacite'];
$qualite_oem = $_POST['qualite_oem'];
$qualite_generique = $_POST['qualite_generique'];
$no_ref = $_POST['no_ref'];
$commentaire = $_POST['commentaire'];
$from = $_POST['email'];
$message = "
<!doctype html>
<html>
<head>
<meta charset=\"utf-8\">
<title>Demande de prix pour consommables</title>
</head>
<h3 style=\"font-family: Segoe, 'Segoe UI', 'DejaVu Sans', 'Trebuchet MS', Verdana, 'sans-serif'; 1.15em; color:#5BA8F6; font-weight: 400;\">Vous avez reçu une demande de prix pour consommables sur votre site de Copiscan</h3>
<h3 style=\"color:#1E3A6E; font-family: Arial,Helvetica Neue,Helvetica,sans-serif; font-weight: 400\">DÉTAILS SUR LE CONTACT</h3>
<table width=\"475\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\">
<tbody>
<tr>
<th align=\"left\" height=\"25\" width=\"200\" style=\"font-family: Segoe, 'Segoe UI', 'DejaVu Sans', 'Trebuchet MS', Verdana, 'sans-serif'; 1.15em; background-color:#11519F; color: #FFFFFF !important; font-weight: 400\"> <span style=\"color: #FFFFFF;\">Nom de la compagnie </span></th>
<td width=\"300\" style=\"background-color:#E8E8E8; font-family: Arial,Helvetica Neue,Helvetica,sans-serif; \"> $nom_compagnie</td>
</tr>
<tr>
<th align=\"left\" height=\"25\" width=\"200\" style=\"background-color:#11519F; font-family: Segoe, 'Segoe UI', 'DejaVu Sans', 'Trebuchet MS', Verdana, 'sans-serif'; 1.15em; color: #FFFFFF !important; font-weight: 400\"> <span style=\"color: #FFFFFF;\">Nom du client </span></th>
<td width=\"300\" style=\"background-color:#E8E8E8; font-family: Arial,Helvetica Neue,Helvetica,sans-serif;\"> $nom_complet</td>
</tr>
<tr>
<th align=\"left\" height=\"25\" width=\"200\" style=\"background-color:#11519F; font-family: Segoe, 'Segoe UI', 'DejaVu Sans', 'Trebuchet MS', Verdana, 'sans-serif'; 1.15em; color: #FFFFFF !important; font-weight: 400\"> <span style=\"color: #FFFFFF;\">Téléphone</span> </th>
<td width=\"300\" style=\"background-color:#E8E8E8; font-family: Arial,Helvetica Neue,Helvetica,sans-serif; \"> $telephone ext: $poste</td>
</tr>
<tr>
<th align=\"left\" height=\"25\" width=\"200\" style=\"background-color:#11519F; font-family: Segoe, 'Segoe UI', 'DejaVu Sans', 'Trebuchet MS', Verdana, 'sans-serif'; 1.15em; color: #FFFFFF !important; font-weight: 400\"> <span style=\"color: #FFFFFF;\">Adresse courriel </span></th>
<td width=\"300\" style=\"background-color:#E8E8E8; font-family: Arial,Helvetica Neue,Helvetica,sans-serif; \"> $email</td>
</tr>
</tbody>
</table>
<h3 style=\"color:#1E3A6E; font-family: Arial,Helvetica Neue,Helvetica,sans-serif; font-weight: 400\">DÉTAILS SUR LE(S) PRODUIT(S) DEMANDÉ(S)</h3>
<table width=\"475\" border=\"1\" cellspacing=\"1\" cellpadding=\"2\">
<tbody>
<tr>
<th align=\"left\" height=\"25\" width=\"200\" style=\"font-family: Segoe, 'Segoe UI', 'DejaVu Sans', 'Trebuchet MS', Verdana, 'sans-serif'; 1.15em; background-color:#0080FF; color: #FFFFFF !important; font-weight: 400\"> <span style=\"color: #FFFFFF;\">Marque de l'imprimante </span></th>
<td width=\"300\" style=\"background-color:#E8E8E8; font-family: Arial,Helvetica Neue,Helvetica,sans-serif; \"> $marque</td>
</tr>
<tr>
<th align=\"left\" height=\"25\" width=\"200\" style=\"background-color:#0080FF; font-family: Segoe, 'Segoe UI', 'DejaVu Sans', 'Trebuchet MS', Verdana, 'sans-serif'; 1.15em; color: #FFFFFF !important; font-weight: 400\"> <span style=\"color: #FFFFFF;\">Modèle de l'imprimante </span></th>
<td width=\"300\" style=\"background-color:#E8E8E8; font-family: Arial,Helvetica Neue,Helvetica,sans-serif;\"> $modele</td>
</tr>
<tr>
<th align=\"left\" height=\"25\" width=\"200\" style=\"background-color:#0080FF; font-family: Segoe, 'Segoe UI', 'DejaVu Sans', 'Trebuchet MS', Verdana, 'sans-serif'; 1.15em; color: #FFFFFF !important; font-weight: 400\"> <span style=\"color: #FFFFFF;\">Numéro de référence(s)</span> </th>
<td width=\"300\" style=\"background-color:#E8E8E8; font-family: Arial,Helvetica Neue,Helvetica,sans-serif; \"> $no_ref</td>
</tr>
<tr>
<th align=\"left\" height=\"25\" width=\"200\" style=\"background-color:#0080FF; font-family: Segoe, 'Segoe UI', 'DejaVu Sans', 'Trebuchet MS', Verdana, 'sans-serif'; 1.15em; color: #FFFFFF !important; font-weight: 400\"> <span style=\"color: #FFFFFF;\">Toners </span></th>
<td width=\"300\" style=\"background-color:#E8E8E8; font-family: Arial,Helvetica Neue,Helvetica,sans-serif; \"> $toner_noir $toner_cyan $toner_magenta $toner_yellow</td>
</tr>
<tr>
<th align=\"left\" height=\"25\" width=\"200\" style=\"background-color:#0080FF; font-family: Segoe, 'Segoe UI', 'DejaVu Sans', 'Trebuchet MS', Verdana, 'sans-serif'; 1.15em; color: #FFFFFF !important; font-weight: 400\"> <span style=\"color: #FFFFFF;\">Tambours </span></th>
<td width=\"300\" style=\"background-color:#E8E8E8; font-family: Arial,Helvetica Neue,Helvetica,sans-serif; \"> $value $drum_noir $drum_cyan $drum_magenta $drum_yellow</td>
</tr>
<tr>
<th align=\"left\" height=\"25\" width=\"200\" style=\"background-color:#0080FF; font-family: Segoe, 'Segoe UI', 'DejaVu Sans', 'Trebuchet MS', Verdana, 'sans-serif'; 1.15em; color: #FFFFFF !important; font-weight: 400\"> <span style=\"color: #FFFFFF;\">Capacité</span></th>
<td width=\"300\" style=\"background-color:#E8E8E8; font-family: Arial,Helvetica Neue,Helvetica,sans-serif; \"> $capacite $capacite_standard $haute_capacite $extra_haute_capacite</td>
</tr>
<tr>
<th align=\"left\" height=\"25\" width=\"200\" style=\"background-color:#0080FF; font-family: Segoe, 'Segoe UI', 'DejaVu Sans', 'Trebuchet MS', Verdana, 'sans-serif'; 1.15em; color: #FFFFFF !important; font-weight: 400\"> <span style=\"color: #FFFFFF;\">Qualite</span></th>
<td width=\"300\" style=\"background-color:#E8E8E8; font-family: Arial,Helvetica Neue,Helvetica,sans-serif; \"> $qualite $qualite_oem $qualite_generique</td>
</tr>
</tbody>
</table>
<p style=\"font-family: Arial,Helvetica Neue,Helvetica,sans-serif;\">Notes laissé par le visiteur :<br />$commentaire</p>
<body>
</body>
</html>
";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=UTF-8' . "\r\n";
$headers .= "From: $from\r\n";
$headers .= "Reply-to: $email\r\n";
$headers .= "Cc: $cc\r\n";
$headers .= "X-Mailer: PHP v" . phpversion() . "\r\n";
mail($to, $subject, $message, $headers);
header('Location: envoi_soumission-pour-fournitures_success-fr.html');
}
?>
Aucun commentaire:
Enregistrer un commentaire