Hey,
i’m currently working on forms with fields wich can be duplicated (cloned) and i want to write this data to a database.
This is how i currently have my code.
echo $form->textField( $account , '[0]email' , array(
'class'  => 'form-control' ,
) );
but if i clone this field, the cloned field will also have a name with modelName[0][‘email’]
So i want to recieve my cloned element data on another array index, does anyone have a smart solution for this?
I have red the page about tabular onpit on: http://www.yiiframework.com/doc/guide/1.1/en/form.table , but it diddnt really solve my problem.
Thanks in advance.
         
        
          
        
           
           
           
         
         
            
            
          
       
      
        
        
          Hi,
Please can you tell me how you are cloning your textfield
         
        
        
           
           
           
         
         
            
            
          
       
      
        
        
          You can use [] instead of [0], so an array will be passed.
         
        
        
           
           
           
         
         
            
            
          
       
      
        
        
          
	$( '.dynamic-rows' ).on( 'click' , '.dynamic-add' , function() {
		var dynamicRows = $( this ).closest( '.dynamic-rows' );
		var formGroup = $( this ).closest( '.form-group' );
		var clone = formGroup.clone( false );
		clone.find( ':input' ).val( null );
		formGroup.after( clone );
		clone.find( ':input' ).first().focus();
	} );
I just put all the content wich can be duplicated in a dynamic-rows div, and inside that div i have a button with the class dynamic add.
         
        
        
           
           
           
         
         
            
            
          
       
      
        
        
          
I have tried that, but when i use only [] all data will be set on a differnt index, and i need data to be groupped to assign it to a model, and then write it to the database right?
         
        
        
           
           
           
         
         
            
            
          
       
      
        
        
          I’m not sure what’re you trying to do, maybe this would help:
$form->textField( $account , 'email[]');
Notice the reversed order of field name and brackets.
Also make sure you have setter for your array field, or process it in beforeSave().