Forums

Retrive table connected and update a field

kluster 16 Nov, 2011
Hi to all,
i need to develop a simple plugins in order to print values of form into pdf using FPDF, and i would like to know how to retrieve table connected name from chronoforms.

I'm in the onsubmit event and i've already generated the PDF and attached to email (if i can get it works fine i will post the code)



			if ($params->get('savetodb')) 
{
     // TODO salva nel DB  */
    $db 				=& JFactory::getDBO();
    $updateRow 			= new JObject();

                     // THIS IS WHERE I NEED TO RETRIEVE TABLE ID AND NAME
    $updateRow->cf_id 	= JRequest::getVar( "cf_id", 0, "post", "int", "" );
    $messages[] 		= 'Valore del record: '. print_r($updateRow->cf_id ,true);
    $updateRow->pdfpath = JPATH_SITE.DS. $params->get('dirserver').$params->get('pdfFileName');
    $ret 				= $db->updateObject('jos_chronoforms_pdfTest', $updateRow,'cf_id');
    $messages[] 		= 'Salvataggio del file in DB: '. print_r($ret,true);
}
if ($params->get('debugging')) 
{
    $helper->showPluginDebugMessages($messages);
}


The Problem you'll know is: i don't have cf_id in Jrequest. From Autogenerated code i would do it with no problem, but i need get it done inside the plugin so is there's a shortcut or i need to check mysql for mysql_insert_id() function?

Second i would like to retrieve the name of the Table connected to $chronoforms, it should be automatic and not hardcoded in the plugin (in this case jos_chronoforms_pdfTest). Witch chronoobject collection hold the table name connected to form id?
GreyHead 16 Nov, 2011
Hi kluster,

Most (maybe all) of the form info is in the $form object. Echo that out and check if the table name is included.

Bob
kluster 16 Nov, 2011
Thank you Grayhead for your prompt reply

I try but i don't have a form object, for now i hack using a parameter for plugin
$params->get('tableName')

but i guess there's something like that or isn't?

$MyForm =& CFChronoForm::getInstance();
$tableName = $MyForm->formparams['?????']


or maybe
$tableName = CFChronoForm::getTableName($row->form_id); ????

i keep trying

Thanks
kluster 16 Nov, 2011
Ok, it's in the
$MyForm->formparams('tablenames');
kluster 16 Nov, 2011
I've done some testing, and it seems to me, correct me if i'm wrong but in
/com_chronocontact/libraries/chronoform.php the program make the steps
1. uploads
2 plugins_before_email
3. onsubmitcodeb4
[4. autogenerated_before_email]
5. emails
then 6-7-8
autogenerated_after_email
onsubmitcode_order
plugins_after_email
depends on which order is defined in the "Run Order" tab right?

So, i can't attach the email (plugins_before_email) togheter with updating the data inserted because the saving occurs after the emails events. Did i get it right?

This is my config


So is the plugin

echo $pane->endPanel();
echo $pane->endPane();
$hidden_array 	= array ( 'id' => $id,
'form_id' => $form_id,
'name' => $this->plugin_name,
'event' => $this->event,
'option' => $option,
'task' => 'save_conf');
$hidden_array['params[onsubmit]'] = 'before_email';								
echo  $helper->createHiddenArray( $hidden_array );



I tried also JRequest::getVar('uid') that comes from autogen_code and $db->insertid() but nothing, it retrieves post, form parameters, create pdf, but no value in DB because there's no record still inserted. (I can't use the plugins_before_email because the pdf can be set to attach pdf to email and/or saved to db)

Chronoforms version:
3.2.0
Joomla versione:
1.5.24
Component Installed:
Advanced Module Manager 2.2.6
Admintools 2.1.10
Akeeba 3.3.4
Content Templater 1.14.1
easysql 1.27
eXtplorer 2.1.0RC5
FLEXIcontent 1.5.6 beta3 (r955)
JCE 2.0.14
JComments 2.2.0.2
jNews 7.2.0
QContacts

Any suggestion? ...i keep on diggin...
Thanks
kluster 18 Nov, 2011
Sorry if i trouble you but i need a confirmation.

The db store event happens after sending the email? Looking my run order it should be not, but debuggin the plugin it happens after...
GreyHead 24 Nov, 2011
Hi kluster,

It depends on several things. The run order tab - the option on the DB Connection tab and the 'Send Emails' setting on the General tab (that must be set to Yes).

Bob
kluster 24 Nov, 2011
Thank you for you help.
I fixed the problem, i needed the saving after the mail for attaching the PDF, but after that needed to update the field so now i'm setting the field in JRequest::setVar() and the autogenerated code do the rest no matter which order has.
Now the plugin is running, i don't know if you've saw the PM i sent you with screenshots, it's still in beta, i sure need to clean and improve the html pre-processing performance but now it's working. If you want me to post here let me know
Thank you
GreyHead 24 Nov, 2011
Hi kluster,

Glad to hear you got it working.

I have your plug-in in an open browser tab waiting for me to get to look at it properly.

Bob
kluster 24 Nov, 2011
ok, i'm updating the zip files during this days.
I don't know when you have downloaded but in first version there was an error on relative path of attachment on Windows, i suggets you to download again (the 55kb only class and plugin zip).
This topic is locked and no more replies can be posted.