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

3 years ago

mikeb
Member | 30
+
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)

3 years ago

David Grudl
Nette Core | 6864
+
0
-

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

3 years ago

mikeb
Member | 30
+
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

3 years ago

David Grudl
Nette Core | 6864
+
0
-

Which Nette version do you use?

3 years ago

mikeb
Member | 30
+
0
-

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

3 years ago

CZechBoY
Member | 3380
+
0
-

Send composer.lock.

3 years ago

David Grudl
Nette Core | 6864
+
0
-

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