Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialjoeboo2529
9,805 PointsHow to submit checkboxes?
<div class="row"> <div class="col-sm-6">
<?php $salarysurveys = array('general' => 'General Surveys',
'industry' => 'Industry Surveys',
'local' => 'Local Surveys',
'club' => 'Club / HR Surveys',
'tailormade' => 'Tailormade Surveys');
?>
<?php foreach ($salarysurveys as $key => $salarysurvey): ?>
<?php echo "<p class='label-p'>$salarysurvey</p>" ; ?>
<?php endforeach ?>
</div>
<div class="col-sm-6 center-checkbox">
<?php foreach ($salarysurveys as $key => $salarysurvey): ?>
<?php echo "<input name='salarysurveys[]' type='checkbox' value='$key'>"; ?>
<?php endforeach ?>
</div>
</div><!-- end row -->
2 Answers
Christian Andersson
8,712 PointsIs that your complete HTML? I assume you are writing a form using the <form>
tag? If so, are you using the POST or GET method? When submitting, is the user redirected to a different page or does the same one re-load?
joeboo2529
9,805 PointsHi christian. Yes it is my complete HTML form (ish). i'm using POST when submitting a form to a page called check-contact-form.php. This page is checking whether the inputs is empty or has any malicious input or not. Once the form is submit, it redirect back to the same page and add a string of ?=status
joeboo2529
9,805 Pointsjoeboo2529
9,805 Points// Check form page
<?php
// turn off errors error_reporting(E_ALL ^ E_NOTICE);
if ($_SERVER["REQUEST_METHOD"] == "POST") { $companyname = trim($_POST["companyname"]); $contact_jobtitle = trim($_POST["contact_jobtitle"]); $title = trim($_POST["title"]); $fullname = trim($_POST["fullname"]); $address = trim($_POST["address"]); $tel = trim($_POST["tel"]); $email = trim($_POST["email"]); $details = trim($_POST["details"]); // $salarysurveys = $_POST['salarysurveys']; // $hrpolicysurveys = $_POST['hrpolicysurveys'];
}
?>