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.
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@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
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 Holly http://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@gmail.com mailto:listmail.ayendesigns@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 <http://drupal.org/user/367108> linkedin.com/in/jeffrgreenberg <http://linkedin.com/in/jeffrgreenberg> accidentalcoder.com <http://accidentalcoder.com> / ayendesigns.com <http://ayendesigns.com> @accidentalcoder--
drupal.org/user/367108 http://drupal.org/user/367108 linkedin.com/in/jeffrgreenberg http://linkedin.com/in/jeffrgreenberg accidentalcoder.com http://accidentalcoder.com / ayendesigns.com http://ayendesigns.com @accidentalcoder
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@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@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/ ]
Actually you should be able to alter the form in the validation function yes? Just change the function signature to pass $form by reference and make the changes to the form that you need rather than going through the later hook?
Dave
From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Jeff Greenberg Sent: Wednesday, February 11, 2015 8:45 AM To: support@drupal.org Subject: Re: [support] Changing checkboxes options during hook_node_validate
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@earthlink.netmailto:hovercrafter@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 Holly
http://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@gmail.commailto:listmail.ayendesigns@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/367108http://drupal.org/user/367108 linkedin.com/in/jeffrgreenberghttp://linkedin.com/in/jeffrgreenberg accidentalcoder.comhttp://accidentalcoder.com / ayendesigns.comhttp://ayendesigns.com @accidentalcoder
-- --- drupal.org/user/367108http://drupal.org/user/367108 linkedin.com/in/jeffrgreenberghttp://linkedin.com/in/jeffrgreenberg accidentalcoder.comhttp://accidentalcoder.com / ayendesigns.comhttp://ayendesigns.com @accidentalcoder
-- [ Drupal support list | http://lists.drupal.org/ ]
-- --- drupal.org/user/367108http://drupal.org/user/367108 linkedin.com/in/jeffrgreenberghttp://linkedin.com/in/jeffrgreenberg accidentalcoder.comhttp://accidentalcoder.com / ayendesigns.comhttp://ayendesigns.com @accidentalcoder
Tried this. So my function signature is: function si_core_node_validate($node, &$form, &$form_state) {
and the last thing I do is:
$form['refs'][LANGUAGE_NONE][0]['#options'] = $options; $form_state['rebuild'] = TRUE; form_set_error('refs', 'Select the potential entity links to be processed.');
yet the form displays the original field option.
On Wed, Feb 11, 2015 at 11:58 AM, Metzler, David metzlerd@evergreen.edu wrote:
Actually you should be able to alter the form in the validation function yes? Just change the function signature to pass $form by reference and make the changes to the form that you need rather than going through the later hook?
Dave
*From:* support-bounces@drupal.org [mailto:support-bounces@drupal.org] *On Behalf Of *Jeff Greenberg *Sent:* Wednesday, February 11, 2015 8:45 AM *To:* support@drupal.org *Subject:* Re: [support] Changing checkboxes options during hook_node_validate
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@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 Holly
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@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
-- [ Drupal support list | http://lists.drupal.org/ ]
Actually you never really know what is going to happen in validation. So many modules can do funky things. A lot of times the multi-step type forms handle the rebuild through a submit callback.
There's another option here as well, depending upon the criteria that has to be met, and that is using the #states system. You can see an example here:
http://cgit.drupalcode.org/examples/tree/form_example/form_example_states.in...
Jamie Holly http://hollyit.net
On 2/11/2015 11:58 AM, Metzler, David wrote:
Actually you should be able to alter the form in the validation function yes? Just change the function signature to pass $form by reference and make the changes to the form that you need rather than going through the later hook?
Dave
*From:*support-bounces@drupal.org [mailto:support-bounces@drupal.org] *On Behalf Of *Jeff Greenberg *Sent:* Wednesday, February 11, 2015 8:45 AM *To:* support@drupal.org *Subject:* Re: [support] Changing checkboxes options during hook_node_validate
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@earthlink.net mailto:hovercrafter@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 Holly http://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@gmail.com <mailto:listmail.ayendesigns@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 <http://drupal.org/user/367108> linkedin.com/in/jeffrgreenberg <http://linkedin.com/in/jeffrgreenberg> accidentalcoder.com <http://accidentalcoder.com> / ayendesigns.com <http://ayendesigns.com> @accidentalcoder -- --- drupal.org/user/367108 <http://drupal.org/user/367108> linkedin.com/in/jeffrgreenberg <http://linkedin.com/in/jeffrgreenberg> accidentalcoder.com <http://accidentalcoder.com> / ayendesigns.com <http://ayendesigns.com> @accidentalcoder-- [ Drupal support list | http://lists.drupal.org/ ]
--
drupal.org/user/367108 http://drupal.org/user/367108
linkedin.com/in/jeffrgreenberg http://linkedin.com/in/jeffrgreenberg
accidentalcoder.com http://accidentalcoder.com / ayendesigns.com http://ayendesigns.com
@accidentalcoder
Got it to work after all using the method of storing the new options in $form_state[storage] and then, if it isset during the subsequent hook, force-feeding the field with the values from the form state.
Thanks very much Dave and Jamie!!
On Wed, Feb 11, 2015 at 2:25 PM, Jamie Holly hovercrafter@earthlink.net wrote:
Actually you never really know what is going to happen in validation. So many modules can do funky things. A lot of times the multi-step type forms handle the rebuild through a submit callback.
There's another option here as well, depending upon the criteria that has to be met, and that is using the #states system. You can see an example here:
http://cgit.drupalcode.org/examples/tree/form_example/form_example_states.in...
Jamie Hollyhttp://hollyit.net
On 2/11/2015 11:58 AM, Metzler, David wrote:
Actually you should be able to alter the form in the validation function yes? Just change the function signature to pass $form by reference and make the changes to the form that you need rather than going through the later hook?
Dave
*From:* support-bounces@drupal.org [mailto:support-bounces@drupal.org support-bounces@drupal.org] *On Behalf Of *Jeff Greenberg *Sent:* Wednesday, February 11, 2015 8:45 AM *To:* support@drupal.org *Subject:* Re: [support] Changing checkboxes options during hook_node_validate
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@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 Holly
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@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
-- [ Drupal support list | http://lists.drupal.org/ ]
There could be something else overriding that in validation. Instead of using the default hook_node_validate, trying adding $form['#validate'][] = 'my_custom_validation_function' in hook_form or hook_form_alter. That way it's the last validation hook called.
Jamie Holly http://hollyit.net
On 2/11/2015 11:45 AM, Jeff Greenberg wrote:
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@earthlink.net mailto:hovercrafter@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 Holly http://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@gmail.com <mailto:listmail.ayendesigns@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 <http://drupal.org/user/367108> linkedin.com/in/jeffrgreenberg <http://linkedin.com/in/jeffrgreenberg> accidentalcoder.com <http://accidentalcoder.com> / ayendesigns.com <http://ayendesigns.com> @accidentalcoder -- --- drupal.org/user/367108 <http://drupal.org/user/367108> linkedin.com/in/jeffrgreenberg <http://linkedin.com/in/jeffrgreenberg> accidentalcoder.com <http://accidentalcoder.com> / ayendesigns.com <http://ayendesigns.com> @accidentalcoder-- [ Drupal support list | http://lists.drupal.org/ ]--
drupal.org/user/367108 http://drupal.org/user/367108 linkedin.com/in/jeffrgreenberg http://linkedin.com/in/jeffrgreenberg accidentalcoder.com http://accidentalcoder.com / ayendesigns.com http://ayendesigns.com @accidentalcoder
Ok, did that , and the #validate function is firing. I might get this wrong, because my confusion level is high, but here is what I think I observe in xdebug.
When I was setting a form error during validation, when it eventual made its way to drupal_process_form it wasn't doing a rebuild because of that. So I tried not setting a form error, since I'm setting $form_state[rebuild]=true anyway. Now drupal_process_form does a rebuild, but what happens is that just prior to the rebuild, the #options are what I just set them to with $form[my_field][LANGUAGE_NONE][0][#options] = my_options_array; in validation, but right after the rebuild, the original value is back. Do I need to set #options in more than one section of $form or somewhere in $form_state?
On Wed, Feb 11, 2015 at 12:01 PM, Jamie Holly hovercrafter@earthlink.net wrote:
There could be something else overriding that in validation. Instead of using the default hook_node_validate, trying adding $form['#validate'][] = 'my_custom_validation_function' in hook_form or hook_form_alter. That way it's the last validation hook called.
Jamie Hollyhttp://hollyit.net
On 2/11/2015 11:45 AM, Jeff Greenberg wrote:
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@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@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
-- [ Drupal support list | http://lists.drupal.org/ ]
Also make sure your hook_form_alter has & signs in front of the $form parameter (as well as $form_state) to indicate pass by reference. It’s easy to overlook that if your field isn’t changing when you think you should. If you forget to do this hook_form_alter won’t actually alter anything, but it won’t give you any errors either.
mymodule_hook_form_FORMID_alter(&$form, &$form_state);
From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Jeff Greenberg Sent: Wednesday, February 11, 2015 7:43 AM To: support@drupal.org Subject: Re: [support] Changing checkboxes options during hook_node_validate
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@gmail.commailto:listmail.ayendesigns@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/367108http://drupal.org/user/367108 linkedin.com/in/jeffrgreenberghttp://linkedin.com/in/jeffrgreenberg accidentalcoder.comhttp://accidentalcoder.com / ayendesigns.comhttp://ayendesigns.com @accidentalcoder
-- --- drupal.org/user/367108http://drupal.org/user/367108 linkedin.com/in/jeffrgreenberghttp://linkedin.com/in/jeffrgreenberg accidentalcoder.comhttp://accidentalcoder.com / ayendesigns.comhttp://ayendesigns.com @accidentalcoder