I am developing an application using symfony2. I would like to know how I can receive arguments from a template in a controller because I want to store the value of the argument in the data base. The argument will get its value in a JavaScript script inside the template and must be passed to the controller when submitting a button. This is the script:
$("MatchedTag").click(function ()
{
$(this).toggleClass("highlight");
var IdOfTag = this.id;
});
The variable I want to receive in the controller is IdOfTag. How can I do this? Thanks.
You can pass the variable using AJAX (take a look at $.ajax, $.post, $.get – jQuery) or add a hidden input field to form with the desired value.
Example
If you want to pass
IdOfTagto/path/controller/tags(as example) using jQuery.ajax your code will looks like this:Then in the controller you can get the value of
idOfTagthrough$_POST["tag_id"]Good look and check the links above.