【问题标题】:Using 2 different submit buttons on an AJAX email form在 AJAX 电子邮件表单上使用 2 个不同的提交按钮
【发布时间】:2011-08-06 05:39:27
【问题描述】:

我对 AJAX 非常陌生,昨天按照教程在我的网页上获取电子邮件系统,而无需刷新页面。这是我目前拥有的代码:

    <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>

这运行良好,并且通过 process.php 发送电子邮件而无需刷新页面。我真正需要的是能够在“电子邮件”文本区域中输入电子邮件地址,并有 2 个不同的提交按钮。其中一个按钮会将信息 A 发送到输入的电子邮件,另一个按钮将发送信息 B。

这可能吗,还是我需要 2 个完全独立的表格和 2 个电子邮件输入框?

感谢您的帮助

【问题讨论】:

  • 信息A和B有什么区别,这个“信息”到底是什么?这些信息是由用户通过文本区域/输入框输入的吗?将 发送到 process.php 的内容添加到 HTML 中可能是值得的
  • 嗨,加里,两封电子邮件都预设在 process.php 文件中,一个发送用户注册详细信息,另一个发送他们的图片。我对 Silver Light 的回答很满意,因为它工作正常,但是你知道我在对 silver 的帖子的评论中提出的问题的答案吗?谢谢

标签: php mysql ajax email


【解决方案1】:

我不会使用单独的提交按钮 - 如果您关心表单的可用性,那就错了。我会使用下拉菜单或单选按钮和单个提交按钮。在您的情况下,这可以在不过多更改代码的情况下获得所需的结果:

<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>

然后,在您的process.php 中使用$_POST['info_type'] 来确定要做什么。

【讨论】:

  • 感谢银灯,我会试一试 :) 我不确定他们是否会对此感到满意,因为他们特别说 2 个按钮,但我会解释为什么这样更好
  • @user683526,祝你好运!我也总是很难向管理层解释可用性问题。
  • 哈哈,我想大多数设计师/开发人员都一样!另一件事,你知道如何让用户点击输入框的“值”文本自动消失吗?例如。我希望该框默认为“在此处输入备用电子邮件”,但不希望用户必须自己删除框中的文本。谢谢:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-02-10
  • 2014-08-27
  • 1970-01-01
  • 2015-02-06
  • 2012-02-10
  • 2017-11-02
  • 1970-01-01
相关资源
最近更新 更多