Forums

Calling a form from another form's Custom Code

MainsailSoftware 29 Jan, 2015
I am uploading a CSV file that contains data for some of the columns in a table.

The table was created using ChronoForms v5 and when used by a associated form its DB Save action automatically creates the unique id, create date, created by, etc.

I would like to use a form like this and be able to call the same DB Save action from within Custom Code. The Custom Code contains a loop processing the CSV file rows.

I found a post showing some code for processing CSV files, but it was for CFv4 and appeared to require the code to generate the CF table fields like the unique id, create date, created by, etc., and then insert directly into the table (I can no longer find that post; should have stared it!). I would like to avoid doing this and rather reuse existing functionality in CFv5.

How can I call a DB Save action or another form's submit from within a form's Custom Code loop?
calculus00 29 Jan, 2015
Hello MainsailSoftware,
I'm not a Chrono professional, but after checking your new post, I think that the following links may help:
I need custom code for my form
P.S: I'm just an automated service😉
MainsailSoftware 29 Jan, 2015
Found the related post:

http://www.chronoengine.com/forums/posts/t89801.html

I am hoping I can be pointed in the right direction with either another post reference or a couple line example of calling out to a DB Save action or another form...

Jim
GreyHead 29 Jan, 2015
Hi MainsailSoftware,

I'm not clear what you are trying to achieve here?

Is this a one-off? In that case let me have the CSV file and I'll covert it for you (I have a MySQL plug-in for Excel that does quite a good job.

If it's a frequent task then I'd use a database query in the custom code rather trying to call a DB Save action. Here's an example writing a single record:
<?php
$db = JFactory::getDBO();
$query = "
  INSERT INTO `#__cf_invoices`
    SET `unique_id` = '{$form->data['unique_id']}',
    `created` = NOW(),
    `invoice_date` = CURDATE(),
    `gateway` = '{$form->data['gateway']}',
    `currency` = '{$form->data['currency']}',
    `amount` = '{$form->data['amount']}',
    `amount_gbp` = '{$amount_gbp}' ;
";
$db->setQuery($query);
$result = $db->execute();
?>
You can use a loop to create a string of 'VALUES' entries to use in a query; or just loop through with one query for each record.

Bob
MainsailSoftware 29 Jan, 2015
Well, currently it is a one-off, but I was trying to create something more generic that could be easily adapted again in the future.

As I am fairly new to Joomla and ChronoForms/Connectivity v5 (and v4 for that matter), I am trying to learn the best practice and appropriate way to minimize coding and maximizing reuse.

The actual problem is that when I created the Joomla website in question, I used Joomla Weblinks to reference about 40 newsletter PDF files. I am trying to convert to using CCv5 and eliminate usage of Weblinks, which uses absolute URL values. I have created from the Weblinks table a CSV file with the title, alias, ordering, and relative file path to be used in the URL I will create in the CC connection.

I created a new table in CFv5 as I want to be able to use a future CF file upload form to add each new newsletter to the directory and CC list displayed to a logged in user. When I use a CF form to do this I really like the way it automatically generates the CF specific table field values like uniq_id, user_id, and the dates, and such. I guess I was hoping I could simply reuse that DB Save functionality.

I guess at this point I can simply do something similar to what you have provided.

I would like to know how CFv5 generates the uniq_id value so I stay consistent and ensure they do not collide in the future.

Thanks for offering to convert the CSV into an SQL script. For now, I will use the Custom Code approach.

Jim
This topic is locked and no more replies can be posted.