验证不在电子邮件模板中工作

时间:2013-11-21 09:08:52

标签: javascript php jquery ajax html5

我使用JavaScript来验证使用id #mycontactform的表单,但它不起作用。 然后我使用了必需但它也没有工作。我花了更多的时间在这背后,但仍然没有成功。

这是我试过的JavaScript。

$(document).ready(function() {
  //$('#mycontactform').submit()
    $('#mycontactform').submit(function() {
        $.post('send.php', $('#mycontactform').serialize(),  function(response) {
            $('#success').html(response);
          //$('#success').hide('slow');
            setTimeout(function() {
                alert('Information Send Successfully');
            }, 1000);
            $('#submit').css('background','green');
        });
        return false;
    });
});

这是HTML:

<form id='mycontactform' action='send.php' method='post'>
    <select id='time' name='time' style='text-align:center;' required>
        <option value=''>&nbsp;&nbsp;-- select --&nbsp;</option>
        <option value='this week'>this week</option>
        <option value='next week'>next week</option>
        <option value='no rush'>no rush</option>
    </select>

    <select id='people' name='people' style='text-align:center;' required>
        <option value=''>&nbsp;&nbsp;-- select --&nbsp;</option>
        <option value='1'>1</option>
        <option value='2'>2</option>
        <option value='3'>3</option>
        <option value='4'>4</option>
        <option value='5'>5</option>
    </select>

    <label for='radio3'>Yes</label>
    <input type='radio' id='radio3' name='obstacles' value='yes' checked>

    <label for='radio4'>No</label>
    <input type='radio' id='radio4' name='obstacles' value='no'>
</form>

这是PHP:

<?php
$obstacles = $_POST['obstacles'];
$people = $_POST['people'];
$tim = $_POST['time'];
$to = 'mymail@gmail.com';
$from = $email;
$subject = 'Domestic & Commercial Gutter cleaning Replies From Email';
$body = "Obstacles : <strong>$obstacles</strong><br>
People Required : <strong>$people</strong><br>
Time required : <strong>$tim</strong><br>
";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: $from";
$ok = mail($to, $subject, $body, $headers);
if($ok)
echo '1';
else
echo '0';
?>

请建议我有用的解决方案。所有可能的方法,如使用Ajax,使JavaScript工作,或任何其他方式。

1 个答案:

答案 0 :(得分:0)

您的HTML代码没有提交按钮。

<input type="submit" id="submit" name="submit" value="Send Data">