[SOLVED] Pre-propulate data in field from one form to another form

antonitus

Member
Hi,

Can someone please tell me how to pre-populate data from one form in one field to another form in another field.

For example, I want to pre-propulate data from a registration form called 'Registration' in, say field 'Dental Practice Name' when a user registers. The data in that field then gets pre-populated in another form called 'Referral' in a field called 'Dental Practice Name.

I searched for hours in the forum, but could not find a suitable solution unless I use 'databasejoin' plugin which works ok, but I want the data to show without user intervention, i.e. automatically show when form is loaded.

Any help would be much appreciated. Thank you.
antonitus

P.S. I am using Fabrik V3.3.2 under Joomla 3.4.1
 
Thanks for your help Icollong, however I need a dynamic one. This plugin is not dynamic, i.e. it will not change if a user edits their information.

There must be something out there that does this and I'm quite baffled as to why this is not easy to find as it is a very important functionality. It's so easy to use JUser fields, but it's not easy to use Fabrik's own pre-populated data functionality.
 
Databasejoin is not suitable for this. I just want the data to be automatically filled into the field without dropdowns, radiobuttons, etc. Maybe the devs could add another option to add it into the field. It's very strange this was not thought out properly. I may see if I can add it myself in the code or replace one of the databasejoin options to a field only, saves me having to create another table and mess things up.
 
Hi Antonitus,

I am working on a similar problem to this at the moment. Whilst I'm not sure I have all of the solution for you I am exploring whether passing a variable through the url will work to prepopulate various parts of a form I have. Have you considered if this approach might work for you? This thread may help, though I am still working out how to make it work! http://fabrikar.com/forums/index.ph...iables-to-a-form-using-url.41059/#post-206883

Also, if you want answers more quickly and time is an issue you might consider upgrading your membership to community. It doesn't cost very much at all and my experience is that the makers of Fabrik have thought about pretty much every scenario, have a solution for it and will help you. I have been getting great help from them and the rest of the community.

You sound pretty grumpy and critical of the community in your previous post, that may not be intentional, but you should realise it makes people much less likely to spend their time helping you. ;)

Kind regards,
Hannah
 
It's very strange this was not thought out properly. I may see if I can add it myself in the code or replace one of the databasejoin options to a field only, saves me having to create another table and mess things up.

Contributions to the code are encouraged. If you'd like to submit a PR on github, we'll review it.

-- hugh
 
Hi Hannah,

Yes you are right I was a little grumpy, I didn't mean to be, but so far Fabrik options allow you to do just about anything to a database and why the developers did not add an option to just allow data to be pre-populated into a field as well really baffles me. Maybe an update to achieve this is considered. Like I said before adding Juser fields is very simple by adding a couple of lines of code in the condition statement. I tried adding a similar code for the Fabrik tables, but it did not work. Also, it would be so easy to add just {formname___field} to the condition section as you can pretty much add this to an email to output the result. This is why I am baffled, but don't get me wrong I am extremely grateful to the Fabrik developers who are in my opinion geniuses in developing such a powerful component. I have to hand this to them and thank them for making it free.

I will look at your solution in passing a URL and see if that works for me, so thank you very much for your response, which is much appreciated. I'll let you know how I got on. In the meantime I think I may edit the databasejoin plugin to see if I can add data to just a field. I know basic PHP and quite good with MySQL as I use to create databases years ago, so hopefully it shouldn't be hard to do, .... I think. The Joomla way of creating databases is a lot different than doing it the normal way as you have to abide by their MVC rules and I find that a bit confusing, even though Joomla simplified the coding.

Tony
 
Hi Hannah, having looked at your URL workaround, it's actually not good for me as I need the id of the user to match that record. If I was to get it to work, it will not be secure as I will have sensitive dental patient details that anyone who figures it out will see my other patients records.

Thanks for your help.
 
No worries! Yes the security side of things is a bit of an issue isn't it? I'm just wrestling with the same debate myself, is the info I am passing through sensitive or not? Sometimes it is, which means I'm going to have to do some rethinking. Oh the joys! :rolleyes:
 
Hi,
[...] For example, I want to pre-propulate data from a registration form called 'Registration' in, say field 'Dental Practice Name' when a user registers. The data in that field then gets pre-populated in another form called 'Referral' in a field called 'Dental Practice Name'.
Why not make the 'Dental Practice Name' in the Referral table a calc element that will query the Registration table and always return the 'Dental Practice Name' from the Registration table?

Assuming you already have a user_id element in the Registration table, and the user_id in that table is always unique, and the form is only shown to the 'Registered' users, and you don't want the user to be able to edit the value (in the Referral form) - then the calc element sounds like the easiest way to go - and the calc code would be similar to...
PHP:
$db = JFactory::getDbo();
$db->setQuery('SELECT dental_practice_name FROM registration WHERE user_id={$my->id}');
return $db->loadResult();
Just be sure to set this calc element in the Referral form to always calc on load - since the value may have been changed elsewhere since the last edit.
 
Hi Bauer,

Thank you very much for helping me, it's much appreciated.

I added your above syntax, however I just get a blank area with no field and it only shows the label. Any suggestions. I also set to calculate on load too. I tried different user fields, but without any success. This code seems so promising and I'm sure I'll get there in the end.
 
Try adding some debugging to your code. E.g.
PHP:
$db = JFactory::getDbo();
$myQuery = 'SELECT dental_practice_name FROM registration WHERE user_id={$my->id}';
echo $myQuery.'<br />';
// leave this exit here until you get a working query
// after each edit, cut/paste the echoed query string into a query in phpMyAdmin and run the results.
// once you get a working query, remark this exit out
exit;
$db->setQuery($myQuery);
$name = $db->loadResult();
echo $name;
// if the name is as expected then remove this exit and the echos above - and it should work.
exit;
return $name;
If that doesn't get you there then post your code - 2 more eyes always helps.
 
Hi Bauer,

Thank you once again for your kind help and time.

I added your above code and yet I can't get it to work, i.e. the field in the front end is still blank as if nothing is happening. Maybe I am doing something wrong with the settings of this field. If I do not add a field or id in the section 'Or user field' in 'Access' section, I get a blank screen so it looks to me like there is something going on here. Also, if I do not add the PHP opening and closing tags, i.e. <?php ?>, I also get a blank screen. I wasn't sure if I needed to add the PHP opening and closing tags as it is PHP Eval'd already. Also, I don't have any code to add here, except for yours. I really can't believe the developers cannot make this easier for us, just like with the JUser fields. If I was to create a database from scratch, I could just add row id for an output and it will work, but not with Fabrik and Joomla.

Tony
 
Actually this is the proper table name code:

Code:
$db->setQuery('SELECT Practice_Name FROM registration WHERE id={$my->id}');
 
Actually this is the proper table name code:

Code:
$db->setQuery('SELECT Practice_Name FROM registration WHERE id={$my->id}');
Are you sure of that? My example code was not meant to be used verbatim - it was an example. I have no idea the exact table or element names you are using here.

Did you use the debugging suggestions mentioned in my last post?
If so, what is the text/value of "$myQuery" that was echoed to the screen?
Do you know how to run a query on a database table via phpMyAdmin so you can actually test that "this is the proper table name code"?

Is "registration" a valid database table name? (exact spelling - case sensitive)
Is "Practice_Name" the name of the field/element in the "registration" table that holds the practice name? (exact spelling - case sensitive)
Is "id" the field in the "registration" table that contains the active user's Joomla USER ID? (because that is what the placeholder {$my->id} will always return).

I use the calc element quite a bit - and it works. If it doesn't return the result expected, then your code is incorrect.
(And no, you don't need to include the php tags in the calc code.) The return value from the last line of the calc code will be the value set (and always stored as a text string) and displayed for that element.

If you doubt it works - then try entering...
return 'TEST';
as the only line of code in the calc element - then tell me if it is still blank.
It is only blank because your calc code either
1. returns a blank value
2. generates a php error and so fails and never reaches the 'return ...' line (So you can also try looking at your php error log for a clue)

That is the point of using the suggested debugging code in a calc element - so you can pinpoint when/where/why the code is farting out on you.

This isn't rocket science and you'll be slapping yourself in the forehead with an "oh, duh" once you understand how it works and why your calc code wasn't working.:)
 
Strange that second long code you sent me just gives me a blank screen. I checked, re-checked everything. I even run the various queries on phpMyAdmin and they seem to work, except for id={$my->id}, which did not work. The strange thing is 'id' exists and is the id of the element and not for a JUser. I then went back and added a field called 'jid' , with JUser code (in both registration and referral forms):
Code:
$user = JFactory::getUser();
return $user->get('id');

and now the first code you sent me, below works when I replace 'id' with 'jid':
Code:
$db = JFactory::getDbo();
$db->setQuery('SELECT Practice_Name FROM registration WHERE jid={$my->id}');
return $db->loadResult();

Does this sound logical or is it the wrong way of doing it? How do you call a JUser id in a form with 'id' already being used for the id of the element?

By the way return 'TEST'; does return 'TEST' so that was working.
 
It sounds like you've got it.

I think I may have run into problems before when using a fabrik placeholder directly inside a $db->setQuery().

If what echoed to the screen was id={$my->id} then the placeholder was not being recognized.
If I recall, the simple fix for that is to store the placeholder to a variable - then use the variable in the setQuery().

So instead of
PHP:
$db->setQuery('SELECT dental_practice_name FROM registration WHERE user_id={$my->id}');
I should have suggested

PHP:
$user_id='{$my->id}';
 
$db->setQuery('SELECT dental_practice_name FROM registration WHERE user_id='.$user_id);

I'm pretty sure that query would have worked.

And, as you discovered, the Joomla user functions can be used to accomplish the same thing.

Sometimes I'm not all there with my responses. And my knowledge, understanding or recognizing the nuances of all things fabrik is probably average at best. I'm just another community member trying to help .
 
Bauer, that makes so much sense. My main issue is with how I figure out the Joomla way of coding. If I were creating a database by scratch without Joomla, then I would pretty much figure it out and I have done in the past. It would be nice if Fabrik, somewhere had a section of Joomla codes to use with their explanation. I will try the above code too, i.e.
Code:
$user_id='{$my->id}';
You have actually helped me out so much and I am so grateful to you, because without you I wouldn't have done this (take note, devs, this is much better and quicker response from the community, even though I bought a standard subscription just the other day). You have also taught me how to code Joomla stuff into Fabrik and I can pretty much do a lot to a Fabrik form.

Thank you once again.

I also have one more issue, maybe you can help me with this as you seem to be a whiz kid at this:
http://fabrikar.com/forums/index.ph...rd-password-strength-meter.41047/#post-206853
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top