Search code examples
joomlajoomla2.5joomla-extensions

dynamicly add form fields in joomla


I'm wondering if there is a possibility to add form fields to depending on some options,

for example:

when user select number of options = 8 and user click save, on next view user see 8 text box each with different names.

I was trying to use form fields class not via .xml files but can't get it to work.

Any1 know if it is even possible?


Solution

  • Yes that's is possible. You can get the number of fields from the form. Assume It's 10($count).

    Next view you can loop as below and create text boxes.

    for($i = 1; $i <= $count; $i++)
     echo '<input type="text" name="fields[]" class="class_fields">';
    

    At the backend you can fetch the data as below.

    $values = JRequest::getVar( 'fields', 'default_values', 'post', 'array' );
    

    Read more

    If you have any issues let me know