Jump to content

Delete checkbox in inputfieldImage


thomas
 Share

Recommended Posts

Hello,

I'm trying to build a form for registered users to upload images in the frontend and basically rebuilt an admin page. It all works great, upload, sort, all fields etc except for the "delete image" option.

In the inputfield there's a checkbox to delete with value "1". This never gets checked or is anything but "1". I would like to know, how I can check if "delete" image was clicked?

Can anyone help me?

Thanks,

thomas

Link to comment
Share on other sites

This isn't specific to ProcessWire, but HTML checkbox fields in general. When it comes to seeing if a checkbox is checked, the presence of the field in $_POST means that it was checked. If a checkbox is unchecked, it doesn't show up in the $_POST. Whatever value you assign to a checkbox field doesn't really matter, as that isn't the indicator of whether it was checked or not. Using some non-zero value in your checkbox does make sense though because a statement like this would indicate whether the checkbox was checked or not:

if($input->post->my_checkbox) {
 // checkbox was checked
} else {
 // checkbox was not checked
}
  • Like 1
Link to comment
Share on other sites

Cheers Ryan,

I was trying to build an Ajax Form including image upload using the PW tools and the problem was which inputs to pass to the function. It turned out not woth the hassle though and now I use a regular form. Works great!

  • Like 1
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

×
×
  • Create New...