Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: default to false for CheckableTypes with null values #339

Open
tegola opened this issue Mar 24, 2017 · 2 comments
Open

Proposal: default to false for CheckableTypes with null values #339

tegola opened this issue Mar 24, 2017 · 2 comments

Comments

@tegola
Copy link

tegola commented Mar 24, 2017

Since unchecked checkboxes are not posted (as per html spec), and since the Form class has the handy feature of returning null values when a field is not present in the POST, I find myself doing this in every form:

public function alterFieldValues(array &$values)
{
	$checkboxNames = ['name1', 'name2', 'name3'];

	foreach ($checkboxNames as $name) {
		if ($values[$name] == null) {
			$values[$name] = false;
		}
	}
}

Basically, I'm converting all known checkbox fields that are null to false. Having the Form class do this automatically would be great.

What do you think?

@kristijanhusak
Copy link
Owner

@tegola looks like a good idea, but i would like to make it optional, just because of the BC. Will you create a PR to add that feature?

@tegola
Copy link
Author

tegola commented Jun 27, 2017

Sorry for the delay.
I don't think I have the knowledge to do it, I couldn't find the time to see how the package works internally.

Where should I put the option and the necessary code to alter the form values?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants