Forums

Repopulate form on front-end open

jgribble 04 Oct, 2011
I have a client with a unique end-user need. She wants the form to be used just like an author-editable Joomla article, only it saves versions to the database. The test form is working beautifully from the standpoint of storing data. It is linked to a menu item in the front end. When that link is clicked, I want the most recent dbase record to repopulate the publicly visible fields in the front-end display. On save, I want the edited data to reappear for further editing by the user if desired. I thought this was a simple matter of enabling "load fields" in the db record loader event. And adding a "redirect user" URL in the "On Submit" event actions. But apparently there are a couple other nuances, relating to parameters, which I hope to discover through this thread. And share with others who have a similar need. This need is for something that functions as an editable interface, versus say a login or registration form which simply files and routes data records.
GreyHead 04 Oct, 2011
Hi jgribbel,

I guess this is ChronoForms v3?

How are you storing the versions?

I'd probably use the profile plug-in to re-load the data for editing.

What problems are you finding?

Bob
jgribble 04 Oct, 2011
I'm using the new version 4 and really love it. I've read about the Profile Plugin but haven't been able find it for download; and I assume it comes with documentation. The problem is, my current settings don't repopulate the form on open as desired by the client. Also, upon Submit, although I have a URL redirect event set up to take the user back to the form, the Submit result takes the user to a blank Joomla article. Thanks for the fast reply!
apryl 05 Oct, 2011
Is there a profile plugin for v4. I have just started using the new version and can't seem to find that option anywhere?
GreyHead 05 Oct, 2011
Hi jgribble,

The Profile Page plug-in was a CFv3 plug-in. In CFv4 the equivalent is the DB Record Load action - I think that there's a tutorial for using it in the Downloads area here.

In CFv4 use the ReDirect User action to redirect to a fixed URL. If you want to redirect to a dynamic URL dependent on the form results then use the ReDirect URL action follwed by the ReDirect User action.

Bob
jgribble 05 Oct, 2011
Thanks, I do have a load record event installed and configured according to the tutorial, but it doesn't work. I also have a redirect user event installed, which also doesn't work. In the drag window of Events/Core Options, I don't see "redirect url" as an option. So, how do I add the event? I also do not see such an event option in the second tier of Events ("utilities" etc.). I assume there are some tricks that I am missing.
Max_admin 05 Oct, 2011
Hi Jim,

There may be more than 1 way to do this but here is a simple one I could think about now:

#1- make sure your form fields has a hidden field named "cf_id"
#2- in your "on submit" event, remove any redirect actions you may have, and add a custom code action after the "db save" action, and add this code inside:


<?php
$mainframe =& JFactory::getApplication();
$form_url = "ADD your form url here";
$mainframe->redirect($form_url."&token=".$form->data['chronoform_data']['cf_uid']);
?>


Assuming you have followed the tutorial and that your form is using the "token" parameter name to load the data then your form should be reloaded with the data just saved and is still editable🙂

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
jgribble 05 Oct, 2011
Thanks, I am giving it a try right now. Looks straightforward.
jgribble 05 Oct, 2011
Worked! Fantastic. But . . . I also want the most record to populate the fields On Open. Such that the last edited data is there on screen for the user to see when the user clicks on the menu item to open. I assume a variation of the code has be inserted into the "On Load" event? I believe I have the On Load event parameters set correctly. Screen shot is attached.
GreyHead 06 Oct, 2011
Hi jgribble,

It should be enough to include the DB Record Loader in the On Load event before the Dhow HTML action (check that the Show HTML action has Republish set to Yes).

Bob

Bob
Max_admin 06 Oct, 2011
Hi Jim,

If you are going to have the "token" parameter in the form link when it loads then having the same actions/events structure is enough as Bob has mentioned, but if the parameter will not be in the link then you need to load the record using the logged in user's ID maybe ? if yes then please see this post:
http://chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=26&t=22788&p=74585#p74585

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
jgribble 06 Oct, 2011
Thanks, but . . . If the way I have it set up now "should be enough," I am still puzzling over why the record does not populate the fields on open from the front end. In other words, why doesn't work?Is there another step? Also, I don't want to use user ID as the param, because the document needs to be visible to all registered users for reference. One of the uses here will be a publicly viewable telephone contact list.
jgribble 12 Oct, 2011
Well, none of your suggestions have solved the problem, careful as I was to follow them to the letter. You said it SHOULD work, but when it DOESN'T work, what then? FYI, what will happen if I tell the form to use cf_uid versus cf_id to repopulate the fields? Bear in mind that this is an open document to which multiple users will have edit access; and must be viewable by any registered site user. It's intended so that registered users can edit the information, save, and voila the updated documents pops right back up. Seems to me that this is a pretty common end-user need. How about posting a step-by-step tutorial? Also, if you'd like to take a quick look at this form in the back end, I'd be happy to let you in.
pharnos 08 Dec, 2011
I would also love to know how to achieve this.

I have a form set up, which saves correctly to the database.

Setting the QUERY at DB Record Loader to the below will successfully load the first set of data that the particular logged in user entered.
<?php
$user = &JFactory::getUser();
echo "cf_user_id = ".$user->id
?>

What I want though, is for the data to be loaded based on what the article id is. So, there is one form added to multiple articles using {chronoforms}form_name{/chronoforms} but depending on which article it is inside, it should load the data relevant to the article. All Joomla users need to be able to see the different articles and different corresponding data in each form.

I added a new hidden element called "id" and now changing the QUERY at DB Record Loader to the below, it successfully adds the article id number to the DB Save.
<?php
$id = JRequest::getInt('id', '', 'get');
?>

So now the form is aware of the article it is inside, I just don't know what additional code to add to the QUERY in order for it to display the correct data. It seems possible because it works when looking up the currently logged in user; but this way no matter which article you open, the same data is loaded (which makes sense since it's just looking at the user you are currently logged in as).

If anyone could help, that'd be choice!


Cheers,
Steve.
GreyHead 17 Dec, 2011
Hi Pharnos,

I think that if you add id in the Request Param box of the DB Record loader this should work OK.

Bob
pharnos 20 Dec, 2011
Hey I just thought I'd update this thread as I've managed to get it working how I wanted.

In the form preview I created 2 hidden fields, with a field names of "cf_id" and "id". Not sure if "cf_id" is requied, I left it there from testing with the tutorial.

In the "On Load" action I added a "DB Record Loader" with the settings:
DB Field "id"
Table "<name of table to load the data from>"
Request Param "id"
Load Fields "Yes"
Model ID "<blank>"
Load Under Model ID "No"
WHERE statement "<blank>"
Array Fields Sets "<blank>"
Array Separators "<blank>"

Now I can create a new article with:
Title = "Test Form in Article"
Body of article = <read more tag - red dotted line> followed by {chronoforms}<name of form>/chronoforms}

Then, opening that article (which has an id of 33 in this case) it displays my form, all good so far, all the form fields are blank, as expected. After filling out the form and performing a "DB Save" (which I named as a button on the form called "Update") it redirects you (using the redirect action) to a page displaying all the articles available. If you open the article just created, the form is displayed AND ALL THE FIELDS ARE POPULATED WITH WHAT WAS PREVIOUSLY ENTERED WOOHOO! As a test I changed the text in one of the fields, updated, opened the article again AND THE AMENDED TEXT IS DISPLAYED IN THE FIELD THAT WAS UPDATED, YES!

So, everything is now working how I want it to. Hopefully this might help other out who may be tryign to achieve the same.
This topic is locked and no more replies can be posted.