I have developed a code to create dynamic textboxes on click of "Add" button using javascript -
Javascript
function GetDynamicTextBox(value,index) {
return
'<input type="text" name="jform[options][]" id="jform_options_'+index+'" value="">' +
'<input type="button" value="Remove" class="remove btn-danger" />'
}
formname.xml
<field name="options][" type="text" label="Options" multiple="true" description=""></field>
When I click on Add button , it will append n number of textboxes . But I am facing a problem in saving this field in database.
database
columnname = options, type= text
I want to save the values entered in textboxes in form of json. For this I am trying to override the controller save method-
controllername.php
public function save($key = null, $urlVar = null){
if($_POST['jform']){
$jinput = JFactory::getApplication()->input;
$postData = $jinput->post->get('jform', array(), 'array');
$postData['options']=json_encode(implode(',',$postData['options']));
// Save it back to the $_POST global variable
JRequest::setVar('jform', $postData, 'post');
}
// Finally, save the processed form data
return parent::save('id', $urlVar);
}
But all the rest values in the form are saving but not the "options field." - Note: you can see the image attached to understand what i am trying to achieve
- Any help would be appreicated