D6. I have an ajax popop form I have appear when creating a node. It contains a choice of terms from the node body to add to vocabularies. Since I don't know the nid yet, I serialize that form with js and store it in the node form in a hidden field. I can't add the data to the node_term table until the save is complete...but I don't know how to move the data along to that point. I can put a submit handler before the normal one, and that gives me access to the data via the form, but by the time I get to where hook_nodeapi op pre_save would fire, there is no form and that field info won't be present in the node. Yikes. Jeff -- /I am a non sequitur. Beware, the contents were packaged where peanuts are processed./ Ayen Designs 388 Bullsboro Drive #105 · Newnan, Georgia 30263 404-271-9734 Web:ayendesigns.com <http://ayendesigns.com/> Blog: theAccidentalCoder.com <http://theaccidentalcoder.com/> Drupal: j. ayen green <http://drupal.org/user/367108> (367108) IRQ: j_ayen_green IM (Yahoo) baalwww (MSN) baalwww@yahoo.com Skype: ayendesigns | Facebook: ayendesigns | Twitter: @ayendesigns Ayen Designs is the computer services division of
On 4/24/11 2:47 PM, jeff@ayendesigns.com wrote:
I can't add the data to the node_term table until the save is complete...but I don't know how to move the data along to that point. I can put a submit handler before the normal one, and that gives me access to the data via the form, but by the time I get to where hook_nodeapi op pre_save would fire, there is no form and that field info won't be present in the node.
I went through the same thought process once, and was pleasantly surprised to find the field info actually is present in the node. The node object is created directly from $form_state['values'], so the $node itself in hook_nodeapi() will contain the values you added to the form. For example, if you added a field named 'something' with hook_form_alter(), you'll see that in $form_state['values']['something'] in a form submit handler, and you'll see the same value in $node->something in hook_nodeapi(). -- Scott Reynen MakeDataMakeSense.com
That would be (will be?) great, but here's what I see. I have a field myfield that I send to the client as a hidden field with value 0. I change the value, via javascript, on the client. When I dsm $form in form_submit (I didn't try form_state yet), I see form->myfield->value as 0, but form->myfield->#post->myfield has the correct value. When I look at the node object, I see myfield, but it is value 0, the original value, but not the value that was present when the form was submitted. On 04/24/2011 05:22 PM, Scott Reynen wrote:
I went through the same thought process once, and was pleasantly surprised to find the field info actually is present in the node. The node object is created directly from $form_state['values'], so the $node itself in hook_nodeapi() will contain the values you added to the form. For example, if you added a field named 'something' with hook_form_alter(), you'll see that in $form_state['values']['something'] in a form submit handler, and you'll see the same value in $node->something in hook_nodeapi().
On 4/24/11 4:47 PM, jeff@ayendesigns.com wrote:
I have a field myfield that I send to the client as a hidden field with value 0. I change the value, via javascript, on the client.
When I dsm $form in form_submit (I didn't try form_state yet), I see form->myfield->value as 0, but form->myfield->#post->myfield has the correct value.
Are you perhaps setting your value on the hidden field with #value rather than #default_value? There's a note about that here: http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html... "Note that if you plan to use JavaScript to change your hidden element's value, you will need to use the #default_value property rather than #value." -- Scott Reynen MakeDataMakeSense.com
Scott, that was it! I have to admit I was a little dubious. I'm setting the value in jquery with $(myselector).val(newvalue), and thought, "There's no jquery .default_value" ... so that the note was referring, of course, to the form setting. What I don't understand is (a) why the value was in form-myfield-#post-myfield when I used #value (so -something- knew about it) and (b) how setting the value differently on its way to the client can make a difference when it's being reset on the client side with .val() The only thing I can think of is that when #value is used it's being marked as read-only in some way, and even though #post contains the new value, it's being reset to the original at some point. Thanks again, Jeff On 04/24/2011 07:28 PM, Scott Reynen wrote:
Are you perhaps setting your value on the hidden field with #value rather than #default_value? There's a note about that here:
http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html...
"Note that if you plan to use JavaScript to change your hidden element's value, you will need to use the #default_value property rather than #value."
participants (2)
-
jeff@ayendesigns.com -
Scott Reynen