Fwd: Re: [development] #just_before_validation ?
Sent this from the wrong address originally... ---------- Forwarded Message ---------- Subject: Re: [development] #just_before_validation ? Date: Saturday 20 May 2006 14:30 To: development@drupal.org If you are defining the node type: in hook_form(), no need to set $form['title']. In yournodetype_node_form_submit($form_id, $form_values), do something like: $form_values['title'] = 'whatever you want'; return node_form_submit($form_id, $form_values); If you're not defining the node type, you can probably remove the title in hook_form_alter, and do the same thing in the _submit(). -Dave On Saturday 20 May 2006 01:16, Bèr Kessels wrote:
Hi,
I am looking for the following: I want to generate the title of a node from content in that node.
Hence I need to hook into the node submission on several places.
First: hook_form_alter, to make the title field hidden Then just *before* validation to capture the node content and fill a title. So that all possible validation hooks can still run, but that the title has a value.
Any idea what kind of hook, or #callback I should be looking at?
#validate is not a good option, since I think it is important to run all the normal validations on that title field. But maybe the trick is to set that #validate, and inside that callback function fill the title value and then call all the validation hooks from there? I am personally not a fan of using validation to cahnge values. Validation is for.... validation.
Also important is, that this needs a POST, because I have to grab info from that POSTed node.
Bèr
-------------------------------------------------------
Thank you. On 5/20/06, Dave Cohen <drupal@dave-cohen.com> wrote:
Sent this from the wrong address originally...
---------- Forwarded Message ----------
Subject: Re: [development] #just_before_validation ? Date: Saturday 20 May 2006 14:30 To: development@drupal.org
If you are defining the node type:
in hook_form(), no need to set $form['title'].
In yournodetype_node_form_submit($form_id, $form_values), do something like:
$form_values['title'] = 'whatever you want'; return node_form_submit($form_id, $form_values);
If you're not defining the node type, you can probably remove the title in hook_form_alter, and do the same thing in the _submit().
-Dave
On Saturday 20 May 2006 01:16, Bèr Kessels wrote:
Hi,
I am looking for the following: I want to generate the title of a node from content in that node.
Hence I need to hook into the node submission on several places.
First: hook_form_alter, to make the title field hidden Then just *before* validation to capture the node content and fill a title. So that all possible validation hooks can still run, but that the title has a value.
Any idea what kind of hook, or #callback I should be looking at?
#validate is not a good option, since I think it is important to run all the normal validations on that title field. But maybe the trick is to set that #validate, and inside that callback function fill the title value and then call all the validation hooks from there? I am personally not a fan of using validation to cahnge values. Validation is for.... validation.
Also important is, that this needs a POST, because I have to grab info from that POSTed node.
Bèr
-------------------------------------------------------
Thanks, But It does not help me.
f you're not defining the node type, you can probably remove the title in hook_form_alter, and do the same thing in the _submit().
This is the case
On Saturday 20 May 2006 01:16, Bèr Kessels wrote:
First: hook_form_alter, to make the title field hidden
So: I already do this
Then just *before* validation to capture the node content and fill a title. So that all possible validation hooks can still run, but that the title has a value.
*removing* the title causes validation errors. So nodeapi(submi) is too late! Bèr
On 5/21/06, Bèr Kessels <ber@webschuur.com> wrote:
Then just *before* validation to capture the node content and fill a title. So that all possible validation hooks can still run, but that the title has a value.
*removing* the title causes validation errors. So nodeapi(submi) is too late!
In hook_form_alter() try $form['title']['#type'] = 'value'; $form['title']['#value'] = 'dummy value';
Op zondag 21 mei 2006 13:31, schreef Earl Dunovant:
In hook_form_alter() try
$form['title']['#type'] = 'value'; $form['title']['#value'] = 'dummy value';
I do a $form['title']['#type'] = 'value'; $form['title']['#value'] = 'THIS_MIGHT_VALIDATE'; But that is neither clean nor secure. what if the hypothetical title_must_contain_three_words.module hops in ? Nor will the autogenerated title pass by any validation anymore. This is the current route a node takes (very rough) new/existing node -> POST -> hook_validate -> Store -> hook_insert() I would love to see, use or have: new/existing node -> POST -> *DO STUFF* -> hook_validate -> Store -> hook_insert() As you can see, _insert and nodeapi('insert') is too late anyway. (I need to verify, it was like this all along 4.7 to head a few months ago. But even itf it hooks in earlier, I cannot use it) So let me take a step back, rephrase, and ask my question again: I am looking for the following: I want to generate the title of a node from content in that node. I currently manage to do this, by abusing validation, by adding dummy text in hook_form_alter. I am looking for a SOLID and clean way to achieve this. So: Is form api able to help me with this? In some undocumented hook that I missed? Or do we simply lack the hooks to do this, and should I continue on my hackish and dirty (but working) road? Bèr -- [ Bèr Kessels | Drupal services www.webschuur.com ] CVS onder de knie krijgen: http://help.sympal.nl/cvs_onder_de_knie_krijgen
On 5/21/06, Bèr Kessels <ber@webschuur.com> wrote:
So: Is form api able to help me with this? In some undocumented hook that I missed? Or do we simply lack the hooks to do this, and should I continue on my hackish and dirty (but working) road?
I think you'll be hacking. I am, until the next version of Drupal anyway.
It's amazon.module. Pre FormAPI, I would let users retrieve the title of a product by leaving the field blank and hitting preview. In hook_validate() I'd attach the results of a product query to the node object. Now I'm querying Amazon.com in hook_form_validate() and hook_form_submit(). Frankly, I just added the hook_form_submit() function last night. At the moment there some terrible hackery in the module and I'm only recently seeing my way clear to fixing it. I converted it for FAPI when I actually need to reorganize it. On 5/21/06, Bèr Kessels <ber@webschuur.com> wrote:
Op zondag 21 mei 2006 15:14, schreef Earl Dunovant:
I think you'll be hacking. I am, until the next version of Drupal anyway.
Just curious: what module do you use this for?
Bèr
participants (3)
-
Bèr Kessels -
Dave Cohen -
Earl Dunovant