In Slim framework 4; How can I return a Formr-form in my controller as a response to a get-request?
$app->group('/timer', function (Group $group) {
$group->get('/', function (Request $request, Response $response) {
$form = new Formr\Formr();
// $form->create_form('Name')
// die();
$response->getBody()->write($form->create_form('Name'));
return $response;
});
});
The code outputs nothing. However, if I uncomment the two lines, it outputs (as expected):
<form action="/index.php" id="myFormr" method="post" accept-charset="utf-8">
<input type="hidden" name="FormrID" value="myFormr"><label for="name">Name</label>
<input type="text" name="name" id="name" />
<button type="submit" name="button" id="button">Submit</button>
</form>
From Formr documentations:
Formr will automatically echo form elements and messages to the screen, and this is usually fine. However, in some instances - such as when using a templating framework - this is not an option. In these cases simply pass the word hush and then manually echo your elements and messages.
$form = new Formr\Formr('bootstrap', 'hush');
The default value for the first parameter of Formr\Formr
constructor is an empty string, so in your case you should create new Formr instance with an empty string ''
as the first parameter ann 'hush'
as the second parameter:
$app->group('/timer', function (Group $group) {
$group->get('/', function (Request $request, Response $response) {
// required change
$form = new Formr\Formr('', 'hush');
$response->getBody()->write($form->create_form('Name'));
return $response;
});
});