Jon Posted April 27, 2016 Share Posted April 27, 2016 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 More sharing options...
SiNNuT Posted April 28, 2016 Share Posted April 28, 2016 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 3 Link to comment Share on other sites More sharing options...
Jon Posted April 28, 2016 Author Share Posted April 28, 2016 Thanks Sinnut, I already have that tick but empty and "0" are being treat the same any other ideas? Cheers Jon Link to comment Share on other sites More sharing options...
tpr Posted April 29, 2016 Share Posted April 29, 2016 You can try == "". But just use var_dump($page->cruise_spaces), or echo(gettype($page->cruise_spaces)) to see what it really is. 2 Link to comment Share on other sites More sharing options...
horst Posted April 29, 2016 Share Posted April 29, 2016 is_int() & is_null() if(is_null($page->cruise_spaces)) if(!is_int($page->cruise_spaces)) if($page->cruise_spaces === NULL) if($page->cruise_spaces !== NULL) 4 Link to comment Share on other sites More sharing options...
Jon Posted April 29, 2016 Author Share Posted April 29, 2016 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now