Custom template wrong when displayed back after error

lcollong

FabriKant d'applications web
Hi,

I've a custom form template with a very simple mod in the file "default_group.php" :

PHP:
foreach ($this->elements as $element) :
    $this->element = $element;
    if ((strpos($element->id,'enf_photo') && !JFactory::getSession()->get('dispPhoto', '0' ))) $element->hidden = true;

It works as it should : not displaying the element "enf_photo" if the session var "dispPhoto" is set to false.
But if my form failed to validate, it is displayed back to the user with the unwanted element.

This happens only if I publish a php form plugin onBeforeLoad set to "front-end" and "new form only" (see snapshot). Even if the php does nothing or very few ("echo 'hello';" or "return true;"). As soon as I unpublish the plugin, everything is working fine : the element does not show and if the validation fail, the form is displayed back with the right errors messages and without the "enf_photo" as expected.

It's pretty easy to reproduce. I've also tried to set a specific class rather than use "$element->hidden" but the result is the same, the class does not show up in case the form is displayed back after a failed validation.

The purpose of the plugin is to prevent the form to be displayed if a quota limit is reached. I Have written a function which return true if it's ok or redirect the user to a specific place in case of quota reached.

It has nothing to see with the fact to display or not the "enf_photo" element. But one is disturbing the other.

Any suggestion ?
 

Attachments

  • Capture.PNG
    Capture.PNG
    29 KB · Views: 36
The session variable is part of a group set at login time and remain intact all over the session. These variables are used to store parameters set in DB to avoid to do a select each time we want to change the behavior of a script or a display based on these parameters.
However, even if I set the variable to a constant ( "true" ) where it should always being hidden, the element shows up on the form displayed after the validation failed.
It sounds like applying the "default" template in case of validation failed ?
 
Can you make some obvious change to your custom template, so you can see if it's being used after the validation failure?

-- hugh
 
I've added a <p>apchea</p> html in default_group.php so that it displays "apchea" before each element. The form displayed for a new record shows "apchea" everywhere (snapshots) but after the submit with nothing in the fields (blank form), it displays back the form after validation failed with error messages and no more "apchea". no where.

If I unpublish the php plugin "onBeforeLoad", everything is good : "apchea" everywhere, even after failed validation.
 

Attachments

  • form displayed on new record.PNG
    form displayed on new record.PNG
    4.6 KB · Views: 31
  • Form displayed after validation failed.PNG
    Form displayed after validation failed.PNG
    21.4 KB · Views: 31
I can't replicate this, setting the form template either in the form settings, or the "Form Template" settings of a list menu item, or in the "Template" of a form menu item.

In all cases, after a failed validation, with or without a PHP 'onBeforeLoad' plugin, they correctly load my test template.

Even if I set the layout on the query string, &option=com_fabrik&view=form&formid=25&layout=bootstrap_test, it still shows the correct layout after a failed validation.

-- hugh
 
I'm setting the template at the form level. As far as I've just verified, nothing is done at the menu level.
Strange. Something should be specific to my setup.
If you agree to try it on my dev site, I've filled "mySites" (PS) as well as explanations to reproduce the thing in the "notes" field.
 
After the failed validation it's really loading the bootstrap form template on your site (see "Sources" in browser dev tools).
But I can't replicate this behaviour on my site.

When clicking "Ajouter" it's showing a system message above the form (also above the validation error message after saving):
Erreur
Une erreur dans la configuration de votre ?tablissement est survenue. Contactez le webmaster.

Maybe this is related?
 
Hi Troester,

Thank you for testing. The system message you've seen is "normal" as you probably logged in using the super-user back-office identifiers. Using the front-end ids I gave on the "mySites" record shouldn't show up this message. I've just tested both cases.

The behavior I have is directly related to the form plugin "onBeforeLoad". Even if doing a simple "echo 'hello';". As far as I unpublish it, it works as expected.
 
Hmm,
the php plugin in your form id=1 is onLoad (not onBeforeLoad) and is calling a php file + running code in the code field.
What are you doing in the php file (require_verificationDroits)?
Did you also try to unpublish the autofills?

System message: oops, I didn't understand that it's the frontend login infos (I thought it was a part of the URL)
 
I've unpublished the failing plugin which was calling class/routines in library (it works very well elsewhere and allow to concentrate all the code in one unique place instead of having it spread in each local "scripts" directory).
Now the plugin is just doing an "echo 'hello'"; But still failed on both "onLoad" or "onBeforeLoad".
I've also unpublished the two autofill plugins.
So now, it seems to be a "simple" form with only one php very basic plugin on(Before)Load and a custom template.
The behavior is still the same : the right template is loading at the initial display but after failed validation the "default" one is raising up.
However I succeed in making it working using onBeforeJS (see snapshot). It could be a way to go, as far as I can run my code before the form is actually displayed.
 

Attachments

  • Capture.PNG
    Capture.PNG
    14.6 KB · Views: 32
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top