Render form in variable, prevent direct echo

AndiLeni
Member | 8
+
0
-

Hello,

I am trying to integrate nette/forms into an application which is not based on the nette framework.

Unfortunately, I struggle with some points.

$form = new Form;

$form->setAction($action);
$form->setMethod('POST');

$form->addText('name', 'Name:');
$form->addPassword('password', 'Password:');
$form->addSubmit('send', 'Sign up');

return $form->render();

When I call ->render() on my form, the form gets echoed directly and hence breaks my page layout.
Is it possible to render the form as html into a variable which I can pass to my templating system?

I tried passing the $form directly, but this gives me a “Form cloning is not supported yet.” exception.

Pepino
Member | 103
+
0
-

Did you try use __toString() ? https://github.com/…rms/Form.php#L639

David Grudl
Nette Core | 7734
+
0
-
return (string) $form;
AndiLeni
Member | 8
+
0
-

Thanks, that was too simple to come to my mind 🤦‍♂️🙂