如何在Symfony中自行提交表格


How to self submitting Form in Symfony?

我在模板中有一个符号形式:

Template.php

<form class="well" action="<?php echo url_for("@submitParam?param=".$con) ?>" method="post">
  <input type="text" name="param">
  <button type="submit" class="thisBtn">Button</button>
</form>

按下提交按钮时,如何使用jqueryjavascript或任何其他方式(symfony或者php)将值从HTML输入name="param"传递到url或变量$con

更新:你也可以使用AJAX:

$(".btn").live('click', function(){
        $.post("<?php echo url_for('@submitParam'); ?>", $('.box').serialize(), function(response) {
            switch(response.status) {
                case 'success':
                    console.log("Success");
                    break;
                case 'failure':
                    console.log("Failure");
                    break;
            }
        }, 'json');
        return false;
    });

操作:

$request->getParameter('param');

要在url中发送param值,请使用提交按钮

<input type="submit" class="thisBtn" value="button"/>

并改变获取的方法

method="get"

为什么要这样做?您已经有了param的值,因为它是表单中的一个输入元素。