Session error when using nette/forms in other app
- mikeb
- Member | 33
Hello
I'm brand new to nette and at this stage just using the nette/forms (instaled
via composer) in a legacy app which does a session start before the page with
the nette form is called. i get the following error:
i had to silence tracy to see the error as tracy just said server error and it wasn't an error in my php logs. my guess is there's a clash in how sessions are handled. If i eliminate all traces of the other app my nette/forms code runs fine, which at this stage is just the bootstrap3-rendering.php examples recycled from here.
its on an xampp server with php 5.6.8. can anyone suggest a solution? is it around session management? is it a matter of starting nette http before anything else? if so, how?
thanks
Mike
Last edited by mikeb (2016-09-21 12:46)
- mikeb
- Member | 33
further… it appears the sessions exceptions are not encountered until the
form is echoed via the Forms\Form.php __toString() magic method which manages
the rendering.
So even when i start Nette before the other legacy app, I can't work around
Nette's requirement for starting a session…
maybe override the __toString() method? tho that sounds very hacky.
or is it that Nette forms just won't play well with other frameworks or apps
that also require session?
all comments appreciated
Mike
- mikeb
- Member | 33
OK one more comment. the form I am playing with adds CSRF protection:
if I comment out this line then the session error no longer appears.
I assume this feature changes the rendering process and bumps into the session
clash.
I don't understand Nette well enough to know if this is intentional (i guess
session holds the CSRF token?) but it does look like a show stopper.
???
- mikeb
- Member | 33
ok i think I have a work-around/result using the forms module alone with a legacy app that also sets session. that is, generate and add a token as a hidden required element and add a custom validator to that:
1. make a token (I'm happy with one token per sesssion as session is destroyed with login/logout)
2. then make a custom validator:
3. then add a hidden input to the form:
I'm sure there is a more elegant and nette-friendly solution but this appears
to work. and I can now use nette forms with my project and have some CSRF
protection!
(it would be nice it future versions of nette didn't have such insistent
requirements for session so they could play nicely with other apps, assuming
security isn't compromized)
HTH
Mike
Last edited by mikeb (2016-09-23 02:30)