I've something like:
$form['add']=array( '#tree' => TRUE, ); $form['qty']=array( '#tree' => TRUE, ); // ... while(...) { $form['qty'][$id]]=array( '#type'=>'textfield', '#default_value'=> 0, '#size'=>3, '#maxlength'=>3, ); $form['add'][$id]=array( '#type'=>'button', // '#type'=>'submit', // '#name'=>$id, '#value'=>t('Add'), ); }
In a table
+ a general submit button
If the general submit button is pressed all the qty have to be collected... and saved in the DB. If one of the add button is pressed I should record just the qty of the corresponding button.
But since all buttons should have the same #value, I can't see how I could understand which one was pressed in the _submit function.
I can't use JavaScript.
thanks
On Wed, 25 Mar 2009 16:32:10 +0100 Ivan Sergio Borgonovo mail@webthatworks.it wrote:
I had to resort to some Web 1.5 techniques
$form['add'][$id]=array( // '#type'=>'button', '#type'=>'submit', '#name'=>$id.'-add', '#value'=>t('Add'), ); }
roll over qty
foreach($form_values['qty']... if($form_values[$key.'-add']==t('Add');
Did things get better in D5+?
D6 has the clicked_button value set:
Instead of just returning the value of the clicked button in $form_state['op'], you get the entire form element returned.
Jamie Holly http://www.intoxination.net http://www.hollyit.net
Ivan Sergio Borgonovo wrote:
On Wed, 25 Mar 2009 16:32:10 +0100 Ivan Sergio Borgonovo mail@webthatworks.it wrote:
I had to resort to some Web 1.5 techniques
$form['add'][$id]=array( // '#type'=>'button', '#type'=>'submit', '#name'=>$id.'-add', '#value'=>t('Add'), ); }
roll over qty
foreach($form_values['qty']... if($form_values[$key.'-add']==t('Add');
Did things get better in D5+?
A little known fact... You can create containers in the forms array that have no visual representation in the form, kind of like fieldsets, but without the fieldset.
While (...) { $form[$id] = array('#tree' => TRUE); $form[$id]['qty'] = array(....); $form[$id]['add'] = array(....); }
Might clean up some of the code you've discovered.
I usually nest all the rows into a single fieldset as well, but that's optional.
Dave
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Ivan Sergio Borgonovo Sent: Wednesday, March 25, 2009 8:56 AM To: support@drupal.org Subject: Re: [support] multiple buttons with same #value D5
On Wed, 25 Mar 2009 16:32:10 +0100 Ivan Sergio Borgonovo mail@webthatworks.it wrote:
I had to resort to some Web 1.5 techniques
$form['add'][$id]=array( // '#type'=>'button', '#type'=>'submit', '#name'=>$id.'-add', '#value'=>t('Add'), ); }
roll over qty
foreach($form_values['qty']... if($form_values[$key.'-add']==t('Add');
Did things get better in D5+?
-- Ivan Sergio Borgonovo http://www.webthatworks.it
-- [ Drupal support list | http://lists.drupal.org/ ]
On Wed, 25 Mar 2009 12:29:09 -0700 "Metzler, David" metzlerd@evergreen.edu wrote:
A little known fact... You can create containers in the forms array that have no visual representation in the form, kind of like fieldsets, but without the fieldset.
While (...) { $form[$id] = array('#tree' => TRUE); $form[$id]['qty'] = array(....); $form[$id]['add'] = array(....); }
Might clean up some of the code you've discovered.
I usually nest all the rows into a single fieldset as well, but that's optional.
No they were actual editable values. Each row had a textfield (qty) and a button + a "superbutton" at the end of the table.
Anyway problem was solved directly controlling the name attribute.
Yeah I understood that, but what I was pointing out is that you can get all your id's field data grouped by $id in your forms array if you reversed the nesting and put them in a container. You'd still need to use the name trick to get the buttons detected right ( I Think) .
Sorry if I wasn't clear. Here's a fictional example from a shopping cart metafor.
The form -- // Build the rows of items. While (....) { $row['qty] = array('#type' => 'textfield' ...); $row['size'] = array('#type' => 'radios'); $items[$id] = $row; } $form['items'] = $items; $form['items']['#tree'] = TRUE;
The values // Iterate the cart foreach ($form_values['items'] as $id=>$item) { // inside this loop $item['qty'] is the quantity // and $item['size'] is the size }
I just thought you (and others) might find this useful.
Dave
-----Original Message----- From: support-bounces@drupal.org [mailto:support-bounces@drupal.org] On Behalf Of Ivan Sergio Borgonovo Sent: Wednesday, March 25, 2009 12:35 PM To: support@drupal.org Subject: Re: [support] multiple buttons with same #value D5
On Wed, 25 Mar 2009 12:29:09 -0700 "Metzler, David" metzlerd@evergreen.edu wrote:
A little known fact... You can create containers in the forms array that have no visual representation in the form, kind of like fieldsets, but without the fieldset.
While (...) { $form[$id] = array('#tree' => TRUE); $form[$id]['qty'] = array(....); $form[$id]['add'] = array(....); }
Might clean up some of the code you've discovered.
I usually nest all the rows into a single fieldset as well, but that's optional.
No they were actual editable values. Each row had a textfield (qty) and a button + a "superbutton" at the end of the table.
Anyway problem was solved directly controlling the name attribute.
-- Ivan Sergio Borgonovo http://www.webthatworks.it
-- [ Drupal support list | http://lists.drupal.org/ ]
Quoting Ivan Sergio Borgonovo mail@webthatworks.it:
But since all buttons should have the same #value, I can't see how I could understand which one was pressed in the _submit function.
Do you have access to #name? In your example it is set to the value of the id.
-- Earnie http://r-feed.com Make a Drupal difference and review core patches.
-- http://for-my-kids.com/ -- http://www.4offer.biz/
---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.