Hi,
I've just started to use Drupal, and I found an incomprehensible difference compared to standard form handling: after the user submits a form and presses Back button in the web browser, Drupal CLEARS the previously filled information from the form (anyway the post method works fine, so PHP's $_POST variable transfers all filled data, the problem is only with the back button)! I'm talking about standard html method. I tried with "post" and "get" as well, but under Drupal none of them keeps the filled information on the form after pressing back button. But if I submit the same form _outside_ of Drupal, the web browser keeps filled information on the form after pressing Back, like normally Drupal should as well, but it doesn't.
I need it to propose a user the option to edit submitted data, and the easiest way was to send the web browser back to the form ( with history.back() javascript). This worked fine for me until I moved to Drupal. I know I could solve it by submitting the submitted data back to the form (in hidden elements), but I don't want to prepare all my forms to prefill values from a submit. Is there a way to keep this method under Drupal as well?
Thank you,
Dexx
Comments
form_set_error
You could use form_set_error and hook_validate to return a form if there are errors.
I think this is standard behaviour
I think this is desirable from a security point of view. If you need to be able to edit stuff then when you create your form just set the #default_value to be the starting values that you need to edit (in the same way as the standard node editing works), or as the last posted mentioned use the very powerful hook_validate stuff.
The forms API is designed to make this kind of thing easy, its a bit of a struggle to get used to - but once you have mastered it you'll never want to go back :)
Like books? Check out booktribes the new (Drupal based) community for book lovers
from Computerminds
Mike,
Computerminds offer Drupal development, consulting and training
forms api
Thanx for your replies. I haven't tried Forms API yet, and now probably I won't recreate my html based forms with Drupal's Forms, but I will examine this possibility for future developments. Anyway, do you have a link at hand to a good example showing the features of Forms API, too see what I could accomplish with it? Because I have some extra demans what it maybe couldn't satisfy (for example: HTML Quickform wasn't enough for me at some cases, in these cases I had to fall back to standard html forms).
And about the Back button: do you have any further idea about why this basic way (with html-based forms) doesn't work under Drupal? I would need to fix it this way, and at this moment I have no time to examine Drupal's source files to find the reason.
Thx,
Dexx
...
This isn't forms api stuff but if you are going to skip out on Drupal's tools you should read this on writing secure code: http://drupal.org/node/62304
The forms api stuff is in the handbook under API's.: http://drupal.org/node/37775
-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain
-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain
...
Thanks, that is useful about security, however I already knew them, but I didn't know all the stuffs available for Drupal. Actually,
I have only one question about Forms API right now: is it possible, to hide/show a DIV which contains a lot of form elements? It was the only thing I couldn't accomplish with HTML Qickforms, and that's why I hold off myself from another form tool. So, let's guess I have 4 checkboxes, and if I check one of them, a DIV containing further checkboxes/textboxes/etc should appear/disappear "under" the selected checkbox. I couldn't accomplish it with Quickform, beacuse I couldn't "insert" a DIV tag among the form elements, I had no control about that. Quickform simply rendered them continuosly, and hiding the form element one by one wouldn't be a solution.
Is it possible to encapsulate some form elements into a DIV with Drupal's Forms API to accomplish the above described goal?
(I'm not curious about the exact solution, I'm asking only that if it is possible someway)