Jump to content

[ANSWERED] Using unset_fields with unset_add_fields and unset_edit_fields

  • Please log in to reply
1 reply to this topic

#1 HumbleMonk



  • Members
  • PipPip
  • 25 posts

Posted 19 April 2012 - 04:04 AM

There is a bug/unexpected behaviour when using unset_fields at the same time as using unset_add_fields or unset_edit_fields.

For instance, I want the 'name' field to not be in any fields and I want the 'age' field to be in the edit field but not the add field:


The actual result of this code is that 'name' is in both add and edit forms and age is not in the add forms (in other words, the first line of code is ignored).

If we switch the order the reverse happens:


'age' will be in the add form but 'name' will not be in any form (again, the first line of code is being ignored).

The workaround is to just not use unset_fields with unset_add_fields and unset_edit_fields and instead use unset_add_fields and unset_edit_fields to explicitly remove a field from both.

However, to me this is unexpected behaviour and the above code should actually work.

#2 web-johnny


    grocery CRUD Author

  • Administrators
  • 1,144 posts
  • LocationLondon

Posted 19 April 2012 - 06:07 AM

This is the expected behaviour actually. I know that I still haven't documented so it's ok to not understand how it works.

The way it works it is really easy so let me explain


it is just a shortcut to:


nothing more, nothing more complicated than that. So when you have


it is like you have:

and grocery CRUD just add the last one, don't add more. So you can NOT do something like this:


it will just unset the "lastname".

However you can work with arrays, so in your case you can simply do:

$unset_fields = array('name');
$unset_fields[] = "age";

Posted Image

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users