• Fabrik V4.4.1 is now available.

    This version corrects the Admin issue introduced by V4.4. V4.4.1 is available through the Joomla Updater or for download through your My Downloads area of our website.

    Turns out a code change intended for our 5.0dev branch inadvertantly got pushed to the 4.x branch (by me, duh!). The javascript structure in 5.0 will change considerably and part of that change took effect with the inadvertant code change.

    We have reverted the code change and released 4.4.1. V4.4 has been retracted.

    Sorry for any inconvenience.

  • A new version of Full Calendar is now available.

    See the details here

Return Pb in PHP validation plugin

Incremental

Member
Hi,
in a PHP validation element, I use the following code :
Code:
// Check if ID exists
//===================
// Get the form field's value :
$IDinput = (int) $formModel->_formData['contacts___ContactsFormID'];
//dump($IDinput, "Form ID");

// Get the db object
$db =JFactory::getDbo();

// Quote the values for security reasons
$IDinput = $db->quote($IDinput);

// Build the query
$query = $db->getQuery(true);
$query = "SELECT count(*) FROM ContactsParams WHERE ID=" . $IDinput;
$db->setQuery($query);
//dump($query, "Query");

// Run the query
$found = (int) $db->LoadResult();
dump($found, "found");

return ($found != 0);

I have a naughty bug at validation.
After loading the form, each time I save the form with a correct ID, the $found trace is 1 and the validation is True.
If I set a not existing ID, $found is null and the validation is False.
Until now, everything is OK, BUT if I set again an existing ID, $found = 1 and the validation is always False.
If I refresh the form it works again.
It's like if validation is False, it could never become again True.

Please help, I get crazy since 2 days !!!
Thanks
 
Is that 'dump' actually showing anything? AFAIK, dump() is not a PHP function.

Try var_dump() instead.

I can't replicate this behavior, so I'd probably need to get my hands on your site to fix this.

-- hugh
 
dump($found, "found"); is the way to display a var with J!Dump, without breaking execution.
Var_dump() generates a JSON error and the result could only be seen with Firebug.

I tried this code on a local Uwamp server.
I could try to export my package on my live site.
When I create a package with Lists and forms and I edit it again, I see only Forms added. Is it normal ?
 
Same pb with last Git and creating a new element identical.
Really annoying ! Returns code seems to behave as a trigger....
 
After an error, when I set a good value in ContactsFormID, I have a funny behaviour If refresh my browser with F5 :
  • First F5 : my field ContactsFormID is not validated, with the other fields which are not filled
  • Second F5 : my field is correctly validated and the other fields are initialised (empty)
Any ideas would be greats !
 
thanks but.,....
I don't see an element using a PHP validation rule. Which element (name/id) is it?
 
Sorry Rob, development was not finished on-line.
The field is "ContactsFormID". It's normally hidden, but I unhide it for the test.
You can login or not in frontend.
Allow popups in Firefox to see J!Dump debug displays.
Go in the Contact Form "Nous contacter". You can just play with ContactsFormID and 'Save' button.

For this form ContactsFormID is fixed to 1, but valid values are 1 to 3. You can use them without validation error.
If you change it to 4, you'll get an error, but if you change it now back to 1, 2 or 3, you will still have the error.
The only way to correct this is to type F5 to reload the form.
Thanks for help
 
ok so if you embed a form in an article using the {fabrik....} content plugin then the form automatically submits via Ajax, so there will not be any output to the screen with jdump.

Instead you would need to use firebug in firefox to observe the ajax request and the server response, simply doing :

Code:
echo "here";exit;

for example would show up in the ajax request's response tab.


At a guess I would say that jdump wont output strings when inside an ajax request.

So your code was almost right - except you had inverted the logic for whether the validation failed or not (returning true rather than false)
I've updated your code to:

PHP:
// Check if ID exists
//===================
// Get the form field's value :
//$IDinput = (int) $formModel->_formData['contacts___ContactsFormID'];
$IDinput = (int) '{contacts___ContactsFormID}';
//dump($IDinput, "Form ID");
 
// Get the db object
$db =JFactory::getDbo();
 
// Quote the values for security reasons
$IDinput = $db->quote($IDinput);
 
// Build the query ? Tables names = CASE SENSITIVES
$query = $db->getQuery(true);
$query = "SELECT count(*) FROM contactsparams WHERE ID=" . $IDinput;
$db->setQuery($query);
//dump($query, "Query");
 
// Run the query
$found = (int) $db->LoadResult();
 
return ($found == 0);
 
Sorry Rob, but inverting the return is not the solution (read my 12th topic)
With your correction, it's wrong with 1 to 3 values (which are correct) and OK with wrong values ( > to 3 ).
The validation should be ok when "found = True" ==> return ($found != 0);
But the fundamental problems remains !!!

1) Once you get a wrong value, you're never able to have a right one anymore, unless you press F5.
Something seems to persist in a cache ??? or the Ajax validation doesn't follow the full process ???
Can you try different values for ContactFormID, even if validation is wrong ?

2) A strange behavior is also that when I recall the form from the Joomla Menu :
  • default form content (ContactFormID = 1) are set --> OK
  • if the form was not submitted with a wrong value, there is no validation error message "Some parts of your form have not been correctly filled in" --> OK
  • BUT if I submit a wrong value AND reload the form from the MENU, then the default values are set (OK) but the Error Message REMAINS (NOT OK) :eek:
Are these problems linked ???
Thanks A LOT for help. Regards
 
My suggestion is that you debug this using a standard component link, not a content plugin. Basically, things get kind of funky when doing AJAX from a content plugin, and debugging anything happening via AJAX is a pain in the butt.

When I load the component link directly (with index.php?option=com_fabrik&view=form&formid=4), it tosses a MySQL error, which looks like it's coming from the WHERE clause on your Subject join. So you should probably sort that out first.

Once you have the form loading cleanly, start on the validations. Unpublish all the other validations, and see if you can get your PHP one working as expected.

Let me know if you still have the same problems on a component link.

-- hugh
 
Hi Cheesegrit, thanks for answering :)

My suggestion is that you debug this using a standard component link, not a content plugin.

1) Not sure to understand. Do you mean not using J!Dump ? OK I disabled it.


When I load the component link directly (with index.php?option=com_fabrik&view=form&formid=4), it tosses a MySQL error

2) You are right ! I suppose this URL validates the form with contacts___ContactsFormID not being initialized.
I modified the code back to my initial instructions.
With a call to index.php?option=com_fabrik&view=form&formid=4 it perfectly works when I fill values for ContactsFormID
==> so the problem is not in my code or SQL.

BUT invoking the Menu link --> a Joomla article containing {fabrik view=form id=4 contacts___ContactsFormID=1 show-title=0} I get the same wrong behavior.
Is this call correct ???

If YES, other clues :
  • First click on the Menu 'Nous contacter' : ContactsFormID is set to 1 (OK)
  • Change ContactsFormID to 2. Validate :
    • field is OK
    • Form is KO because of fields not filled.
    • Global Error message is displayed
  • 2nd click on the Menu 'Nous contacter' : ContactsFormID stays to 2 (KO)
    • Form initialisation is not good
    • Global Error message remains on the form
  • 3rd click on the Menu 'Nous contacter' : ContactsFormID is set to 1 (OK)
    • Global Error message dissapears
  • Change ContactsFormID to 4. Validate :
    • field is KO
    • Form is KO because of fields not filled.
    • Global Error message is displayed
  • 4th click on the Menu 'Nous contacter' : ContactsFormID is set to 2 (KO)
    • Form initialisation is not good
    • Global Error message remains on the form
  • 5th click on the Menu 'Nous contacter' : ContactsFormID is set to 1 (OK)
    • Global Error message dissapears
Otherwise what could be wrong with this article call ???
I would really appreciate your help ! When it will be OK, I'll publish this case in the Wiki.
Thanks
 
1) Not sure to understand. Do you mean not using J!Dump ? OK I disabled it.

No, I mean start by setting up a normal J! menu item to your list/form, rather than using the embedded {fabrik ...} content plugin. using the content plugin adds a layer of complexity, and makes things harder to debug.

So what I'm saying is basically one of the first rules of debugging a complex problem, which is to strip as much of the complexity out, and start adding things back one by one.

So ... create a menu item, turn off all your validations, and make sure you can cleanly load and submit the form.

2) You are right ! I suppose this URL validates the form with contacts___ContactsFormID not being initialized.
I modified the code back to my initial instructions.
With a call to index.php?option=com_fabrik&view=form&formid=4 it perfectly works when I fill values for ContactsFormID
==> so the problem is not in my code or SQL.

That's not necessarily true. Can you paste your WHERE filter code here?

-- hugh
 

Members online

No members online now.
Back
Top