开发者

Using 2 different submit buttons on an AJAX email form

I am very new to AJAX and yesterday followed a tutorial to get an email system on my webpage without having to refresh the page. This is the code I have at the moment:

    <script type="text/javascript">
    $(document).ready(function(){
        $("#myform").validate({
            debug: false,
            rules: {
                name: "required",
                email: {
                    required: true,
                    email: true
                }
            },
            messages: {
                name: "Please let us know who you are.",
                email: "A valid email will help us get in touch with you.",
            },
            submitHandler: function(form) {
                // do other stuff for a valid form
                $.post('http://www.test.co.uk/erc/process.php?imei=<?php echo $imei; ?>&send_type=1', $("#myform").serialize(), function(data) {
                    $('#results').html(data);
                });
            }
        });
    });

</script>

<form name="myform" id="myform" action="" method="POST">  
<!-- The Email form field -->
    <label for="email" id="email_label">Email</label>  
    <input type="text" name="email" id="email" size="30" value=""/> 
    <br>
<!-- The Submit button -->
    <input type="submit" class="email-buttons" name="submit" value="Alternate Medical history"> 
</form>

This is working well and emails are sent via 开发者_如何学Cprocess.php without refreshing the page. What I really need though is to be able to enter the email address in the 'email' text area, and have 2 different submit buttons. One of these buttons will send information A to the entered email and the other will send information B.

Is this possible or do I need to have 2 completely seperate forms and 2 email entry boxes?

Thanks for any help


I wouldnt use separate submit buttons - it would be wrong, if you care about form usability. I would use a dropdown or radiobutton and a single submit button. In your case, this makes possible to get the desired result without changing the code too much:

<form name="myform" id="myform" action="" method="POST">  
<!-- The Email form field -->
    <label for="email" id="email_label">Email</label>  
    <input type="text" name="email" id="email" size="30" value=""/> 
    <br>
<!-- The Email form field -->
    <input type="radio" name="info_type" value="a"> send information A <br>
    <input type="radio" name="info_type" value="b"> send information B <br>
    <br>
<!-- The Submit button -->
    <input type="submit" class="email-buttons" name="submit" value="Alternate Medical history"> 
</form>

And then, use $_POST['info_type'] in your process.php to determine what to do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜