PHP Plugin on form

Status
Not open for further replies.
Hi there,

I want to update data in another table when my form is saved.

I created a script and pointed the form plugin to it.
(I built the script from pieces that I found in posts and it follows below)
It does nothing!!!
I then one of read cheesegrits advise on a post and inserted a vardump to at least check that I get the form element values at least...it does not dump the values which made me think that the script is not triggered when I expected to. I tried the different process script options onBeforeCalculations, onAfterProcess, onBeforeProcess . Nothing

Does anyone have any advise for me?

(I have also tried removing the line which says something about dying?)

When you look at the script below does it look as if the query syntax is correct and should work?


'------The Script itself (in lptenders.php)
defined('_JEXEC') or die();
$registerclose = getElementData('tenders_register___tender_register_closingdate');
$tenderclose = getElementData('tenders_register___tender_close_date');
$tenderid = getElementData('tenders_register___id');
var_dump($registerclose, $tenderclose, $tenderid);exit;

$db =&JFactory::getDBO();
$db->setQuery("UPDATE tender_invitees SET tender_register_closingdate = '$tenderclose',tender_closingdate = '$registerclose' WHERE tender_id = '$tenderid'");
$db->query();
 
OK, first when you say, "it does nothing", what exactly happens?

If the code in your post is actually the one that is suppose to run, you should at least have a white screen, with normally the dumped value of your variables, when you submit the form.

If not, then the plugin is indeed not run. Is your script at the correct location, that is plugins > fabrik_form > php > scripts? If it appears in the selectable scripts, I guess it does.
Can you post a screenshot of your plugin settings?
 
Hi there, thanks for responding

1. I assume the php file is in the correct location as the dropdown picks it up
2. Nope, no white screen or anything ...

the plugin setttings are attached .
 

Attachments

  • PluginSettings.JPG
    PluginSettings.JPG
    35.2 KB · Views: 247
and do you have defined somewhere else a function called 'getElementData' otherwise the code is invalid.
 
Try:

PHP:
defined('_JEXEC') or die();
$registerclose = $formModel->getElementData('tenders_register___tender_register_closingdate', true);
$tenderclose = $formModel->getElementData('tenders_register___tender_close_date', true);
$tenderid = $formModel->getElementData('tenders_register___id', true); 
var_dump($registerclose, $tenderclose, $tenderid);exit;
if (!empty($tenderid)) {
    $db = JFactory::getDBO();
    $db->setQuery("UPDATE tender_invitees SET tender_register_closingdate  = '$tenderclose', tender_closingdate = '$registerclose' WHERE tender_id   = '$tenderid'");
    $db->query();
}
That should at least run, and dump out those three variables. Make sure that:

a) Both dates are in standard MySQL YYYY-MM-DD HH:MM:SS format.

b) That the id is an integer, not an array. I can't remember offhand what the 'internalid' element type submits as. If it is an array, put this after the getElementData:

PHP:
if (is_array($tenderid)) {
   $tenderid = JArrayHelper::getValue($tenderid, 0, 0);
}
Note that I've also wrapped your db update up in a test to make sure $tenderid has a value, to avoid nastyness if, for any reason, it doesn't.

Would suggest running this onAfterProcess, to ensure that it only happens if the form has successfully submitted and the main form processing has already updated the tender_registers table.
 
Also, you should probably run all three variables through $db->quote(), rather than just quoting them yourself, to avoid SQL injection attacks.

PHP:
    $db->setQuery("UPDATE tender_invitees SET tender_register_closingdate  = " . $db->quote($tenderclose) . ", tender_closingdate = " . $db->quote($registerclose) . " WHERE tender_id   = " . $db->quote($tenderid));

-- hugh
 
Had a couple of issues.
1. jfquestiaux , yup I forgot (did not actually know) the (<?php and ?>)
2. Then I misread the other post and did not add the $formModel-> into the code


After that , it worked ....
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top