The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Post new topic Reply to topic  [ 17 posts ] 
Author Message
 Post subject: Dynamic form fields
PostPosted: Mon Jan 21, 2013 9:01 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Jul 22, 2011 1:51 pm
Posts: 23
We are creating a Joomla component and using xml to define most of the form fields on backend. But we have one form that needs dynamic fields.
The input field is dynamic, the category that shows on top, and the label for the field will all come from the database.
The values will be stored in a table in a key-value relationship. Please, check the attached mockup for better understanding.

How do we accomplish the creation of custom fields on a joomla form xml (fields definition)?


You do not have the required permissions to view the files attached to this post.


Last edited by sohopros on Tue Jan 22, 2013 12:35 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Dynamic form fields
PostPosted: Mon Jan 21, 2013 11:58 pm 
User avatar
Joomla! Master
Joomla! Master

Joined: Sun Feb 19, 2006 6:47 pm
Posts: 17903
Location: Toledo, OH
And your question is?

_________________
Don't HACK the Joomla! core. Extend and Override.
http://harpervance.com -
Live Joomla! Help available at the site M-F, 9-12 am edt 2-5pm edt.
by appointment on evenings and weekends.


Top
 Profile  
 
 Post subject: Re: Dynamic form fields
PostPosted: Tue Jan 22, 2013 12:34 am 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Jul 22, 2011 1:51 pm
Posts: 23
The question is: How do we accomplish the creation of custom fields on a joomla form xml (fields definition)?


Top
 Profile  
 
 Post subject: Re: Dynamic form fields
PostPosted: Wed Jan 23, 2013 7:06 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Apr 07, 2006 7:36 pm
Posts: 16
Hi

Make a folder somwhere in your component called 'fields'. Inside this folder copy one of a core JForm field from ../libraries/joomla/form/fields (i.e. for dropdowns you can take list.php). Rename it (File, Classname, $type) to your custom fieldname, and customise the 'getOptions'-method (you could place a sql-query there, to 'ask' your DB about options).

Then, in your form.xml write somthing like that
Code:
<fieldset addfieldpath="/administrator/components/com_mycomponent/path/to/fields/folder" >


If everthing is done, you should be able to use your file in that .xml like
Code:
<field name="yourfieldname"
    type="yourcostomfield" ....../>


Attributes and childelements depends on what you have implemented in your field-class.

If once you have done that, you be able to use that field in front- or backend, or in other components to.

Hope it helps
Cheers
Roger

_________________
...sorry, but I'm just here to learn english!


Top
 Profile  
 
 Post subject: Re: Dynamic form fields
PostPosted: Wed Jan 30, 2013 11:17 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Jul 22, 2011 1:51 pm
Posts: 23
Tribal6, thank you for your help but this is not really what we are trying to accomplish.
Please, check the attached mockup (from our first post) for better understanding.

We must have form like that

Dynamic Category A:
Dynamic Field A label: Dynamic Field A input
Dynamic Field B label: Dynamic Field B input

Dynamic Category B:
Dynamic Field A label: Dynamic Field A input
Dynamic Field B label: Dynamic Field B input

Not options of the fields but fields are coming from database.


We are still looking for an answer.
Thanks!


Top
 Profile  
 
 Post subject: Re: Dynamic form fields
PostPosted: Wed Jan 30, 2013 11:35 pm 
User avatar
Joomla! Master
Joomla! Master

Joined: Sun Feb 19, 2006 6:47 pm
Posts: 17903
Location: Toledo, OH
I'm still looking for a question that makes sense

_________________
Don't HACK the Joomla! core. Extend and Override.
http://harpervance.com -
Live Joomla! Help available at the site M-F, 9-12 am edt 2-5pm edt.
by appointment on evenings and weekends.


Top
 Profile  
 
 Post subject: Re: Dynamic form fields
PostPosted: Wed Jan 30, 2013 11:40 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Jul 22, 2011 1:51 pm
Posts: 23
ranwilli, thank you for your reply.
How do we accomplish this using Joomla 2.5 form xml through the <field />?

Please let us know if we clear enough in our explanation.

Thanks!


Top
 Profile  
 
 Post subject: Re: Dynamic form fields
PostPosted: Thu Jan 31, 2013 12:11 am 
User avatar
Joomla! Master
Joomla! Master

Joined: Sun Feb 19, 2006 6:47 pm
Posts: 17903
Location: Toledo, OH
Nowhere near clear enough.

_________________
Don't HACK the Joomla! core. Extend and Override.
http://harpervance.com -
Live Joomla! Help available at the site M-F, 9-12 am edt 2-5pm edt.
by appointment on evenings and weekends.


Top
 Profile  
 
 Post subject: Re: Dynamic form fields
PostPosted: Thu Jan 31, 2013 1:56 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Jul 22, 2011 1:51 pm
Posts: 23
We want fields on the form that come from the database, so that when a field item is added to the component (like adding a Zone D on the attached screenshot), that new field will show up on our add/edit form (mock-up for that form is attached to our original posting).

The Zones in this case are our referenced dynamic form fields.


You do not have the required permissions to view the files attached to this post.


Top
 Profile  
 
 Post subject: Re: Dynamic form fields
PostPosted: Thu Apr 18, 2013 1:56 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun May 23, 2010 11:25 pm
Posts: 34
Seems perfectly clear to me....

You want to have dynamic options (drawn from the database) in the drop down list but you can't put PHP code in the forms XML, so how do call the records from the database and reference them in the XML as :
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>

I'm trying to do the same thing. If you found an answer, please post it. Thanks


Top
 Profile  
 
 Post subject: Re: Dynamic form fields
PostPosted: Thu Apr 18, 2013 4:50 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Jul 22, 2011 1:51 pm
Posts: 23
Hi riprod!

In our case, we had to create a custom form field plugin to accomplish what we needed. But, I believe that to generate a dynamic dropdown loading the options from database you can use a SQL type field. Please, check the links bellow:

//Creating a custom form field type
http://docs.joomla.org/Creating_a_custo ... field_type

//SQL form field type
http://docs.joomla.org/SQL_form_field_type

//Standard form field types
http://docs.joomla.org/Form_field

Hope it helps!
SOHO Prospecting Team


Top
 Profile  
 
 Post subject: Re: Dynamic form fields
PostPosted: Thu Apr 18, 2013 8:36 pm 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Sat Dec 06, 2008 7:07 pm
Posts: 307
I understand what you say.
You would have to create a custom field that is able to support input for different fields (that must be retrived from database).
I guess you could do that. That is, a custom field that shows different input controls, depending on the configuration on database.
The hard would be putting the values in a single field (maybe a hidden field) so it can be stored correctly in database.

_________________
http://www.ratmilwebsolutions.com


Top
 Profile  
 
 Post subject: Re: Dynamic form fields
PostPosted: Thu Jul 04, 2013 9:13 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Tue Jun 11, 2013 6:44 am
Posts: 1
Look for the language field as a reference (/libraries/joomla/form/fields/language.php) which generate the dynamic list of languages as options of a pulldown menu based on the database. It is calling a helper function (/libraries/joomla/language/helper.php).

Oliver


Top
 Profile  
 
 Post subject: Re: Dynamic form fields
PostPosted: Tue Oct 08, 2013 11:25 pm 
User avatar
Joomla! Intern
Joomla! Intern

Joined: Fri May 07, 2010 4:43 am
Posts: 83
Location: SoCal
sohopros wrote:
Hi riprod!

In our case, we had to create a custom form field plugin to accomplish what we needed. But, I believe that to generate a dynamic dropdown loading the options from database you can use a SQL type field. Please, check the links bellow:

//Creating a custom form field type
http://docs.joomla.org/Creating_a_custo ... field_type

//SQL form field type
http://docs.joomla.org/SQL_form_field_type

//Standard form field types
http://docs.joomla.org/Form_field

Hope it helps!
SOHO Prospecting Team


sohopros,

would be great if you could share an example of how you executed this.
I am attempting something similar and the js in the view is getting in my way.


Top
 Profile  
 
 Post subject: Re: Dynamic form fields
PostPosted: Mon Oct 14, 2013 3:13 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu May 14, 2009 10:00 am
Posts: 9
@sohopros - did you find a way to do this? I'm trying to achieve the same thing and I can't figure a way of doing it using the Joomla! "xml/fields" method.

For those who don't understand the question (@ranwilli - why bother being that nonconstructive?) as far as I understand what sohopros is trying to do (and me) is:

Create a component in the admin area of which it is possible to create form fields to use elsewhere (front-end in my case) within the component. These fields will be stored in the database.
As these fields will be named "dynamically" as they are created in the component, you cannot (seemingly) use the normal Joomla! method for creating the "edit.php" views for displaying/editing.

Example (based on MY requirements):

OK for a "fixed" form field:

administrator/components/my_component/models/forms/release_credit.xml
Code:
<field name="num_credits" type="numfields" default=""
            label="Number of credits available to this user" class="readonly" readonly="true"
            description="How many credits available?   "  />


administrator/components/my_component/views/release_credit/tmpl/edit.php
Code:
<div class="control-group">
   <div class="control-label"><?php echo $this->form->getLabel('num_credits'); ?></div>
   <div class="controls"><?php echo $this->form->getInput('num_credits'); ?></div>
   </div>


So, along with the field type file we can display the form field.

But if I want to use this method for many fields that are created dynamically in the admin area and front-end users fill them in to populate a db table I can't use the method I describe above as I don't know what the fields will be!

OK, I could create my own forms in the view and override the "save" function but I'd like to do it 'properly' if there is such a way to do it.

My current line of thinking is to populate the xml file programmaticaly each time a new form field is added, but this seems like a right old faff to me.

Anyone got any further ideas?


Top
 Profile  
 
 Post subject: Re: Dynamic form fields
PostPosted: Tue Oct 15, 2013 3:59 pm 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Sat Dec 06, 2008 7:07 pm
Posts: 307
I can do this for you if you want.
PM me.

_________________
http://www.ratmilwebsolutions.com


Top
 Profile  
 
 Post subject: Re: Dynamic form fields
PostPosted: Tue Oct 15, 2013 4:02 pm 
User avatar
Joomla! Explorer
Joomla! Explorer

Joined: Sat Dec 06, 2008 7:07 pm
Posts: 307
Anyway, what´s wrong in overwritting the save method?
This would be in order to put all field values into one value.
Otherwise you would have to create a hidden field and write the value using javascript.

_________________
http://www.ratmilwebsolutions.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ] 



Who is online

Users browsing this forum: No registered users and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group