Manually submit form in presenter #2

Notice: This thread is very old.
_Martin_
Generous Backer | 680
+
0
-

Hi,

I need form, that user can fill and send. And at the same time, I need form, which application can prefill automatically (using setDefaults method) and send programmatically. Why? Because validation – if there will be error in prefilled data, validation fails and user will have to fix data in form manually.

I can't find any suitable solution. It's almost same question as this https://forum.nette.org/…in-presenter, but it hasn't solved.

Any ideas?

Kori
Member | 58
+
+1
-

Hi, you don't need to submit the form to check if is valid. Set (default) values and then simply validate the form.

$form = $this->getComponent('myForm');

$form->setDefaults($data);

if ($form->isValid()) {

	... show message, redirect, etc.

} else {

... show the form so user can fix incorrect values, etc.
}
old.gandalf
Member | 17
+
0
-

Hello,

I don't understand why you should set incorrect default values. If they are loaded e.g. from the database, they should have either be validated before saved in there or corrected when filling the form with them using setDefaults(). If that is not what you want to do, sorry, I might have misunderstood your question.

I also don't understand what is the problem when calling setDefaults(). Do you want to have the form twice in the same time on your page?

Honza Kuchař
Backer | 1656
+
0
-

This is bad design.

You have to send form using JavaScript.

Or you can validate your data on server-side using Validators from forms. https://github.com/…alidator.php#L86