How to get to form errors if I implement the form through n:name=“componenName”?

mkoula
Backer | 57
+
0
-

I want to connect existing form through createComponentMyForm() with latte template – I found the easiest way to use as <form n:name=myForm ..>, but I wonder how to get in the template to the $form->hasErrors().

I tried to ad it $this->template->myForm = $form; before I return $form; in createComponentMyForm() method, but template says: undefined variable: myForm. It works only, the variable $myForm is present in latteonly if there's an error in the form unless I got the error message.

Any idea as I don't want to use the {control myForm} etc. Any idea?

Martk
Member | 661
+
+3
-
<form n:name="myForm">

is compiled to php

<?php
	$form = $_form = $this->global->formsStack[] = $this->global->uiControl["myForm"];
?>
<form
<?php
	echo Nette\Bridges\FormsLatte\Runtime::renderFormBegin(end($this->global->formsStack), array(), false)
?>
>

You can see, you have two variables ($form and $_form)

so

<form n:name="myForm">
	<ul class="errors" n:if="$form->hasErrors()">
		<li n:foreach="$form->getErrors() as $error">{$error}</li>
	</div>
</form>

another way

{var $form = $control[myForm]}

presenter way

public function renderDefault() {
	$this->template->myForm = $this['myForm'];
}

Last edited by Martk (2018-08-13 16:55)

mkoula
Backer | 57
+
+1
-

Thank you :-)

Now I see and understand it finally, in meaning as you can use the $form variable in between of the <form></form> tags and I had the error messages above and that's why I had the issue with it.