Jump to content

0 and Null in Integer field


Jon
 Share

Recommended Posts

Hello All,

I have a integer field for a number of spaces. In ready PHP. Iam looking to check the spaces field and if its NULL (empty) set the value and if it not empty just leave it. However when the spaces get to 0 this is setting my field back to the default number of spaces. Ive tried isset() empty() but seem to be getting the same result. Any ideas how to solve this?

The code I am using is below. 

    if($page->vessels->id == 1039 && !$page->cruise_spaces) {
        $page->cruise_spaces = 12;
        $page->cruise_single = 2;
}

Cheers

Jon

Link to comment
Share on other sites

If you look in the settings for your particular integer field (cruise_spaces) there should be an option to set how '0' values are treated. If you take the option that 0 and blank are not the same i think it will solve your problem.

Setup->Fields->Edit Field: cruise_spaces

Under the 'Details' tab

  • Like 3
Link to comment
Share on other sites

I've changed my code to use ===NULL I can now save 0 but if cruise_spaces is NULL the fields arent getting set. The full code I am using is below if that help. Ive use !==NULL to test the section of code that sets the spaces and that works fine

$this->pages->addHookAfter('saveReady', null, 'cruiseSpaces');

function cruiseSpaces($event) {

$page = $event->arguments[0];

if($page->cruise_spaces === NULL) {
    if($page->vessels->id == 1039) {
        $page->cruise_spaces = 12;
        $page->cruise_single = 2;
    }else if ($page->vessels->id == 1041 || $page->vessels->id == 1042)
    {
         $page->cruise_spaces = 11;
         $page->cruise_single = 2;

    }}

}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...