Hi,
I am trying to integrate my module with views. Currently I am trying to make a custom filter for my module. This filter consists of an autocomplete textfield. But in the case that the user just enters in some text and submits the form without waiting for the autocomplete, I want to be able to run some validation on it and then once it is validated, input the correct value back into the textfield.
So i figured that default values are based on $form_state['input'][$identifier]. However my validation is done on exposed_validation($form, $form_state). My validation function is also responsible for cleaning up the input and outputting the best correct input. Is there anyway to modify the default values for the value_form / exposed_form elements from either the validation or submit functions?
Thank you in advance
Comments
Comment #1
merlinofchaos commentedIn your validation function you can use form_set_value() to set the cleaned up value. See the API documentation for this on http://api.drupal.org.
Comment #2
n4964918 commentedawesome thanks merlin :-D
Comment #3
n4964918 commentedhi again,
sorry mate, but i tried that function which it works and updates my form_state['values']. However this still does not change the form_state['input'][$identifier]. Maybe this variable is based on the $_GET value?
Thanks for your help again.
Comment #4
merlinofchaos commentedYou may need to set both to be safe.
Comment #5
n4964918 commentedHi merlin,
I am able to change the initial value by changing my form_state['input'][$identifier] in my value_form function. However, I only know what value to change it to from my exposed_validate function as this is where I run most of my logic. If I change my form_state['input'][$identifier] in my validation function, it seems to be too late to alter the form element value.
One option for me is to run the validation in the value_form function, however I would ideally like to run it in the validation function, with which alters the initial value of the exposed form.
Not sure if this is possible.
Thanks
Comment #6
rschwab commentedAny progress on this?
"If I change my form_state['input'][$identifier] in my validation function, it seems to be too late to alter the form element value."
Can you move the logic to find your needed value to a separate function called from your form function before validation?
Comment #7
iamjon commentedI'm closing this issue from lack of activity.
please feel free to reopen with more information.
Comment #8
joetsuihk commentedsorry to reopen, I have a similar situation.
User case: adding a currency dropdown via form_alter to before a textfield, use form_alter to add a new validation call to calculate user selected currency into USD, and pass to a existing exposed form
But the above code still cannot change the submitted value in exposed form
Comment #9
merlinofchaos commentedWhat about setting $form_state['values']...?
Comment #10
joetsuihk commentedre #9 no
I discovered that in #validate, you can only change $form_state values (it is by reference), but not $form
and you can change values in $form in #submit instead.
I even tried to override every single instance of that value, but still no luck, below the ugly code:
i dig deep to the field handler part, but that confuse me, no idea where to go next.
Comment #11
joetsuihk commentedSorry guys, I just make a simple test case that, confirmed:
will be enough to change the exposed submit value if the field is NOT a cck field.
But my case, which still not resolved, because the field_min_usd_rate_value is a computed field. Similarly, a simple textfield from cck fails too. Does it mean I need to move this to CCK? where should I explore now?
Comment #12
merlinofchaos commentedNot sure what to say. With numeric values, check to see if there are multiple values; if the operator is exposed I think it has possibilities for a max/min which means there is a $form_state['values'][$identifier]['value'] or something like that as well?
Otherwise...maybe it's CCK but I suspect when it comes to exposed filters they're not going to know much there. :/
Comment #13
joetsuihk commentedThanks for the input. No, the field operator is not exposed.
Can you guide me where exactly the comparsion take place? I will test more on it next week.
Comment #14
merlinofchaos commentedIt's pretty tough to guide you; the exposed stuff in Views is pretty spread out across the filter handlers. I guess what you should do is dig into the CCK filter handler and follow the 'value' that it gets.
Comment #15
R.Hendel commentedHallo,
is your request still open?
It is for quite a long time undiscussed.So I will set it on fixed to clean the queue.
Please feel free to reopen it, if you have any further questions. Otherwise it would be closed automatically after two weeks.
Comment #16
joetsuihk commentedre #15
it is not fixed in my case. I used js work around that only work specific to my case. And I have provided all the info/test cases I have, so I agree just mark as fixed and leave this to the greater web.