Checkboxes in a form
Posted: Fri Aug 14, 2009 1:15 pm
I have a small problem in a form. I have adapted a contact form for use as a questionnaire, but I have added two checkbox questions.
I have added the two questions ok, and they show up ok on my webpage. However, when the form is submitted, it is not including the results of the checkbox questions because I haven't changed the code from what it was (which was a simple text field). I know that I need to add some code that is something like "foreach" to go through each box and add the result to another field if it is checked, but I have no idea how to do it.
I'm not a developer, nor a web designer, just a bit of an amateur techie.
Can anyone help me? I asked a couple of designers and they wanted access to my site and my logins and so on, and I didn't really want to give anyone that much access.
This is my code for the bit that first explains the fields (sorry if the terminology I'm using is wrong):
And also this is the bit which says what goes in teh email:
and finally this is the bit that puts the question into my webpage:
Many thanks in advance to anyone who can help me at all.
Claire
I have added the two questions ok, and they show up ok on my webpage. However, when the form is submitted, it is not including the results of the checkbox questions because I haven't changed the code from what it was (which was a simple text field). I know that I need to add some code that is something like "foreach" to go through each box and add the result to another field if it is checked, but I have no idea how to do it.
I'm not a developer, nor a web designer, just a bit of an amateur techie.
Can anyone help me? I asked a couple of designers and they wanted access to my site and my logins and so on, and I didn't really want to give anyone that much access.
This is my code for the bit that first explains the fields (sorry if the terminology I'm using is wrong):
Code: Select all
// initalize vars
$error = 0;
$error_print = '';
$message_sent = 0;
$mail_to = '';
$to_contact = '';
$name = '';
$title = '';
$company = '';
$website = '';
$email = '';
$turnover = '';
$employees = '';
$interested = '';
$past = '';
$experience = '';
$objectives = '';
$learn = '';
$hear = '';
// add another field here like above
$error_contact = '';
$error_name = '';
$error_email = '';
// add another field here like above
// process form now
if (isset($_POST['action']) && ($_POST['action'] == 'send')) {
// check all input variables
$cid = ctf_clean_input($_POST['CID']);
if(empty($cid)) {
$error = 1;
$error_contact = 'Selecting a contact is required.';
}
else if (!isset($contacts[$cid]['CONTACT'])) {
$error = 1;
$error_contact = 'Requested Contact not found.';
}
$mail_to = ctf_clean_input($contacts[$cid]['EMAIL']);
$to_contact = ctf_clean_input($contacts[$cid]['CONTACT']);
$name = ctf_name_case(ctf_clean_input($_POST['name']));
$title = ctf_clean_input($_POST['title']);
$company = ctf_clean_input($_POST['company']);
$website = ctf_clean_input($_POST['website']);
$email = strtolower(ctf_clean_input($_POST['email']));
$turnover = ctf_clean_input($_POST['turnover']);
$employees = ctf_clean_input($_POST['employees']);
$interested = ctf_clean_input($_POST['interested']);
$past = ctf_clean_input($_POST['past']);
$experience = ctf_clean_input($_POST['experience']);
$objectives = ctf_clean_input($_POST['objectives']);
$learn = ctf_clean_input($_POST['learn']);
$hear = ctf_clean_input($_POST['hear']);
Code: Select all
if (!defined('PHP_EOL')) define ('PHP_EOL', strtoupper(substr(PHP_OS,0,3) == 'WIN') ? "\r\n" : "\n");
$subj = "$sitename $subject";
$msg = "Sent from $sitename
To: $to_contact
From:
Name: $name
Title: $title
Company: $company
Website: $website
Email: $email
Turnover: $turnover
Employes: $employees
What marketing activities are they interested in? $interested
What marketing activities have they done in the past? $past
What is their general experience of marketing? $experience
What are their objectives for the workshop? $objectives
What do they want to learn? $learn
Where did they hear about MIOD? $hear
";
Code: Select all
<div class="title">
<label for="interested">Which marketing activities are you specifically interested in: </label>
</div> '.echo_if_error($error_interested).'
<div class="field">
<input type="checkbox" value="Market research" name="interested[]" /> Market research<br />
<input type="checkbox" value="Branding" name="interested[]" /> Branding<br />
<input type="checkbox" value="PR" name="interested[]" /> PR (public relations) <br />
<input type="checkbox" value="Databases and CRM" name="interested[]" /> Databases and CRM (customer relationship management) <br />
<input type="checkbox" value="Advertising" name="interested[]" /> Advertising <br />
<input type="checkbox" value="Direct marketing" name="interested[]" /> Direct marketing <br />
<input type="checkbox" value="Newsletters" name="interested[]" /> Newsletters <br />
<input type="checkbox" value="Exhibitions" name="interested[]" /> Exhibitions <br />
<input type="checkbox" value="Events" name="interested[]" /> Events <br />
<input type="checkbox" value="Literature" name="interested[]" /> Literature <br />
<input type="checkbox" value="Websites" name="interested[]" /> Websites <br />
<input type="checkbox" value="Sponsorship" name="interested[]" /> Sponsorship <br />
<input type="checkbox" value="Loyalty" name="interested[]" /> Loyalty programmes <br />
<input type="checkbox" value="Referral" name="interested[]" /> Referral schemes <br />
<input type="checkbox" value="Internal" name="interested[]" /> Internal marketing<br />
<input type="checkbox" value="Promotions" name="interested[]" /> Promotions <br />
<input type="checkbox" value="All" name="interested[]" /> All<br />
<input type="checkbox" value="None" name="interested[]" /> None<br />
</div>
<br />
<div class="title">
<label for="past">Which marketing activities have you undertaken in the past: </label>
</div> '.echo_if_error($error_past).'
<div class="field">
<input type="checkbox" value="Market research" name="past[]" /> Market research<br />
<input type="checkbox" value="Branding" name="past[]" /> Branding<br />
<input type="checkbox" value="PR" name="past[]" /> PR (public relations) <br />
<input type="checkbox" value="Databases and CRM" name="past[]" /> Databases and CRM (customer relationship management) <br />
<input type="checkbox" value="Advertising" name="past[]" /> Advertising <br />
<input type="checkbox" value="Direct marketing" name="past[]" /> Direct marketing <br />
<input type="checkbox" value="Newsletters" name="past[]" /> Newsletters <br />
<input type="checkbox" value="Exhibitions" name="past[]" /> Exhibitions <br />
<input type="checkbox" value="Events" name="past[]" /> Events <br />
<input type="checkbox" value="Literature" name="past[]" /> Literature <br />
<input type="checkbox" value="Websites" name="past[]" /> Websites <br />
<input type="checkbox" value="Sponsorship" name="past[]" /> Sponsorship <br />
<input type="checkbox" value="Loyalty" name="past[]" /> Loyalty programmes <br />
<input type="checkbox" value="Referral" name="past[]" /> Referral schemes <br />
<input type="checkbox" value="Internal" name="past[]" /> Internal marketing<br />
<input type="checkbox" value="Promotions" name="past[]" /> Promotions <br />
<input type="checkbox" value="All" name="past[]" /> All<br />
<input type="checkbox" value="None" name="past[]" /> None<br />
</div>
Claire