? Success

User tests: Successful: Unsuccessful:

avatar pjdevries
pjdevries
27 Jan 2015

In case of a validation failure, the (error) message is not displayed. This is due to the fact that an Exception object is pushed onto the JForm::errors array, while this must be a text string apparently.

Line 1212
array_push($this->errors, $valid);

has now been changed into
array_push($this->errors, $valid->getMessage());

Which seems to solve the problem.

Test instructions:

This is for testing that a custom rule error message is not shown by Joomla in a component configuration.

Test instructions:

  • Download test component from com_formtest
  • Install com_formtest
  • Open com_formtest in administrator
  • Click on Options
  • Fill in the letters ab
  • Click on Save
  • The problem: no error message is shown
  • Apply patch
  • Fill in the letters ab
  • Click on Save
  • Problem solved: an error message is shown
  • Fill in the number 2
  • Click on Save
  • Success message is shown
avatar pjdevries pjdevries - open - 27 Jan 2015
avatar jissues-bot jissues-bot - change - 27 Jan 2015
Labels Added: ?
avatar jissues-bot jissues-bot - change - 27 Jan 2015
Labels Added: ?
avatar zero-24
zero-24 - comment - 27 Jan 2015

@pjdevries can you explain how we can reproduce that? what kind of validation error you mean?

BTW the unit test fails:

There was 1 failure:
1) JFormTest::testGetErrors
Line:831 The errors should be exception objects.
Failed asserting that false is true.
/home/travis/build/joomla/joomla-cms/tests/unit/suites/libraries/joomla/form/JFormTest.php:832

So maybe the exception object is correct?

avatar pjdevries
pjdevries - comment - 27 Jan 2015

Hi whoever you are,

Thanx for the feed back. It's my first pull request and I didn't read
the instruction very well (understatement). I'm already in contact with
Roland Dalmulder to improve it.

Either this unit test is incorrect or another one somewhere higher up. I
tested my solution locally. When the Exception object is pushed onto the
error array, as si the case now, the message is not displayed. When I
push the actual text message onto the array, the message is displayed
perfectly. This raises the question which code and which unit test needs
to be adjusted.

I'll try to figure this out with Roland.

Regards,

Pieter-Jan de Vries

On 27-1-2015 18:08, zero-24 wrote:

@pjdevries https://github.com/pjdevries can you explain how we can
reproduce that? what kind of validation error you mean?

BTW the unit test fails:

|There was 1 failure:
1) JFormTest::testGetErrors
Line:831 The errors should be exception objects.
Failed asserting that false is true.
/home/travis/build/joomla/joomla-cms/tests/unit/suites/libraries/joomla/form/JFormTest.php:832
|

So maybe the exception object is correct?


Reply to this email directly or view it on GitHub
#5894 (comment).

avatar zero-24
zero-24 - comment - 27 Jan 2015

Thanks @pjdevries

Thanx for the feed back. It's my first pull request and I didn't read
the instruction very well (understatement).

No Problem You are very welcome here!

I'll try to figure this out with Roland.

ok Thanks :smile: Let me know if you figured it out. So I can try to test it. Thanks!

avatar pjdevries
pjdevries - comment - 27 Jan 2015

I'll keep you in the loop. Good to know there's already one tester :)

Regards,

Pieter-Jan

On 27-1-2015 18:30, zero-24 wrote:

Thanks @pjdevries https://github.com/pjdevries

Thanx for the feed back. It's my first pull request and I didn't read
the instruction very well (understatement).

No Problem You are very welcome here!

I'll try to figure this out with Roland.

ok Thanks :smile: Let me know if you figured it out. So I can try to
test it. Thanks!


Reply to this email directly or view it on GitHub
#5894 (comment).

avatar wilsonge
wilsonge - comment - 27 Jan 2015

So this is one of those kinds of bugs which are horrible. There's no 'good' fix. The unit tests except an Exception (which personally I think is correct). But JModelForm expects a string (joys). I think JModelForm actually has the bug where it's looking for a string. But I might be wrong :/

avatar mbabker
mbabker - comment - 27 Jan 2015

I have run into this issue previously in framework applications I've built. While this change makes sense and make that errors array consistent, it is a potential backward compatibility breaker, demonstrated by the unit tests failing. For now, this should be fixed in JModelForm when the form is being validated so that the code checks for an Exception instance and re-factoring the error handling code in JForm to either consistently return strings or exceptions be done for 4.0.

avatar joomdonation
joomdonation - comment - 29 Jan 2015

I looked at JForm validate method in the past and saw that Exception is an expected value / behavior. When we call validate method of JForm and validation failure, all elements in $this->errors are Exception objects.

In Joomla core, these errors are displayed in JControllerForm in this block of code (which can be found at https://github.com/joomla/joomla-cms/blob/staging/libraries/legacy/controller/form.php#L706)

for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++)
{
    if ($errors[$i] instanceof Exception)
    {
        $app->enqueueMessage($errors[$i]->getMessage(), 'warning');
    }
    else
    {
        $app->enqueueMessage($errors[$i], 'warning');
    }
}


Maybe in your case, the error is not displayed because you use different code / ways for displaying errors?
avatar Fedik
Fedik - comment - 29 Jan 2015

oh it will be huge b/c issue :smile:

avatar Hackwar
Hackwar - comment - 3 Feb 2015

So since this breaks backwards compatibility and should be solved differently, should this one be closed?

avatar joomdonation
joomdonation - comment - 3 Feb 2015

I think this PR is invalid, so it should be closed

avatar pjdevries
pjdevries - comment - 3 Feb 2015

Roland and me intend to pick this one up later this month. With all the cool feed back, I'm sure we will come up with the proper solution next time.

Thank you all.

avatar pjdevries pjdevries - change - 11 Jun 2015
Title
Update form.php
Proper handling of form validation messages
avatar pjdevries
pjdevries - comment - 11 Jun 2015

Roland, who did most of the work to be honest, and I finally implemented a proper solution. Roland also created a rudimentary component to be used for testing purposes. A download link for the test component can be found in the test instructions.

avatar zero-24 zero-24 - change - 11 Jun 2015
Category Administration Components
avatar zero-24 zero-24 - change - 11 Jun 2015
Easy No Yes
avatar kathastaden kathastaden - test_item - 25 Aug 2015 - Tested successfully
avatar kathastaden
kathastaden - comment - 25 Aug 2015

Just tested this Patch with Joomla version: 3.4.4-dev development.

Used the test-description from above and the test component: com_formtest
Everything worked like described!


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/5894.

avatar zero-24 zero-24 - test_item - 25 Aug 2015 - Tested successfully
avatar zero-24 zero-24 - change - 25 Aug 2015
Status Pending Ready to Commit
avatar zero-24
zero-24 - comment - 25 Aug 2015

Looks and works great and nothing is broken ;) --> RTC Thanks.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/5894.

avatar joomla-cms-bot joomla-cms-bot - change - 25 Aug 2015
Labels Added: ?
avatar zero-24 zero-24 - change - 25 Aug 2015
Milestone Added:
avatar pjdevries
pjdevries - comment - 25 Aug 2015

Thanks for your time!

avatar Kubik-Rubik Kubik-Rubik - change - 3 Sep 2015
Milestone Added:
avatar Kubik-Rubik Kubik-Rubik - change - 3 Sep 2015
Milestone Removed:
avatar rdeutz rdeutz - reference | 2900de4 - 1 Oct 15
avatar rdeutz rdeutz - merge - 1 Oct 2015
avatar rdeutz rdeutz - close - 1 Oct 2015
avatar rdeutz rdeutz - change - 1 Oct 2015
Status Ready to Commit Closed
Closed_Date 0000-00-00 00:00:00 2015-10-01 18:08:48
Closed_By rdeutz
avatar rdeutz rdeutz - close - 1 Oct 2015
avatar joomla-cms-bot joomla-cms-bot - close - 1 Oct 2015
avatar joomla-cms-bot joomla-cms-bot - change - 1 Oct 2015
Labels Removed: ?
avatar zero-24 zero-24 - change - 28 Oct 2015
Milestone
avatar zero-24 zero-24 - change - 28 Oct 2015
Milestone Added:
avatar zero-24 zero-24 - change - 28 Oct 2015
Milestone Added:
avatar zero-24 zero-24 - change - 28 Oct 2015
Milestone

Add a Comment

Login with GitHub to post a comment