Cannot pass zero through ajax #379

Closed
opened 2019-02-26 08:33:38 +00:00 by oriolun · 2 comments
oriolun commented 2019-02-26 08:33:38 +00:00 (Migrated from github.com)

Steps to reproduce the issue

Make new ajax input in "PHP Ajax Methods *" section.
Send zero value in javascript code.

Expected result

success

Actual result

false

System information (as much as possible)

  • OS Name & Version:
  • MySql Version:
  • Apache Version:
  • PHP Version: 7.2
  • Joomla Version: latest
  • JCB Version: latest
  • Browser:

Additional comments

JCB uses this construction to check the data:

if($idValue && $subjectValue && $valueValue)
{
   $result = $this->getModel('ajax')->saveCat($idValue, $subjectValue, $valueValue);
}

It will always return false if we pass a zero value in any variable.
The only way to solve it, i believe, is sending an array, but why not checking empty($variable) instead of just $variable?

### Steps to reproduce the issue Make new ajax input in "PHP Ajax Methods *" section. Send zero value in javascript code. ### Expected result success ### Actual result false ### System information (as much as possible) - OS Name & Version: - MySql Version: - Apache Version: - PHP Version: 7.2 - Joomla Version: latest - JCB Version: latest - Browser: ### Additional comments JCB uses this construction to check the data: ``` if($idValue && $subjectValue && $valueValue) { $result = $this->getModel('ajax')->saveCat($idValue, $subjectValue, $valueValue); } ``` It will always return false if we pass a zero value in any variable. The only way to solve it, i believe, is sending an array, but why not checking `empty($variable)` instead of just `$variable`?

Seeing that is an issue, we normally catch the zero values in the model directly from the JFactory::getApplication()->input opject. This means that if you need to work with a zero value, do not add that value as part of the controller catch and sanitation, but get it in the model (your code) saveCat.

I can see the need to change this, so I will add a tag to enhance JCB to not sanitize (if so desired by the developer) the values, but leave it to the model. Let me see how easy that would be, and get back to you. Until then the above is a great work around.

Seeing that is an issue, we normally catch the zero values in the model directly from the `JFactory::getApplication()->input` opject. This means that if you need to work with a zero value, do not add that value as part of the controller catch and sanitation, but get it in the model (your code) `saveCat`. I can see the need to change this, so I will add a tag to enhance JCB to not sanitize (if so desired by the developer) the values, but leave it to the model. Let me see how easy that would be, and get back to you. Until then the above is a great work around.

You can now pass zero and even null values to the model by this new checkbox called Allow null & zero values:
image

You can now pass zero and even null values to the model by this new checkbox called `Allow null & zero values`: ![image](https://user-images.githubusercontent.com/5607939/56855696-d778e980-694b-11e9-889f-e31a5678259d.png)
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#379
No description provided.