how to override isSubmitted() when other posts/ajax set HttpData

Notice: This thread is very old.
mikeb
Member | 33
+
0
-

I'm using various nette forms on a various pages alongside other (non-nette) ajax calls. these pages ajax/post etc so then Nette thinks its own forms have been submitted: isSubmitted()=true. but it isn't true. And then nette overwrites setDefaultvalue() with blanks (as no such fields were posted).

I know I can use setValue instead of setDefaultvalue(), but this will requires a kludge in many forms and controllers using the forms.

as far as I can tell the problem originates in RequestFactory method createHttpRequest()

<?php
$method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD']
?>

i'd rather not overload this method. making $_SERVER['REQUEST_METHOD']=null will work before the form is initially generated but that's also a bit ugly, and this mustn't happen when nette does actually submit prior to validation.

Also, I guess nette therefore breaks when there are two or more nette forms on one page, as neither knows who was submitted (maybe each form needs to carry a unique id and createHttpRequest can check that?).

is there any other way to force Nette to regard the form as not submitted when it wasn't?

thanks
Mike

Last edited by mikeb (2017-02-03 09:44)

David Grudl
Nette Core | 8228
+
0
-

When your app sends AJAX POST request (which is not form submission), is there a parameter named do?

mikeb
Member | 33
+
0
-

no there isn't an ajax parameter named do.
currently my workaround is $_SERVER['REQUEST_METHOD']=null before creating the nette form.
btw I use nette forms standalone, not the whole nette framework

David Grudl
Nette Core | 8228
+
0
-

Which Nette version do you use?

mikeb
Member | 33
+
0
-

2.4.
here's part of the composer json:
“nette/component-model”: “~2.3”,
“nette/http”: “~2.2”,
“nette/utils”: “~2.4”
 },

CZechBoY
Member | 3608
+
0
-

Send composer.lock.

David Grudl
Nette Core | 8228
+
0
-

And are we talking about Nette\Forms\Form or Nette\Application\UI\Form?