I'm building a dynamic filter system, my user will be able to add as much criteria he wants Here a tiny example of my current aproach: $form['criteria'] = array( '#type' => 'fieldset', '#title' => t('Criterias'), '#collapsible' => TRUE, '#collapsed' => FALSE, '#tree' => TRUE, ); for ($i=1; $i<=variable_get('beginer_criteria', 3); $i++) { $form['criteria'][$i]['table[]'] = array( '#type' => 'select', '#options' => $tables, '#value' => $load[$i]['table'], '#description' => $load[$i]['table'], '#attributes' => array( 'class' => 'edit-table', ), ); } The form will start with X sets of fields (2 combo, 1 editfield) I set jQuery to clone any of those criteria, adding more Here the problem begin, any cloned, will have the same name of the original one. My $form_values does not return the cloned fields. my HTML is: <div class=qz-tablefield><div class="form-item"> <select name="criteria[1][table[]]" class="form-select edit-table" id="edit-criteria-1-table[]" ><option value="0">Select an option</option><option value="6">criticality</option><option value="2">group</option><option value="4">origin</option><option value="3">position</option><option value="5">priority</option><option value="1">reason</option><option value="7">status</option></select> </div> <div class="form-item"> <select name="criteria[1][field[]]" class="form-select edit-field" id="edit-field1" id="edit-criteria-1-field[]" ><option value="0">Select a table</option></select> </div> <div class="form-item"> <input type="text" maxlength="100" name="criteria[1][value[]]" id="edit-criteria-1-value[]" size="30" value="" class="form-text" /> </div>Note the criteria[1], the next set will be criteria[2]The cloned criteria will to be 1 ! the $form_values ignore the new fields.What can I change in my $form to solve that? Thanks a lot Feijó
This: http://jeff.viapositiva.net/drupal/dynamic-forms article written by Jeff Eaton is a good reference for dynamically adding form elements. The basic idea is that your hook_form() function needs to check the $_REQUEST array to determine how many values are coming back, and create the appropriate form elements for them. -Brad
Not quite that I have dynamic fields inserted through jQuery, not via loop in PHP. So, I need array My form its been builted with index ( criteria[1][value[]] ) (note digit 1), my jQuery will clone that, the new field will be equal. In theory, should work, because the value[] has no index, but strangly the array returned within $form_values does not have all my content :( Feijó ----- Original Message ----- From: "Brad Bowman" <brad@atendesigngroup.com> To: <development@drupal.org> Sent: Tuesday, January 15, 2008 1:56 PM Subject: Re: [development] $form #tree issue
This: http://jeff.viapositiva.net/drupal/dynamic-forms article written by Jeff Eaton is a good reference for dynamically adding form elements. The basic idea is that your hook_form() function needs to check the $_REQUEST array to determine how many values are coming back, and create the appropriate form elements for them.
-Brad
Maybe you can try to add another field indicating number of cloned fields? MI. -----Original Message----- From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Alessandro Feijó Sent: 15 January 2008 16:57 To: development@drupal.org; brad@atendesigngroup.com Subject: Re: [development] $form #tree issue Not quite that I have dynamic fields inserted through jQuery, not via loop in PHP. So, I need array My form its been builted with index ( criteria[1][value[]] ) (note digit 1), my jQuery will clone that, the new field will be equal. In theory, should work, because the value[] has no index, but strangly the array returned within $form_values does not have all my content :( Feijó ----- Original Message ----- From: "Brad Bowman" <brad@atendesigngroup.com> To: <development@drupal.org> Sent: Tuesday, January 15, 2008 1:56 PM Subject: Re: [development] $form #tree issue
This: http://jeff.viapositiva.net/drupal/dynamic-forms article written by Jeff Eaton is a good reference for dynamically adding form elements. The basic idea is that your hook_form() function needs to check the $_REQUEST array to determine how many values are coming back, and create the appropriate form elements for them.
-Brad
Wont work, a solution should be manipulate the cloned HTML and change the index to the next avaiable, but it would be a PITA :) Can I build a FORM without that index that Drupal set?? Feijó ----- Original Message ----- From: "Maciek Iwanowski" <maciek.iwanowski@glasspartnership.co.uk> To: <development@drupal.org> Sent: Tuesday, January 15, 2008 3:39 PM Subject: Re: [development] $form #tree issue Maybe you can try to add another field indicating number of cloned fields? MI. -----Original Message----- From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Alessandro Feijó Sent: 15 January 2008 16:57 To: development@drupal.org; brad@atendesigngroup.com Subject: Re: [development] $form #tree issue Not quite that I have dynamic fields inserted through jQuery, not via loop in PHP. So, I need array My form its been builted with index ( criteria[1][value[]] ) (note digit 1), my jQuery will clone that, the new field will be equal. In theory, should work, because the value[] has no index, but strangly the array returned within $form_values does not have all my content :( Feijó
But you can't manipulate HTML only. All HTML changes need to be mirrored in form generating function in PHP. MI. -----Original Message----- From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Alessandro Feijó Sent: 15 January 2008 17:49 To: development@drupal.org Subject: Re: [development] $form #tree issue Wont work, a solution should be manipulate the cloned HTML and change the index to the next avaiable, but it would be a PITA :) Can I build a FORM without that index that Drupal set?? Feijó ----- Original Message ----- From: "Maciek Iwanowski" <maciek.iwanowski@glasspartnership.co.uk> To: <development@drupal.org> Sent: Tuesday, January 15, 2008 3:39 PM Subject: Re: [development] $form #tree issue Maybe you can try to add another field indicating number of cloned fields? MI. -----Original Message----- From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Alessandro Feijó Sent: 15 January 2008 16:57 To: development@drupal.org; brad@atendesigngroup.com Subject: Re: [development] $form #tree issue Not quite that I have dynamic fields inserted through jQuery, not via loop in PHP. So, I need array My form its been builted with index ( criteria[1][value[]] ) (note digit 1), my jQuery will clone that, the new field will be equal. In theory, should work, because the value[] has no index, but strangly the array returned within $form_values does not have all my content :( Feijó
Are you sure?? :) I belive I just solve the mistery I do not need #tree at all!! Just removed it, and now all my cloned fields are returning they content properly!!!! Time to test, progress my code, and later this week I will document my solution and publish somewere... Feijó ----- Original Message ----- From: "Maciek Iwanowski" <maciek.iwanowski@glasspartnership.co.uk> To: <development@drupal.org> Sent: Tuesday, January 15, 2008 3:52 PM Subject: Re: [development] $form #tree issue But you can't manipulate HTML only. All HTML changes need to be mirrored in form generating function in PHP. MI. -----Original Message----- From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Alessandro Feijó Sent: 15 January 2008 17:49 To: development@drupal.org Subject: Re: [development] $form #tree issue Wont work, a solution should be manipulate the cloned HTML and change the index to the next avaiable, but it would be a PITA :) Can I build a FORM without that index that Drupal set?? Feijó ----- Original Message ----- From: "Maciek Iwanowski" <maciek.iwanowski@glasspartnership.co.uk> To: <development@drupal.org> Sent: Tuesday, January 15, 2008 3:39 PM Subject: Re: [development] $form #tree issue Maybe you can try to add another field indicating number of cloned fields? MI. -----Original Message----- From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Alessandro Feijó Sent: 15 January 2008 16:57 To: development@drupal.org; brad@atendesigngroup.com Subject: Re: [development] $form #tree issue Not quite that I have dynamic fields inserted through jQuery, not via loop in PHP. So, I need array My form its been builted with index ( criteria[1][value[]] ) (note digit 1), my jQuery will clone that, the new field will be equal. In theory, should work, because the value[] has no index, but strangly the array returned within $form_values does not have all my content :( Feijó
Are you sure?? :) I belive I just solve the mistery I do not need #tree at all!! Just removed it, and now all my cloned fields are returning they content properly!!!! Time to test, progress my code, and later this week I will document my solution and publish somewere... Feijó ----- Original Message ----- From: "Maciek Iwanowski" <maciek.iwanowski@glasspartnership.co.uk> To: <development@drupal.org> Sent: Tuesday, January 15, 2008 3:52 PM Subject: Re: [development] $form #tree issue But you can't manipulate HTML only. All HTML changes need to be mirrored in form generating function in PHP. MI. -----Original Message----- From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Alessandro Feijó Sent: 15 January 2008 17:49 To: development@drupal.org Subject: Re: [development] $form #tree issue Wont work, a solution should be manipulate the cloned HTML and change the index to the next avaiable, but it would be a PITA :) Can I build a FORM without that index that Drupal set?? Feijó ----- Original Message ----- From: "Maciek Iwanowski" <maciek.iwanowski@glasspartnership.co.uk> To: <development@drupal.org> Sent: Tuesday, January 15, 2008 3:39 PM Subject: Re: [development] $form #tree issue Maybe you can try to add another field indicating number of cloned fields? MI. -----Original Message----- From: development-bounces@drupal.org [mailto:development-bounces@drupal.org] On Behalf Of Alessandro Feijó Sent: 15 January 2008 16:57 To: development@drupal.org; brad@atendesigngroup.com Subject: Re: [development] $form #tree issue Not quite that I have dynamic fields inserted through jQuery, not via loop in PHP. So, I need array My form its been builted with index ( criteria[1][value[]] ) (note digit 1), my jQuery will clone that, the new field will be equal. In theory, should work, because the value[] has no index, but strangly the array returned within $form_values does not have all my content :( Feijó
participants (3)
-
Alessandro Feijó -
Brad Bowman -
Maciek Iwanowski