close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

contact form not sending checkbox

Thread began 5/02/2012 6:48 am by shanebrough438709 | Last modified 3/05/2015 2:49 pm by Jason Byrnes | 6649 views | 15 replies |

shanebrough438709

contact form not sending checkbox

Hi im having a problem with a website im building and testing.
in the contact form when i fill out the form and check some of the checkboxes, i recieve a email with the form info but the check boxes are empty.
can anyone help??

Also just discovered my selectable dropdown menu is only sending 1 of the selected items

Thanks in advance

html code:

<th>Membership * </th>
<td>
<input type="checkbox" name="membership[]" value="ecssa">ECSSA<br />
<input type="checkbox" name="membership[]" value="psa">PSA<br />
<input type="checkbox" name="membership[]" value="nsai">NSAI<br />
<input type="checkbox" name="membership[]" value="eqa">EQA<br />
<input type="checkbox" name="membership[]" value="Other">
Others (Fill Below) <br />
</td></tr>

contact php:

<?php
$field_name = $_POST['cf_name'];
$field_phone = $_POST['cf_phone'];
$field_mobile = $_POST['cf_mobile'];
$field_email = $_POST['cf_email'];
$field_company = $_POST['cf_company'];
$field_services = $_POST['services[]'];
$field_other = $_POST['cf_other'];
$field_areas = $_POST['cf_areas'];
$field_membership = $_POST['membership[]'];
$field_othermember = $_POST['cf_othermember'];
$field_job = $_POST['cf_job'];
$field_leads = $_POST['leads[]'];
$field_agree = $_POST['agree[]'];


$mail_to = 'Removed';
$subject = 'Message from a site visitor '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Phone Number: '.$field_phone;
$body_message .= 'Mobile: '.$field_mobile;
$body_message .= 'Company Name: '.$field_company;
$body_message .= 'Services offered: '.$field_services;
$body_message .= 'Other Services: '.$field_other;
$body_message .= 'Areas will Work: '.$field_areas;
$body_message .= 'Membera of: '.$field_membership;
$body_message .= 'Other Membership: '.$field_othermember;
$body_message .= 'Job Min Value: '.$field_job;
$body_message .= 'Recieve leads: '.$field_leads;
$body_message .= 'Agree to terms: '.$field_agree;

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message\n $check_msg";

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to removed');
window.location = 'index.html';
</script>
<?php
}
?>

Sign in to reply to this post

Jason ByrnesWebAssist

multile checkboxes and multiple select lists pass the values as an array. you need to convert the array to a string, add this code at line 1 to convert the array to a comma seperated list:

php:
<?php

if($_SERVER["REQUEST_METHOD"] == "POST")     {
    foreach(
$_POST as $key => $val) {
        if(
is_array($_POST[$key])) $_POST[$key] = implode(", "$_POST[$key]);
    }
}
?>




you will also need to change these lines:
$field_services = $_POST['services[]'];

$field_membership = $_POST['membership[]'];

$field_leads = $_POST['leads[]'];

$field_agree = $_POST['agree[]'];


to remove the [] from the element names:
$field_services = $_POST['services'];

$field_membership = $_POST['membership'];

$field_leads = $_POST['leads'];

$field_agree = $_POST['agree'];


the [] needs to be included with the name of the element in the form, but not when referring to it in the POST array.

if you need further assistance, compress a copy of the file into a zip archive and include that with your replay so i can see the entire page code in context.

Sign in to reply to this post

shanebrough438709

Hi Jason, Thanks for reply

Tried what you suggested but ended up getting other line errors example:

Parse error: parse error in \\nas01\nas\k\e\keepusafesecurity.net\web\site1\contact3.php on line 52

As you can prob tell am new to this!!
Any help appreciated zip file attached

Attached Files
contact_php.zip
Sign in to reply to this post

Jason ByrnesWebAssist

i'll need a copy of the contact3.php page.

please dont save it as a text file, just compress the original zip file into a zip archive. leave it as is, in the original form unchanged,

Sign in to reply to this post

shanebrough438709

Find attached cheers!!

Attached Files
contact3.zip
Sign in to reply to this post

Jason ByrnesWebAssist

at line 7, the php code block is closed, but you have more php code after it:

change line 7 and 8:

php:
?>

$field_name = $_POST['cf_name'];



to:

php:
?>

<?php
$field_name 
$_POST['cf_name'];



so that a new code block is created.

Sign in to reply to this post

shanebrough438709

Thanks Jason worked perfectly.

any ideas on the selective drop down menu??

only sends back the last highlighted option rather than all that is selected

cheers
shane

Sign in to reply to this post

Jason ByrnesWebAssist

send me all of your pages, the form page and the email script i n a zip archive.

what is the name of the select list?

Sign in to reply to this post

shanebrough438709

Hi Jason please find attached the zip file:
contains: contractors htm and contact3 php

The form in in the contractors page and the name of the list is 'cf_areas'

cheers
also if you could pm me would be great have something to ask you.

Attached Files
contact3.zip
Sign in to reply to this post

Jason ByrnesWebAssist

for a multiple select list to pass multiple values, the name needs to have [] added to the end.

change:
<select multiple="multiple" name="cf_areas">

to:
<select multiple="multiple" name="cf_areas[]">

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...