• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Problem with PHP form plugins not submitting

juuser

Well-Known Member
Hello,

I have two php plugins in one form (onAfterProcess) and they both submit fine when used separately (one disabled), but when both are enabled they are not working.

What could cause this?
First plugin:

Code:
$db3 = JFactory::getDbo();
$query3 = $db3->getQuery(true);
$db3->setQuery( "SELECT MAX(a.lisatud_muudetud) FROM plastone_tooted_vormid_seadist_sissekanded AS a LEFT JOIN plastone_tooted_vormiremont AS b ON a.vormi_id=b.vormi_id WHERE b.vormi_id = '{plastone_tooted_vormiremont___vormi_id}' " );
$tulemus3 = $db3->loadResult();
 
$db1 = JFactory::getDbo();
$query1 = $db1->getQuery(true);
$db1->setQuery( "SELECT MAX(kande_kuupaev) FROM plastone_tooted_vormiremont AS a WHERE a.vormi_id = '{plastone_tooted_vormiremont___vormi_id}' " );
$tulemus1 = $db1->loadResult();
 
$db2 = JFactory::getDbo();
$query2 = $db2->getQuery(true);
$db2->setQuery( "SELECT kande_kuupaev FROM plastone_tooted_vormiremont AS a WHERE a.id = '{rowid}' " );
$tulemus2 = $db2->loadResult();
 
if ($tulemus2 > $tulemus3) {
 
if ($tulemus1 == $tulemus2) {
 
$vormkorras = '{plastone_tooted_vormiremont___tagasi_kuupaev}';
if ($vormkorras == '')
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$db->setQuery( "UPDATE plastone_tooted_vormid AS a LEFT JOIN plastone_tooted_vormiremont AS b ON a.id=b.vormi_id SET hooldusstaatus='4' WHERE a.id = '{plastone_tooted_vormiremont___vormi_id_raw}' " );
return $db->loadResult();
 
} else {
 
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$db->setQuery( "UPDATE plastone_tooted_vormid AS a LEFT JOIN plastone_tooted_vormiremont AS b ON a.id=b.vormi_id SET hooldusstaatus='0' WHERE a.id = '{plastone_tooted_vormiremont___vormi_id_raw}' " );
return $db->loadResult();
}
}
}

Second plugin code:

Code:
$tulemus11 = "R";
$tulemus11 .= "{plastone_tooted_vormiremont___id_raw}";
 
$db7 = JFactory::getDbo();
$query7 = $db7->getQuery(true);
$db7->setQuery( "UPDATE plastone_tooted_vormiremont AS a SET t66_id_nr='$tulemus11' WHERE a.id = '{plastone_tooted_vormiremont___id_raw}' " );
return $db7->loadResult();

Thanks :)
 
Are they not submitting at all?
Or not working correctly?

You can put some debug code, e.g.

echo 'plugin1';exit;
If you get a blank site with "pugin1" remove the exit and addtionally put e.g.
echo 'plugin2';exit;

This should give you a blank page with plugin1plugin2
etc.

To check if the variables are correct, e.g.
var_dump($tulemus11);exit;
 
Thanks Troester,

If i put echo 'plugin1';exit; I get the following output:
Notice: Undefined offset: 0 in C:\Apache24\htdocs\plugins\fabrik_element\fileupload\fileupload.php on line 1565
plugin2

Does this help?

I think the variables should be ok, if the plugins separately work fine?

BR,
Martin
 
Thanks, I tested the variables with var_dump. With the second plugin the output is correct, but with second plugin, var_dump
doesn't work and form submits with no var_dump output.

So it seems like it's not processing the plugin at all :(

I tried copying the code to new PHP plugins and deleted the old ones, but this didn't change anything. Is there something else to try?

Thanks,
Martin
 
Attention:
if you have an exit; in the first plugin (whichever is first executed) this will stop all execution and the 2nd won't run.
 
Yes, i removed var_dump();exit; row from the other plugin, but still nothing. So it still seems that it's not executing the plugin at all.

EDIT: I now noticed that whichever plugin is first in the list, gets executed, and second one not.
Noticed this when deleted the first one and added new one with the same code at the end.
 
Hmm
I just tested with 2 php onAfter plugins setting cookies: both cookies are set.

Which exact Joomla and Fabrik version are you running?
Do you have any other plugins in this form?
 
I have Joomla 3.3.6 and Fabrik from Github from this weekend. This form has also e-mail plugin, but I have disabled it.

One more correction to my last post. The second plugin in list always gets submitted and first one not.
 
Thanks, will have to go away for a while. I cannot test this, now something else seems to be wrong. When wanting to add new row to list i just get white page with "NULL" in the corner. Will have to investigate this later.
Thanks!
 
Thanks, this "NULL" is ok now.

I'm starting to go crazy with this. I even start to see no consistency in this. One thing seems to be sure, both plugins work alone, but not together.
I have tested all the variables with var_dump and they seem to be ok.

This is the same table which related data column i cannot make appear in another table. I made another thread for this:
http://fabrikar.com/forums/index.php?threads/related-data-column-not-showing.40376/

Maybe this table is broken somehow?
 
Unfortunately, there really isn't much more we can do to help on this, if we can't get at your site.

Just FYI, if you want to var_dump() from the first plugin, you can do that, just leave the 'exit' off, then var_dump();exit; from the second one. You should see the output from both.

I just tested, and multiple PHP plugins runing onAfterProcess deifinitely work, here's and example:

http://screencast.com/t/DmFldic0

As you can see, I echo and var_dump() output from the first one, with no exit, then echo and var_dump from the second, with an exit, and I see output from both. Just FYI, that's my Eclipse debugger popping up after I submit the form, where I had a breakpoint in the plugin processing. Also note that I'm dumping the $formModel->formData[] array, which is what we use for grabbing placeholder data from, so that data is deifnitely still set in the second one.

Another thing to note is that onAfterProcess, elements have had their tablename___ stripped off, so placeholders will have to use the {shortname}. I typically don't use placeholders in PHP code, I'll use ...

PHP:
// fetch non-raw value
$foo = $formModel->getElementData('tablename___elementname');
// fetch raw value
$foo_raw = $formModel->getElementData('tablename___elementname', true);

... because the getElementData() method is smart enough to know whether there should be a tablename__ prefix or not, and also understands some other peculiarities, like to look in $formModel->data during form load, rather the formData, which only exists during submission. Etc.

One thing I did notice, was that when I added the second one and saved the form, it seemed to set the first one to unpublished. But after setting it back to being published and saving the form again, everything worked fine.

-- hugh
 
Thanks Hugh for the explanation. I understand that it's a very difficult case when there's no access to site. I try to find a hosting service and set up a copy of my site there.
Martin
 
Your list vormide remondiregister has a join FROM vormi_id TO vormi_id
Fabrik supports only joins where one of the elements is a primary key (so FROM id TO vormi_id or vice versa).

And vormi_id is the dbjoin element used in the related data.

So 2 possible issues:
the incorrect join
+ indentical element names in the join, so in the main group, in the joined group, and used for dbjoin element (which may confuse Fabrik, I can recall an issue with identical element names in joined groups).

Try to rename one of the elements and set up a join with a primary key.
 
Thanks Troester,

I renamed list "Vormide remondiregister" element "vormi_id" name to "vormi_id_nr". I also removed the (vormi_id->vormi_id) database join totally, because there are no relation between id and vormi_id.

Still no change :( I don't know is this important, but exactly the same setup worked with Joomla 2,5 and Fabrik 3.0.)

BR,
Martin
 
OK, I've made a few changes to the scripts, but you need to go in and fix them to reflect the name changes you made to the elements - I'm getting "Unknown column 'b.vormi_id' in 'where clause'". But it's too late and I'm too tired to work out which table you changed that field name in.

But I also think I worked out why your second plugin isn't working, which is because you were doing:

Code:
return $db->loadResult();

... where your query is an UPDATE, not a SELECT. The loadResult() method is used for returning a value from a SELECT. It returns the first value from the first row in the result set. If there is no result set, it returns false. And UPDATE doesn't return a result set. So, you are returning 'false' from your plugin. Which in Fabrik 3.1/2 causes submission processing to stop at that point, meaning no more plugins get run.

So ... where you are currently using $db->loadResult() for UPDATE queries, you need to be using $db->execute(), which will only return false if the query actually fails. The reason this used to work in 3.0 is, loadResult() will still run the UPDATE query, and the query will work, it just means the result coming back is false. And in 3.0, we used to ignore the return value from form plugins, and just carry on processing, even if a plugin returned false.

I've changed all those loadResult() to execute(), but as mentioned above, you'll have to fix the actual queries with the new field name.

BTW, you don't need to grab new $db and $query instances for every query, using JFactory::getDbo() and $db->getQuery(true). You can re-use the same $db and $query objects object, just clear your query between each one, like ...

Code:
$query->clear();

... then just go ahead and re-use it to build the next query.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top