0

I am having some trouble diplaying the values of my checkboxes in the email my form sends, I am using html form field that uses php and javascript Ajax to send the email. If I leave the code form Javascript out then all the values display as Yes and with the code it displays No. I'm new to php and would appreciate any help. Thanks.

HTML

<form method="post" action="test.php" name="contactform" id="contactform">
<input name="extension" type="checkbox" id="extension" value="extension">Extension<br>
<input name="wallmount" type="checkbox" id="wallmount" value="wallmount">Wall Mount<br>
<input name="deskmount" type="checkbox" id="deskmount" value="deskmount">Desk Mount
</form>

PHP

$extension=($_POST['extension'])?"Extension: Yes":"Extension: No";
$wallmount=($_POST['wallmount'])?"Wallmount: Yes":"Wallmount: No";
$wallmount=($_POST['wallmount'])?"Wallmount: Yes":"Wallmount: No";
$deskmount=($_POST['deskmount'])?"Deskmount: Yes":"Deskmount: No";

$msg.="$extension";;
$msg.="$wallmount";;
$msg.="$deskmount";;

Javascipt

jQuery(document).ready(function(){

$('#contactform').submit(function(){

    var action = $(this).attr('action');

    $('#contactform #submit').attr('disabled','disabled');

    $("#message").slideUp(750,function() {
    $('#message').hide();           

    $.post(action, { 

            extension: $('#extension').serialize(),
        wallmount: $('#wallmount').serialize(),
        deskmount: $('#deskmount').serialize(),

        subject: $('#subject').val(),
        verify: $('#verify').val()
    },
        function(data){
            document.getElementById('message').innerHTML = data;
            $('#message').slideDown('slow');
            $('#contactform #submit').attr('disabled',''); 
            if(data.match('success') != null) $('#contactform').slideUp('slow');

        }
    );

    });

    return false; 

});

});

4

2 回答 2

0

您包括每个复选框的值。你应该测试它是否被选中。

更一般地说,您应该让 jQuery 从您的表单中为您构建数据对象。

$.post(action, $('form').serialize());
于 2012-08-07T12:04:52.450 回答
0

尝试

$.post(action, { 
extension: $('#extension').attr('checked'),
wallmount: $('#wallmount').attr('checked'),
deskmount: $('#deskmount').attr('checked'),
},
于 2012-08-07T12:06:35.107 回答