[support] Changing checkboxes options during hook_node_validate

Jeff Greenberg listmail.ayendesigns at gmail.com
Wed Feb 11 16:45:22 UTC 2015


Ok, I've tried that. The last thing I do in hook_node_validate is
$form_state['rebuild'] = true; What I notice is that
hook_form_node_form_alter does not fire between then and the form being
redisplayed, so my pulling the options from $form_state['storage'] never
happens.

On Wed, Feb 11, 2015 at 10:57 AM, Jamie Holly <hovercrafter at earthlink.net>
wrote:

>  The checkboxes have to be added in the form creation stage, so in either
> hook_form or hook_form_alter. Then in the hook_validate, set a variable on
> $form_state['storage'] and set $form_state['rebuild'] = TRUE; and check in
> your hook_form or hook_form_alter for your $form_state['storage'] setting,
> and if set then add your checkboxes.
>
> I suggest looking at the form_example_wizard in the examples module, as
> that's basically what you are after, even though it's not a typical
> multi-step wizard you are after, the logic is still the same.
>
> Jamie Hollyhttp://hollyit.net
>
> On 2/11/2015 10:43 AM, Jeff Greenberg wrote:
>
> One thing that is either part of the issue, or a separate issue that
> impacts this, is that the checkboxes field is added via hook_form_alter. I
> notice that although the field appears in $form_state[values] it does not
> appear in $form_state[field], so I'm wondering where $form_state gets the
> information for the field when rebuilding the form.
>
> On Wed, Feb 11, 2015 at 9:31 AM, Jeff Greenberg <
> listmail.ayendesigns at gmail.com> wrote:
>
>>  I have a node form that contains a checkboxes field with options NULL
>> at the time the form is displayed.
>>
>> During node_validate, if certain criteria is met, an array of options
>> (checkboxes) is created, and the form needs to be redisplayed with the
>> checkboxes as part of it.
>>
>> I've tried setting #options = the new array in the $form, in
>> $form_state[original_form], etc all to no avail. The field doesn't change.
>>
>> I also set one checkbox in the field at the start, so that I could find
>> it in the $form and $form_state structures, changed where I found it to the
>> new options array, and again, no change. I am setting $form_state[rebuild]
>> to true, and even tried explicitly calling for the form to be rebuilt.
>>
>>
>>  --
>> ---
>> drupal.org/user/367108
>> linkedin.com/in/jeffrgreenberg
>> accidentalcoder.com / ayendesigns.com
>> @accidentalcoder
>>
>
>
>
>  --
> ---
> drupal.org/user/367108
> linkedin.com/in/jeffrgreenberg
> accidentalcoder.com / ayendesigns.com
> @accidentalcoder
>
>
>
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>



-- 
---
drupal.org/user/367108
linkedin.com/in/jeffrgreenberg
accidentalcoder.com / ayendesigns.com
@accidentalcoder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20150211/fe134be6/attachment.html 


More information about the support mailing list