Hi! I have a question about the forms api -- if this is not the best place to ask it, please let me know where I should. I want to be able to add an element to a form which is _not_ in the 'edit[]' space. Specifically, I need to be able to set the 'q' item so that it will not be lost across a GET form submission if the site is not using clean urls. Any suggestions of where to look for how to do this would be greatly appreciated. Thanks, Ricky
On Nov 30, 2006, at 4:51 PM, Richard Morse wrote:
Hi! I have a question about the forms api -- if this is not the best place to ask it, please let me know where I should.
Hi! Never mind; just after I sent this, I finally figured out what was going on in form_builder(). If I set the '#name' property in advance (I also set '#input' to false, but that may be unnecessary), then it doesn't create its own. Thanks, Ricky
(I also set '#input' to false, but that may be unnecessary),
It's not 'unnecessarry' but 'fundamentally broken'. If #input is FALSE then user submitted values will never got to your element and the #value of the element won't even be created if it does not exist and $form_values won't get the #value... this is not something you want. I have never heard of a valid use case of someone setting #input outside of hook_elements.
I have never heard of a valid use case of someone setting #input outside of hook_elements.
How about in a #process function? I'm working on form element to return node ids by selecting nodes out of a view. In my #process function I've was running into problems trying to work with the exposed filters - the values of the from the exposed filters would be returned along side the nids I selected. This would cause "illegal option selected" errors. I still working through the issue, and I've started by form altering _every_ form that uses my element, but I'm wondering if perhaps setting #input to false for the exposed filters section of the form wouldn't be the correct behavior. Then I could read from $_POST in my #process function. Does this sound reasonable to anyone? Or should I continue down the form_alter path? Opinions welcome. Code that demonstrates something even more welcome. Thanks, -Mark
On Nov 30, 2006, at 5:15 PM, Karoly Negyesi wrote:
(I also set '#input' to false, but that may be unnecessary),
It's not 'unnecessarry' but 'fundamentally broken'. If #input is FALSE then user submitted values will never got to your element and the #value of the element won't even be created if it does not exist and $form_values won't get the #value... this is not something you want.
The items are hidden values, though, not user input values. The issue is that I need to preserve 'q', 'sort', and 'order' values across form submission (the form is submitted via GET, because I need to preserve the form values across clicks in a tablesort_sql table). The value for 'q' is needed to allow this to work with or without clean urls, but it never needs to be set by the user. 'sort' and 'order' would only change from clicking on a link created by tablesort_sql, so again it isn't being changed by the user in the context of the form. To set the values, I actually grab them out of $_REQUEST, because I don't want the previous values that the form had, I want the values that are new from the user. If you'd like to see this in action, the module I'm working on is site_user_list. RIcky
most (almost all) form API automatism can be stepped over. if you set #name for yourself, it will be honored. that simple :)
participants (3)
-
Karoly Negyesi -
Mark Fredrickson -
Richard Morse