I needed the following patch to prepopulate a checkbox as checked (for a webform checkbox, using edit[submitted][field_name][true]=true).

Comments

rightclick’s picture

Thank you for the patch
Worked also with node checkbox with a small modification
edit[field_designers][und][10]=true

if ($form['#type'] == 'checkbox' && $requestslice >= 1){
  $form['#checked'] = 1;
}
ashrafabed’s picture

StatusFileSize
new519 bytes

Just attaching an updated patch since I had to use it for my site.

rightclick’s picture

Category: bug » task

There is an issue with urls like this "edit[field_designers][und][10]=true". Overlay redirect URL try to create 9 array indexes with empty values.

We changed the code to:

if ($form['#type'] == 'checkboxes'){
  $form[$requestslice]['#checked'] = true;
}

and use urls like :

edit[field_designers][und]=10
mototribe’s picture

the first patch worked for me. Thank you!!!

jpstrikesback’s picture

Title: Prepopulate checkbox [#checked] » Prepopulate checkbox & checkboxes [#checked] with TRUE or FALSE
StatusFileSize
new654 bytes

Here is a version that works for checkbox & checkboxes widgets and allows one to check & uncheck fields by either setting a value or not:

Checkboxes:

checked : edit[field_interest][und][1]=1

not checked : edit[field_interest][und][3]=0

Checkbox:

checked : edit[field_thing][und]=1

not checked : edit[field_thing][und]=0

eddie_c’s picture

Thanks a lot for the patch jpstrikesback. It didn't quite apply properly for me so I've re-rolled it using branch 7.x-2.x.

eddie_c’s picture

Issue summary: View changes

Edit field name

Renee S’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

The patch reroll by @eddie_c in #6 works great for me.

kiwad’s picture

+1 for #6

rollingnet’s picture

I can confirm #6 works great
Please review and submit it to dev

joachim’s picture

Works great for me, for taxonomy term ref fields too.

  • Commit f5c6600 on 7.x-2.x by jbrauer:
    Issue #1386072 by eddie_c, jpstrikesback, ashabed: Better handle...
jbrauer’s picture

Status: Reviewed & tested by the community » Fixed

Committed, Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

zorax’s picture

Do you have a solution for drupal 8 - 9 ?Thanks