i m trying to change a variable after i click on a submit button after verifying some conditions.
i used normal html forms instead of symfony forms idk if there is any difference.
controller:
#[Route('/test', name: 'test')]
public function test(Request $request): Response
{
$response = 'a';
if ($request->isMethod('POST')){
$response = "value changed";
}
return $this->render('charge/test.html.twig', [
'response' => $response
]);
}
template:
{% extends 'base.html.twig' %}
{% block title %}Hello !{% endblock %}
{% block body %}
<div class="container">
<h1>{{ response }}</h1>
<form method="post">
<input type="submit" name="sub1" value="sub1">
<input type="submit" name="sub2" value="sub2">
</form>
</div>
{% endblock %}
Value of response never changes after clicking on any of the submit buttons.
New contributor
idkman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1