Forums

HOW TO use Chronoconnectivity / Chronoforms

TimC 21 Feb, 2015
This is driving me mental and I'm spending way too much time on something that should be straight forward (again !).

I have a CF(v5) Form that captures data and saves it to the DB - great.
I have CC(latest version) and have created a connection that displays data when viewed in the connections manager - also great

Why can I not get a form to display a simple list of all records ???

DBRead
I have tried adding a DBRead and associated RenderHTML block in on the Load event. The data is getting read because if I add an "Export to CSV" block inside the "On found" block a "file, save as" pop up appears so it is clearly retrieving the data ... why is there no "Show Records" equivalent ?

In the Forms Manager I can see the associated table and can view the data, so the connection is working just not displaying when I test the form.

Connection Action
I have also tried removing the ReadDB block and inserting a CC "Connection Action" but no combination of "load" or "view" actions etc will get any data to display when I test the form.

What steps I need to take ?
[list]Do I need a ReadDB block or a Connection Action in the OnLoad block of the form?
If I use a ReadDB block, do I need to add any code/elements to the "OnFound" block ?
Do I need to include elements in the designer to display the results or should the data just "list" (as it does if you select "Front View" in the connection manager)?
Is there a comprehensive set of instructions of how to achieve the simple task of displaying records ?
[/list]

The forums and FAQ's either refer to the previous versions of the products or are missing the vital links in understanding how the products interract.

I'm sure this is down to my understanding of the products but the HOW TO sections of the site only show how to create the connection or how to do some really funky stuff with the products but the simple "how to integrate them both" is really lacking.

I've now spent something close to 5 hours just to display a list of records on the Front End and am getting really frustrated ... double grrr.



Please HELP !!

Thanks,
Tim
GreyHead 21 Feb, 2015
Hi Tim,

I'm not clear what it is that you want to do here?

In the simplest version ChronoForms is for creating forms and ChronoConnectivity is for showing lists of records. So I would expect you to be using CC to show the list?

You can show a list in a ChronoForm though. Put the DB Read action in the form On Load event and set the Model ID to say list_data; then add a Custom Code element in the Designer tab and add PHP+HTML like this:
<table>
  <thead>
    <tr><th>ID</th><th>Title</th>
  </thead>
  <tbody>
<?php 
foreach ($form->data['list_data'] as $row ) {
  echo "<tr><td>{$row['id']}</td><td>{$row['name']}</td></tr>":
}
?>
  </tbody>
</table>
This is a very simple example - your row names and titles will be different and you can have more columns and add more formatting/functionality.

Bob
TimC 21 Feb, 2015
Bob,

Again thanks for the prompt response.

That is indeed very clear ... I was under the impression that the table data needed to be shown in a form to use the CC.

I think what you're saying is that I should be using the CC to embed the data table into an article/module/custom php script.

If I were to show the data in an article, what's the syntax for using the CC connection in code ?

What I'm trying to achieve is to retrieve the Google Map locations which are captured by the Form (and which you've previously helped me achieve - thanks), iterate through each of the rows of data and display a Google Map Marker on the map showing the locations (with a custom icon). There is no need to accept any further user input so I'm kind of kicking myself now thinking that I had to use CC with another Form (although the ability to filter the results by date, location etc would be useful so maybe using a form in time).

I'm pretty sure that once I can retrieve a row of data (either in another form or in a Joomla article), that I'll be able to figure out the map stuff, as there is a wealth of examples/information both here on the forum and elsewhere after a Google search.

You've certainly put me on the right track but some idea about how to use the CC connection string in an article would be a bonus.

Thanks again.
Tim.
GreyHead 21 Feb, 2015
Hi Tim,

I'm not sure that we’ve got it clear yet,

ChronoForms and ChronoConnectivity both stand alone (though they are both based on a shared framework library behind the scenes). If you want to display a list from a table, use CC; if you want to build a form to input or edit data then use CF.

The two will work together - you can add a link in a CC listing to open a ChronoForm to display or edit data for example - but they don't *have* to work together.

You wrote: I think what you're saying is that I should be using the CC to embed the data table into an article/module/custom php script. I'm not sure what that means but I think that the answer is ''. What I gave was an example of a way to create a list in a ChronoForm - if that met your needs.

In your case you want to read a list of entries from a database table and use those to create markers on a Google Map.

The main problem you have here is that you are reading the database table on the server before the form loads and you (I think) need to create the markers using JavaScript in the browser after the form loads. To do this you can set a JavaScript variable in a Custom Code element in your form that can be read once the form has loaded.

Looking at this StackOverFlow answer as a possible method you could create a variable like this (I'm assuming that you have data columns for title, lat and lon).
<?php
$locations = array();
$i = 1;
foreach ($form->data['list_data'] as $row ) {
  $locations[] = "['{$row['title']}', {$row['lat']}, {$row['lon']}, {$i}]";
  $i ++;
}
$locations = implode(",\n", $locations);
$locations = "var locations = [{$locations}];";
$jdoc = JFactory::getDocument();
$doc->addScriptDecalaration($locations);
?>
!! Not tested and may need debugging !!

That should create the locations variable and add it to the page code so you can then access it with your JavaScript to create the markers.

Bob
TimC 21 Feb, 2015
Bob,

Again thanks (I think you're going to be drinking a lot of coffee !).

I understood your response (although still struggling to get your example working - have tried adding the custom code element to both the form (in the designer) and also in the OnLoad event - neither of which are displaying the data just yet).

To ensure my understanding ...

If displaying a (static) list of data on a CF ... Read the DB in the Onload event, dynamically build the HTML for the table of rows (using your example) in the designer (custom code object), so that when the form is rendered the HTML "rows" appear.

If displaying data elsewhere in Joomla (ie. NOT a CF but in an article or module for example), write some code (php) to use CC to make a connection to the relevant table, then iterate through the rows (similar to your example above) to dynamically create the HTML to be displayed.

N'est pas ?
Tim
Max_admin 21 Feb, 2015
Hi Tim,

The quickest way to display a list of data loaded from a database table is to use CC.

But its doable using Chronoforms using Custom code as Bob has already showed, the HTML action or the "Custom code" action should be AFTER the "db read".

We have many CCv5 tutorials on the FAQs section, you can check the first two quickly to get an idea about CC.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 21 Feb, 2015
Hi Tim,

No - not quite.

You wrote: "If displaying data elsewhere in Joomla (ie. NOT a CF but in an article or module for example)"

You can't *just* display data elsewhere. ChronoForms does have a module for displaying a 'form' in a template location; and a plug-in for displaying a 'form' in an article.ChronoConnectivity has neither of these at the moment - maybe sometime in the future - though I believe it is possible to use one of the loadposition extensions to do that.

While ChronoForms is basically a form tool - it can be used to output pretty much anything that you can build with PHP and HTML. So you can put a listing in an article or into a module location that way.

You wrote: "write some code (php) to use CC to make a connection to the relevant table, then iterate through the rows"

No again - ChronoConnectivity includes all of that functionality. it is designed to let you read one table (or several connected tables) and generate a listing from them. There is no need for any code (at least until you get into more advanced customised listings).

I may have caused confusion in my earlier post showing how to create a listing in a ChronoForm - sometimes that is useful for particular applications, but it is not required.

Bob
TimC 21 Feb, 2015
Bob, Max,

Thank you both for taking the time to answer my questions - I am extremely grateful.

I certainly think both products are excellent and are clearly the product of many hours of work.

I'm a lot clearer now as to how both products are used, how they may integrate into my site and definitely justify the small fees charged. I am developing a commercial site which is almost complete and shall be purchasing a subscription for either or both of the products once we're live and I've determined whether I will be using just the CF or the CC component as well.

I shall take more time to read the CC tutorial now I know its purpose - I must confess to getting a bit swamped by all the new information for both components - it's been less than 3 days now which is testament to how simple the interface is for such complex components, and the support you've both offered.

Thank you both again - I couldn't have got here without you.

Kind regards,
Tim
TimC 22 Feb, 2015
Bob (or anyone else that feels their input may be of benefit),

Owing to how helpful you've been so far I was wondering if I could pick your brains on a question of architecture...

The aim
The aim remains to display multiple custom map markers on the Google map. The data having been captured by a CF from user input.

What I have managed to achieve
The "capture" CF now works beautifully, capturing the GeoLocation and custom data for each "location".

Thanks to your help I can now also retrieve the DB records of "locations". I have implemented this with another CF (lets call it "display") due to the simplicity of creating custom content with Chronoforms. It may not be the most efficient way to produce the "display" page but for speed of development it will do for the time being.

I can display Map Markers on the Map based on the retrieved locations (again based on the code you provided) and was just looking into "clustering" (as there may potentially be many markers geographically close) when I came across my problem ...

The Problem
Thinking ahead I am likely to end up with many thousands of markers just within the UK and yet the site will need to cope with markers globally. Clearly I don't want to load "all" markers then handle the logic of whether to display the marker client-side, a-la your example above.

This leads me to the conclusion that I will need to only retrieve the locations that fall within the bounds of the map displayed using a paramaterised query. When a user moves the map and the bounds change, I need to re-poll the DB to retrieve a new dataset of markers that will fall within the "new" bounds of the map. All obvious so far.

The question therefore is:

1) Is using a chronoform the best way to achieve this, and if so how would you handle the requery of the DB ? I currently have hidden fields to hold the lat/long bounds of the map displayed (which update as the map is moved) so that I can reference them easily, however, I'm struggling with the "process" of re-querying the DB. The initial OnLoad event handles retrieving the correct set of "locations" according to the map bounds, by using a parametrised query, but not sure how to handle the "bounds changed" event that is fired to requery again and retrieve the "new" location dataset.

2) Would it be better to develop a custom module and use Chronoconnectivity to handle the parameterised query processing instead?

I have some reservations about option 2 as I'm not sure how to handle the callback (Ajax ?) such that only the map element is updated, but if this is the best option (i.e. not able to achieve what I want with Option 1) then I will take the time to research it - I just don't want to head off down a new research project when I feel so close to completing the project.

Thanks,
Tim
Max_admin 24 Feb, 2015
Hi Tim,

You will need to do an AJAX call when the map bounds change and load the markers within the new displayed area, I didn't work with GMaps before so I'm not even sure if this is doable, but you can create a new event in your form and call it in your AJAX code using this url: form_link + &event=new_event

The results can be then captured and loaded using code, I suggest that you google how to load new markers on map change.

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
TimC 24 Feb, 2015
1 Likes
Max,

Thanks for the response - I am very close to a complete solution and the good news is that it is doable - a lot of head scratching but I got there. Little bit of tidying up to do and then I'll be posting it on the forum to help anyone else trying to achieve the same.

Thanks,
Tim
This topic is locked and no more replies can be posted.