Jump to content

Add form inputs dynamically in admin forms


tarek.fellah

Recommended Posts

I would like to add input forms in ajax forms, i'm searching for 2 days for a solution but i didn't find a solution.

I have an text field zip cod when the user typed 4 characters, an ajax call will be done and i would like the result (cities) to be as checkboxs and added in the form,

i tried this code 

$options = array();								
	for( $i = 1; $i <= $c  ; $i++){

	$f = "".$i."";
	 
	  $json = json_decode($htmlF)->$f->ville;
	
	 $ville = json_decode($htmlF)->$f->ville;
	  
	  $options[] = array(
			"id" => $ville,
			"name" => $ville
		);
	
	}
	//var_dump($this->fileds_temp); exit();
	//$this->fields_form =$this->fileds_temp;
	
	$this->fields_form['input'][]=	array(
										  'type'    => 'checkbox',                         // This is an <input type="checkbox"> tag.
										  'label'   => $this->l('Options'),                // The <label> for this <input> tag.
										  'desc'    => $this->l('Choose options.'),        // A help text, displayed right next to the <input> tag.
										  'name'    => 'options',                          // The content of the 'id' attribute of the <input> tag.
										  'values'  => array(
											'query' => $options,                           // $options contains the data itself.
											'id'    => 'id_option',                        // The value of the 'id' key must be the same as the key for 'value' attribute of the <option> tag in each $options sub-array.
											'name'  => 'name'                              // The value of the 'name' key must be the same as the key for the text content of the <option> tag in each $options sub-array.
										  ));
	return parent::renderForm();

I tested the $this->fields_form['input'] variable before adding it the checkbox and it retrun null, any one had an idea how to solve it or (if it's not a good solution) how to add input element in controller ajax function?

Thanks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...