Pre-populating Forms

jsg2510

Member
I have a list that shows classes in a school. Each class can have several subjects.

I have set up an add new subject button for each class on the list which sends me to the appropriate form. The problem is that on that form it gives me a list of all known classes in the db - it would be much more convenient to have the class auto-populated as the form was launched from a class specific button.

On the other hand it is possible to select an option to add a subject from other parts of the system and in this case the full list of classes is needed so that the subject can be associated with the correct class

thanks
 
Just add the class id as a request var at the end of the url of the add new subject button.
e.g. ?class_id={tabelename___class_id_raw}

Then, in the form, add a PHP plugin and enter php code that is only run 'In: Frontend' and 'On: New'.
In that code check the url request for the class id and pre-set the class element 'raw' value to that id.
PHP:
$class_id = FabrikWorker::getMenuOrRequestVar('class_id','');
if($class_id != '') $formModel->data['tablename___class_element_raw']="$class_id";
 
Rather than a form plugin, it could just be an eval'ed default on the class element i the target form.

Code:
return FabrikWorker::getMenuOrRequestVar('class_id','');

-- hugh
 
Thanks
Sorry - I will need some clearer instructions on where to place this code in order to get it to work

Cheers
 
thanks

I guess that I built my db the other way - so the subject has an element that associates it with a class - hence when I list all the classes & have a button to add a new subject under the class then there is no form element to edit - unless I am missing something obvious
 
I'm talking about on the 'subject' form, your "target" of the link. Where you have the join for classes. Or at least, from this description that's what it sounds like:

I have set up an add new subject button for each class on the list which sends me to the appropriate form. The problem is that on that form it gives me a list of all known classes in the db

-- hugh
 
hi - not sure that I get what you are driving at - but now with upgrade to 3.4.3 the auto-populate seems to work - so thanks!
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top