douba1067 2014-11-22 23:47
浏览 49

通过Ajax将禁用的输入值传递给PHP表单提交

I've got two disabled input fields (city and state) that are calculated automatically when a third field is filled out (zip code) in a form, the relevant parts of which are:

<form method="post" name="myemailform" action="submit.php">
    <input type="text" name="home_address_city" id="home_address_city" disabled>
    <input type="text" name="home_address_state" id="home_address_state" disabled>
    <input type="submit" name="Submit" id="submit_button">
</form>

I'm then taking the form data and submitting it via ajax to a PHP script that emails it:

$(function(){
    $('form').on('submit', function(e){
        e.preventDefault();
        $.ajax({
            type: $(this).attr('method'),
            url: $(this).attr('action'),
            data: $(this).serialize()
        });
    });
});

The PHP then grabs everything as follows:

extract($_POST, EXTR_PREFIX_SAME, "extr");

And should be outputting it in the email body as follows:

$email_body = "City:\t$home_address_city
"."State:\t$home_address_state
";

These disabled fields were previously filled out manually and they were being sent in the email without problem. Since disabling them, they are not being sent in the email but everything else is otherwise working. The values do get sent if I remove disabled or replace it with readonly. (Using readonly instead was considered and rejected because it allows you to focus on the field and select the text, and the client doesn't want the user interacting with the fields at all.)

So how do I pass the values of the disabled input fields to the PHP script?

  • 写回答

1条回答 默认 最新

  • douliang2087 2014-11-23 00:55
    关注

    As suggested in the comments above, you can use JQuery to enable the disabled input elements before the $.ajax call. This post has the details.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分