weixin_33743248 2017-08-10 22:20 采纳率: 0%
浏览 51

如何获得表格输入值?

我是PHP的初学者。

我的网站上有一个表单,这个表单获取特定网站的标题和描述值(带有PRG_Match)。我想添加url输入此表单,当添加url并按Submit按钮时,它会自动获取字段。

例如:

前端代码:

<input name="url">https://testdomain.com/posts/6412</input>

后端代码:

$link = 'input values here';

结果:

表单字段(标题和描述)刷新或使用Ajax。

  • 写回答

3条回答 默认 最新

  • weixin_33675507 2017-08-10 22:32
    关注

    If you use jQuery, you can use its serialize() method to get all the form inputs.

    $("#form").submit(function(e) {
        e.preventDefault();
        $.ajax({
            type: "post",
            url: $(this).attr("action"),
            data: $(this).serialize(),
            success: function(response) {
                $("#result").html(response);
            }
        });
    });
    

    Note, however, that serialize() won't include the submit button itself. That's only submitted automatically in normal form submissions. If the server expects something like $_POST['submit'] to be set, you have to add it explicitly, e.g.

    data: $(this).serialize() + '&submit=true',
    
    评论

报告相同问题?