Re: Changing checkboxes options during hook_node_validate
Jamie Holly <[email protected]> Wed, 11 Feb 2015 10:57:43 -0500
| Newsgroups | gmane.comp.php.drupal.support |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format. --===============6538807153914577933== Content-Type: multipart/alternative; boundary="------------070908030509020001050909" This is a multi-part message in MIME format. --------------070908030509020001050909 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit 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 > <[email protected] > <mailto:[email protected]>> 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 > > --------------070908030509020001050909 Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: 7bit <html> <head> <meta content="text/html; charset=windows-1252" http-equiv="Content-Type"> </head> <body bgcolor="#FFFFFF" text="#000000"> <div class="moz-cite-prefix">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. <br> <br> 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. <br> <pre class="moz-signature" cols="72">Jamie Holly <a class="moz-txt-link-freetext" href="http://hollyit.net">http://hollyit.net</a></pre> On 2/11/2015 10:43 AM, Jeff Greenberg wrote:<br> </div> <blockquote cite="mid:CAPpCgRbWrvQq=myoAHMUAM1MaJFCtUGG=0Y5rOMSyH9eVDBTQQ@mail.gmail.com" type="cite"> <div dir="ltr">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.</div> <div class="gmail_extra"><br> <div class="gmail_quote">On Wed, Feb 11, 2015 at 9:31 AM, Jeff Greenberg <span dir="ltr"><<a moz-do-not-send="true" href="mailto:[email protected]" target="_blank">[email protected]</a>></span> wrote:<br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> <div dir="ltr"> <div style="margin:0px 5px 5px 0px;padding:0px;border:0px;font-size:14px;vertical-align:baseline;width:660px;word-wrap:break-word;line-height:1.3;color:rgb(68,68,68);font-family:'Lucida Grande','DejaVu Sans','Bitstream Vera Sans',Verdana,Arial,sans-serif"> <p style="margin:0px 0px 1em;padding:0px;border:0px;vertical-align:baseline;clear:both">I have a node form that contains a checkboxes field with options NULL at the time the form is displayed.</p> <p style="margin:0px 0px 1em;padding:0px;border:0px;vertical-align:baseline;clear:both">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.</p> <p style="margin:0px 0px 1em;padding:0px;border:0px;vertical-align:baseline;clear:both">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.</p> <p style="margin:0px 0px 1em;padding:0px;border:0px;vertical-align:baseline;clear:both">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.</p> <span class="HOEnZb"><font color="#888888"> <div><br> </div> </font></span></div> <span class="HOEnZb"><font color="#888888"> <div><br> </div> -- <br> <div>--- <div><a moz-do-not-send="true" href="http://drupal.org/user/367108" target="_blank">drupal.org/user/367108</a></div> <div><a moz-do-not-send="true" href="http://linkedin.com/in/jeffrgreenberg" target="_blank">linkedin.com/in/jeffrgreenberg</a></div> <div><a moz-do-not-send="true" href="http://accidentalcoder.com" target="_blank">accidentalcoder.com</a> / <a moz-do-not-send="true" href="http://ayendesigns.com" target="_blank">ayendesigns.com</a></div> <div>@accidentalcoder</div> </div> </font></span></div> </blockquote> </div> <br> <br clear="all"> <div><br> </div> -- <br> <div class="gmail_signature">--- <div><a moz-do-not-send="true" href="http://drupal.org/user/367108" target="_blank">drupal.org/user/367108</a></div> <div><a moz-do-not-send="true" href="http://linkedin.com/in/jeffrgreenberg" target="_blank">linkedin.com/in/jeffrgreenberg</a></div> <div><a moz-do-not-send="true" href="http://accidentalcoder.com" target="_blank">accidentalcoder.com</a> / <a moz-do-not-send="true" href="http://ayendesigns.com" target="_blank">ayendesigns.com</a></div> <div>@accidentalcoder</div> </div> </div> <br> <fieldset class="mimeAttachmentHeader"></fieldset> <br> </blockquote> <br> </body> </html> --------------070908030509020001050909-- --===============6538807153914577933== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline -- [ Drupal support list | http://lists.drupal.org/ ] --===============6538807153914577933==--