I would like to achieve this simple task:
<form id="myForm" action="foo.htm" method="post">
<ul>
<li onclick="myForm.submit();">Click me</li>
</ul>
</form>
My page is a little bit complicated, but nothing too hard: I've a modal loaded by hitting a button on the rendered page, and its draw dynamically based on the content of one variable, so in my scripts part ive this:
$.each(tasks, function(index, task) {
[...]
VARIABLE DECLARATION PART
[...]
body.append('<form class=taskForm id='+taskId+' action="'+
'{{URL::route('dettaglioTask')}}"' +
' method="Post">' +
'@csrf'+
'<li onClick="'+taskId+'.submit()">' +
'<div class="block">' +
'<div class="tags">' +
'<a class="tag">' +
'<span>'+da+'-'+mo+'-'+ye+'</span>' +
'</a>' +
'</div>' +
'<div class="block_content">' +
'<h2 class="title">' +
'<a>'+divStatus+'</a>' +
'</h2>' +
'<div class="byline">' +
'<span>'+tipo+'</span> ' +
'</div>' +
'<p class="excerpt">'+descrizione+'' +
'</p>' +
'</div>' +
'</div>' +
'</li>'+
'</form>'
);
This part is rendered correctly to me in a bootstrap modal. The interesting part:
<ul class="list-unstyled timeline">
<form class="taskForm" id="1135102" action="http://localhost:8000/dettaglioTask" method="Post">
<input type="hidden" name="_token" value="VJQYeeHRWs222Rms1UBWxdvc7tPcBGer7xMy6iUC">
<li onclick="1135102.submit()">
[....]
</li>
Even the next forms/li element are right to me, with unique id, and token, url and variables. So why I got this:
Uncaught SyntaxError: Invalid or unexpected token
When i try to hit the specific "li" element.
The second question is, do I need to embed "csfr", token in every form as described? because i found this on the manual, but is not too clear to me what is the right way of doing it:
CSRF Tokens & JavaScript When building JavaScript driven applications, it is convenient to have your JavaScript HTTP library automatically attach the CSRF token to every outgoing request. By default, the Axios HTTP library provided in the resources/js/bootstrap.js file automatically sends an X-XSRF-TOKEN header using the value of the encrypted XSRF-TOKEN cookie. If you are not using this library, you will need to manually configure this behavior for your application.
I'm using bootstrap.min.js, on Laravel 6.2. thanks!