heldercervantes Posted May 30, 2017 Share Posted May 30, 2017 Hi guys, I'm kinda stuck here. How do you set an InputfieldCheckbox to unchecked via API? I've tried setting it to false, 0, '' and nothing seems to work. Shouldn't be relevant, but I'm using this to control whether a user's password was auto or manually generated. So when a password recovery is requested, I'm doing: $user->setOutputFormatting(false); $user->pass = $randomGeneratedPassword; $user->passwordSet = false; $user->save(); passwordSet is the name of my field. This is generating and saving the random password correctly, but that checkbox stays checked. 1 Link to comment Share on other sites More sharing options...
fbg13 Posted May 30, 2017 Share Posted May 30, 2017 I just tried it and it works both with 0/1 and true/false. Have you tried the code as is without any conditions? 1 Link to comment Share on other sites More sharing options...
heldercervantes Posted May 30, 2017 Author Share Posted May 30, 2017 I'm positive it's going through this code. The password is being changed and also after this it sends an email to the user with the new password and that's working too. I'm thinking it may be some weirdness related to the page being a user. If I don't get there, I'll just use another kind of field. Link to comment Share on other sites More sharing options...
fbg13 Posted May 30, 2017 Share Posted May 30, 2017 The field I tested was also on the user template. Check if you mistyped the field name when you created it. Link to comment Share on other sites More sharing options...
heldercervantes Posted May 30, 2017 Author Share Posted May 30, 2017 Once again I make an ass of myself For starters, I was testing the frontend part on the server and looking at the CMS locally. It was all downhill from there. This to say of course setting it to false unchecks the box. Sorry for wasting your time. Now excuse me while I go reflect on life. 3 1 Link to comment Share on other sites More sharing options...
SwimToWin Posted April 17, 2022 Share Posted April 17, 2022 When working with Checkboxes ("Type: Page Reference - Input field type: Checkboxes - with Page field value type: Multiple pages PageArray" fields, that is), this works: $rs = $pages->find('template=foo, parent=/bar/'); foreach ($rs as $p) { $p->of(false); $p->myCheckboxes = null; // Unset all values first $p->myCheckboxes = 'baz'; // Then set the active checkbox with name (or, use Page ID) $p->save(); } 1 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