1 (edited by apmuthu 12/22/2016 04:31:35 am)

Topic: Bug submitting forms in FA 2.3.x when file field not changed

Try this:
Setup => Company Setup => Save

Even though the checkbox "Delete Company Logo" is unchecked and there is no change in the logo file that exists, the changes in other fields do not get saved and the error: The existing image could not be removed arises.

This is due to the fact that the function check_value() only checks if the checkbox element exists in the $_POST and not if it's value is set to 1 - some browsers (versions) and windows OSes tested in FA 2.3.x (test on other combinations and even in FA 2.4.x for corrections like this) need the said function in includes/ui/ui_input.inc:

function check_value($name)
{
    if (!isset($_POST[$name]))
        return 0;
    return 1;
}

to be

function check_value($name)
{
    if (!isset($_POST[$name]) || !$_POST[$name])
        return 0;
    return 1;
}

0 is generally evaluates false and if 1 is the value of a ticked checkbox enforced throughout FA, then a NOT check of 1 can be used.

In fact, a very thorough check to accomodate unlike variable type comparisions would entail:

function check_value($name)
{
    if (!isset($_POST[$name]) || ($_POST[$name]+0) === 0)
        return 0;
    return 1;
}

Re: Bug submitting forms in FA 2.3.x when file field not changed

@joe: Please fix in both versions.

Re: Bug submitting forms in FA 2.3.x when file field not changed

I think this is strange. Not normal behaviour for serious browsers. But I will let Janusz decide what?

/Joe

Re: Bug submitting forms in FA 2.3.x when file field not changed

Fixed in my repo.

Re: Bug submitting forms in FA 2.3.x when file field not changed

Hello again,

I have talked with Janusz, and he agrees with that this is strange. Form sent by browser should not include unset
checkboxes, and in ajax it should be forced by FA javascript code.

Please, apmuthu, check that there are no problems in your environment. Please state your configuration details where the problem arises (browser type/system, php server version etc). I guess this arises on some customized FA installation, maybe due to some conflict with third party javascript?

Janusz is afraid of possible sideeffects in batch invoicing and invoicing from deliveries. Please check if there are sideeffects.

If not, we can apply the patch.

/Joe

6 (edited by apmuthu 12/23/2016 04:22:54 am)

Re: Bug submitting forms in FA 2.3.x when file field not changed

No customisation, no extensions.
Plain vanilla install of FA 2.3.25+ from official GitHub Master.
en_US-demo.sql - CoA with US demo data.

Test Environment:
Server and client (localhost) on WinXPSp3, XAMPP 1.7.3 having:
MySQL Server & Client version: 5.1.41
Apache/2.2.14
PHP Version 5.3.1
Browser FireFox v37.0.2

This change is important as there could be some instances where during some var scope / js / function execution, the value of a POSTed checkbox variable is set to 0 as would obtain when "cleaning" of POST variables occur. In such an instance, mere checking for the existence of the POST variable would be insufficient, it's value must be 1 (for single checkbox value as prevalent in all if not most of FA) or some pre-set value (some have the audacity to make it -1 when not chosen) and at the very least, that, if present, it should be checked if (not) zero.

Since no change is effected on the POSTed checkbox variable by the code using this function, please let me know how batch invoicing / delivery processing would be affected - do they change the value of the POSTed checkbox variable?

Re: Bug submitting forms in FA 2.3.x when file field not changed

Thanks, well it seems to work without sideeffects.

Both stable and unstable repos are updated.

/Joe