When I submit my webform it only saves the YoName text field that precedes the Table Element. All the (5) checkboxes that I've selected aren't stored.

Am I trying to do something impossible? Hopefully, I'm missing something obvious. I think it would be cool to do school lunch menus with Webform/Table Element.

(attached: view; webform and submission).

Using a basic D7 install - Webform / Webform Table Elements. No errors/notices of any kind in reports/log.

Any ideas on what I can do to try and make this work? I found http://drupal.org/node/1259022 - but am assuming this is perhaps different - as the current 7.x-1.6 is >6mo newer than then the 7.x-1.x-dev in that post - and I'm seeing something like that.

Thanks,

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

KarinG’s picture

Title: I can't get it to save data that's within the Table Element » Does not save data for Checkboxes within Table Element
FileSize
16.1 KB
16.47 KB

I've gotten a little further with this. It's the checkboxes that are causing the troubles. So I've edited the title a bit.

1. When I put radio buttons within a Table Element: image attached: wradiobuttons.png
I can submit the form and all is well - all data are stored.

2. NEXT, in Option settings for desert checking the box Multiple (values will let users select multiple items in this list) - so the form now looks like:
with Checkboxes: image attached: wcheckboxes.png
Upon submit produces these warnings (below) and does NOT store the data [sorry didn't see warnings before - had switched them off in preparation for a demo]. All I see in my submission Email (or Results) is the selections for the Size (which are still radio buttons) and a heading Desert -> but NO values for it.

    Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1572 of /var/www/drupal/git-7/includes/bootstrap.inc).
    Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1572 of /var/www/drupal/git-7/includes/bootstrap.inc).
    Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1572 of /var/www/drupal/git-7/includes/bootstrap.inc).
    Warning: strlen() expects parameter 1 to be string, array given in _webform_display_table_element() (line 303 of /var/www/vhosts/secure.cfis.com/modules/webform_table_element/webform_table_element.module).
    Warning: strlen() expects parameter 1 to be string, array given in _webform_display_table_element() (line 303 of /var/www/vhosts/secure.cfis.com/modules/webform_table_element/webform_table_element.module).
    Warning: strlen() expects parameter 1 to be string, array given in _webform_display_table_element() (line 303 of /var/www/vhosts/secure.cfis.com/modules/webform_table_element/webform_table_element.module).
    Warning: strip_tags() expects parameter 1 to be string, array given in _webform_display_table_element() (line 323 of /var/www/vhosts/secure.cfis.com/modules/webform_table_element/webform_table_element.module).
    Warning: strip_tags() expects parameter 1 to be string, array given in _webform_display_table_element() (line 323 of /var/www/vhosts/secure.cfis.com/modules/webform_table_element/webform_table_element.module).
    Warning: strip_tags() expects parameter 1 to be string, array given in _webform_display_table_element() (line 323 of /var/www/vhosts/secure.cfis.com/modules/webform_table_element/webform_table_element.module).
    Warning: Illegal offset type in _webform_display_table_element() (line 276 of /var/www/vhosts/secure.cfis.com/modules/webform_table_element/webform_table_element.module).
    Warning: Illegal offset type in _webform_display_table_element() (line 276 of /var/www/vhosts/secure.cfis.com/modules/webform_table_element/webform_table_element.module).
    Warning: Illegal offset type in _webform_display_table_element() (line 276 of /var/www/vhosts/secure.cfis.com/modules/webform_table_element/webform_table_element.module).
KarinG’s picture

I worked on this some more and found that when I clone the "Size" element from #1 -> (gave it a new field key) -> an dragged it outside the Table Element -> data for that element outside of the Table Element are stored as expected.

I also just looked at Webform Commerce -> as presumably these school lunches are going to be paid for. Similar thing: if I have the SKU element outside of the Table Element all is well. If I place the SKU element within a Table Element - I get notices/warnings and the data that are collected there are not stored.

Staring to perhaps look like some elements can be placed within a Table Element - and some can not (yet)? I'm willing to put some time into this. But if you think I'm on the wrong track (and checkboxes/SKUs should work as is) then please let me know.

Thanks,

KarinG’s picture

Category: support » bug
ownage’s picture

Your webform screenshots are confusing me. Here's what I did to try to replicate this:

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1_creating_table_element.png

1_creating_table_element.png

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2_creating_checkbox_1.png

2_creating_checkbox_1.png

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3_creating_checkbox_2.png

3_creating_checkbox_2.png

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4_test1.png

4_test1.png

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
5_test2.png

5_test2.png

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The behavior in the results wasn't what I had expected, (as it doesn't show what people have checked), but because we only have one option per row, we are still able to see what is checked by seeing the row label.

This should probably be fixed to show what people have checked.

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

KarinG: Your issue is different than mine-- I went about creating my select list differently. I actually don't know how you made your list if your screenshots are in sync with each other. Perhaps that is why you are getting warnings? (I didn't get any the way I made mine). Your issue actually looks like what I encountered (blank nothingness - in my case - caused by the field keys being identical). I would double check your field keys on everything & every option to make sure each are unique.

Milado’s picture

Version: 7.x-1.6 » 7.x-1.x-dev
Priority: Normal » Major

I've the same problem. I discovered Webform Table Element this morning and I need to make a grid where you can choose multiples values per lines, so I need to use checkbox instead of radio buttons.
First of all I also had the " Warning: htmlspecialchars() expects parameter 1 to be string ..." error.

I did exactly the same things as you ownage.
I realize that I don't have the error anymore if I don't check the "Multiple : Multiple values will let users select multiple items in this list." option, BUT submission is still not saved! (and I think you checked it because there is no way to have a chekbox button without it).

Please help !

KarinG’s picture

Version: 7.x-1.x-dev » 7.x-1.6
Priority: Major » Normal
FileSize
58.89 KB
27.27 KB

Thanks for this!

I tried to reproduce your Select Test. Figuring that would be a good start to figure out why checkbox data isn't stored.

Details:
1. grabbed the latest dev for Table Element (7.x-1.6+2-dev) [based on your other post - you're working w/ the -dev, corrrect?]
2. disabled "Options Element", "Multicolumn checkboxes radios" and "Select (or Other)" modules to ensure absolutely nothing is running interference
3. checked version for Webform:7.x-3.18

Screenshots:
1. collage: my select_test.png: view / webform and the three components of the webform
The only difference I can see - is that I have a "Multiple" option -> I've marked it with a red square. If I leave it unchecked -> I get a radio button. If I check it I get a checkbox instead of a radio button. What version of Webform are you using?
2. results: select_test_results: before and after I hit Submit. I'm getting a notice and it's not saving any result (staying on the view screen). The field keys are different so the notice isn't the result of that [wish it was - then mystery solved].

This is starting to drive me bananas - but then I enjoy a good puzzle. Did I miss anything recreating your Select Test?

Milado’s picture

I made a mistake in the previous post I'm on the 7.x-1.6 version (but it's strange to have the same bug as you during the same period...)

ownage’s picture

1. grabbed the latest dev for Table Element (7.x-1.6+2-dev) [based on your other post - you're working w/ the -dev, corrrect?]

Attiks changed my issue to a Dev. project: http://drupal.org/node/1662708#comment-6168542
So when I tested mine, I was using the recommended release (7.x-1.6) and still am.

Thanks for the attachments, this really is the only way for the developers to pinpoint problems so I'm sure they will appreciate our inputs.

KarinG’s picture

Ok, I ended up with plan B - should have likely been plan A from the start - since all I'm trying to do is to make a table with checkboxes. I've ditched Webform Table Element - it's just having too much difficulty to store data - even for very simple webform nodes.

plan B involved taking the webform-form.tpl.php that is supplied with Webform module and copying that into the theme you're using to render the webform page. If you're using a system default theme - then first create a proper sub theme - then apply that as your default theme to render the webform. Rename the tpl file to webform-form-[nid].tpl.php if you only want to style one of your webforms. You must clear your caches before Drupal will know that you now have a custom tpl to render your webform.

In the tpl you can place all elements of $form anywhere you want. I've put them in table th td and tr to create my grid of productfield (Commerce Webform) checkboxes. Many themes already have default colouring of rows, so simply apply classes (e.g. in a seven-based sub theme: class="odd" and class="even") to quickly make a very nice looking table.

Devel and Theme Developer module in particular are very handy modules to inspect the $form - so that you can figure out what to put where in your table.

attiks’s picture

Version: 7.x-1.6 » 7.x-1.x-dev
Status: Active » Needs review
FileSize
3.16 KB

@all:
Thanks for the extensive debugging, this makes it easier for us to debug.

I just committed a possible fix to the latest dev version, this needs testing!!!

i1659546-10.png

#9: this is a good work-around, we used to do this in the past as well, but the problem is that an end user cannot do this, hence this module.

Milado’s picture

Version: 7.x-1.x-dev » 7.x-1.6
Status: Needs review » Active

Hi KarinG, could you please show us what do you make into your webform-form.tpl.php ?
I'm also looking for another way to display a table with checkboxes , but in this file you only have a call to drupal_render and drupal_render_children so I don't understand how you modify the render.

attiks’s picture

Status: Active » Needs review
Milado’s picture

FileSize
10.44 KB
32.12 KB

@attiks : thank you for working on this, I've download the dev version and your commit to try to fix it. But it doesn't seem to work for me :

Screen1
Screen 2

Warning : htmlspecialchars() expects parameter 1 to be string, array given dans check_plain() (ligne 1572 dans /home/users/a.frin/www/DrupalVierge/includes/bootstrap.inc).
Warning : htmlspecialchars() expects parameter 1 to be string, array given dans check_plain() (ligne 1572 dans /home/users/a.frin/www/DrupalVierge/includes/bootstrap.inc).

attiks’s picture

Version: 7.x-1.6 » 7.x-1.x-dev

Pushed a new fix for the warnings, can you post a screenshot from the results

Milado’s picture

Status: Needs review » Active
FileSize
176.6 KB

Thanks but it's still not working.
Here is a result screen, do not pay attention to the first and second errors they are here since the installation of this DrupalTest, it's a small configuration problem.

screen

attiks’s picture

Can you add the following into bootstrap.inc, replacing the original function

function check_plain($text) {
if (is_array($text)) {
  dpm($text);
  dpm(debug_backtrace());
}
  return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
}
attiks’s picture

Warnings should be solved, keep in mind that you need at least another component on the form (maybe a hidden one) otherwise the form will not submit.

KarinG’s picture

FileSize
62.67 KB

@Milado - I'd be happy to.

$form is an array that contains everything there is to know about the form.

Make sure you disable the rendering of $form['submitted'] as they can only be rendered once
<!-- <?php //print drupal_render($form['submitted']); ?>-->

Then underneath that - start with something like:
<?php print_r($form['submitted']); ?>

Reload your webform node and you'll start to get a good idea of what's all in the array that you can grab and theme.

I'll share what I have at the moment. It's producing (attached).

<!--  // Print out the main part of the form.-->
<!--  // Feel free to break this up and move the pieces within the array.-->
<!--  <?php //print drupal_render($form['submitted']); ?>-->

<?php $allformdata = $form; ?>

<!-- need to figure out how many rows we have -->

<?php
  $submitted = $form['submitted'];

  print_r('<table>');

  print_r('<tr>');
  print_r('<th>&nbsp;</th>');
  print_r('<th>Half-order</th>');
  print_r('<th>Full-order</th>');
  print_r('<th>Milk</th>');
  print_r('<th>Soy Milk</th>');
  print_r('<th>Mixed Fruit</th>');
  print_r('</tr>');

  $i=0;

  foreach ( $submitted as $key => $submitted_entries ) {
     if (isset($submitted[$key]['#webform_component']['type']) == 'productfield'){

       if ($i % 2){
         $rowclass = 'odd';
       } else {
         $rowclass = 'even';
       }

       //print_r($submitted[$key]['#webform_component']['name']);
       print_r('<tr class=' . $rowclass . '>');

       $day = $submitted[$key]['#webform_component']['name'];
       print_r('<td><b>');print_r($day);print_r('</b></td>');

       $all_product_ids = $submitted[$key]['#webform_component']['extra']['items'];
       foreach ( $all_product_ids as $product => $products ) {
         print_r('<td>');
         print_r('<b>');
         print_r($all_product_ids[$product]['sku']);
         print_r('</b>');
         print drupal_render($form['submitted'][$key][0][$product]);
         print_r('</td>');
       }
       print_r('</tr>');
     }
    $i=$i+1;
  }
  print_r('</table>');
?>

<!-- // Always print out the entire $form. This renders the remaining pieces of the -->
<!-- // form that haven't yet been rendered above. -->
<?php print drupal_render_children($form); ?>
Milado’s picture

FileSize
191.25 KB
163.98 KB
136.47 KB

@KarinG > Well thank you understand know, you still use drupal_render but you use it many times, so you can make the form looks like an array, good job ;)

@attiks > Sory to disappoint you but I still have the warning!
1

BUT data are saved (with another component, sorry I didn't knew that).
I've now the same view as ownage :
2
So the display of boxes cheked is not working but with dpm we can see that data are corectly stored :
3

Like I said before I installed the -dev version this morning and then aply your commits, is that the correct process to do? (I'm new to the drupal community so I may have made a mistake)

KarinG’s picture

@Milado - you're welcome. Let me know if you need more details. Many more .tpl.php files come w/ Webform module so you can do the same with the other screens, like View Submission. For someone new to Drupal you're doing just fine.

@attiks - thanks for paying attention to this issue now - you had 3 people reporting they can't save checkbox data :-) It will be indeed be very useful for many to be able to do this from the Webform GUI. I hope you can get this to work properly.

attiks’s picture

The easiest is to use git: git clone --recursive --branch 7.x-1.x http://git.drupal.org/project/webform_table_element.git so you can do git pull to update to the latest version.

Display for switched rows isn't working, I'll have a look at it.

Milado’s picture

FileSize
64.42 KB

You're right there is no warning if I disabled the switch functionality! Hope you can fix it.
I've found another small bug (I should maybe make another post, but I prefer to warn you so you may be aware of it) :
If you create a checkboxe with multiples elements (so a table of checkboxes with more than one boxe on each case), only the first element checked will be displayed on the "view" page!
And there is the screen :
2nd bug

attiks’s picture

FileSize
6.3 KB
11.2 KB

Output should be fixed for both options: regular and row/cols switched

In the case of 'row/cols switched' the data needs to be resaved otherwise it can show up in the wrong order!

i1659546-23.png

i1659546-23b.png

attiks’s picture

FileSize
6.41 KB

second screenshot should be

i1659546-24.png

Milado’s picture

FileSize
194.91 KB
25.79 KB
210.31 KB

Thank you for this work! So yes I see corectly the result table for both options... but there are many notices/warnings for both cases!

For the test made at #22
22

And for another webform made with column/row switched I've another kind of warnings :
1-1
-----------------
1-2

I'll have a look concerning Git but for now I'm still wondering if I should be on the recommended or development release ?

attiks’s picture

If you want to switch rows and columns you better use the dev version, I'll work on the warnings later today.

Does this mean that everything is working now, except for the warnings?

Milado’s picture

Ok so I'll stay on this version. Yes it does!

attiks’s picture

Warnings fixed.

Milado’s picture

Status: Active » Closed (fixed)

Problem solved, it looks like everything is working fine.
Once again thank you attiks for all the job done!

KarinG’s picture

Status: Closed (fixed) » Needs review

@attiks - would you like me to test this w/ productfield checkboxes?

attiks’s picture

@KarinG feel free to test, the more the better, but just so you know I created a 1.7 version a minute ago.

KarinG’s picture

Ok, will do.

KarinG’s picture

FileSize
26.92 KB

Sorry - still not working at all with a table of productfield checkboxes. The form doesn't even get submitted.

I can recreate the table I posted in #18: lunchtpl.png.

webformtable.png

Getting plenty of Notices (30x2) - so 4 Notices per checkbox

Notice: Undefined index: #title in _table_element_expand_rows() (line 119 of /Applications/MAMP/htdocs/Local/commerce/sites/all/modules/webform_table_element/webform_table_element.module).
Notice: Undefined index: #title in _table_element_expand_rows() (line 131 of /Applications/MAMP/htdocs/Local/commerce/sites/all/modules/webform_table_element/webform_table_element.module).

Critical is that absolutely nothing happens upon form submission (Add to cart) . So there are no troubles rendering the view table node - but that's all it really does here. I'll need to continue to theme my own table using the tpl.php files.

attiks’s picture

you need to add at least one regular component, it might be a hidden one, otherwise the post isn't working, the reason is that webform does not know about our post variables.

the example above is using regular checkboxes or some other component?

KarinG’s picture

FileSize
5.75 KB

Yes - of course - I knew about the POST - ok, I've added a Name field - I can now hit Add to cart to get to a next screen - but I can't get it to store info for the checkboxes (and it doesn't get into the shopping cart). I'm using productfield checkboxes - by Webform Commerce module. So no - they are not ordinary checkboxes. Still if you can render the view node properly - there should be a way to store the data that are entered - regardless of what field originally created the element, not?

tableelements.png

attiks’s picture

Title: Does not save data for Checkboxes within Table Element » Does not save data for Productfield Checkboxes within Table Element
Category: bug » feature
Status: Needs review » Active

module: commerce_webform

The problem is that the submit function isn't called, since webform has no knowledge about the post data and cannot call the standard submit function as defined by commerce_webform. The same goes for the displaying of the values in the results.

Turning this into a feature request, to support this we need custom handling inside:

hazmoid’s picture

Ok so I built a safety form based on radio buttons and text fields. I had each row of the webform Table defined as a separate item and added the radio buttons and textfield and was getting a form that looked like what I wanted. Only problem is that it did not output the the radio button setting, and it also would not output the text in the textfield. This was annoying since I spent an afternoon getting the form to look right :( I was getting an undefined index error for every field in each of the tables as well. I made a point of changing the machine field name in each table because they had the same titles for each of the radio and textfields.
At this point I have wiped all the tables out and am looking for an option that will give me the output I need. I originally started out with the idea of making each field a conditional display of the textfield but this did not give me the nice table layout.

Getting very frustrated now.

attiks’s picture

Sad to hear you're running into problems, but without any concrete information it will be hard to help you. A screenshot of your webform components as well as the rendered webform might help.

If you're using 'productfield checkboxes - by Webform Commerce module', then this isn't going to work right now, feel free to write a patch or find funding to implement this.

travist’s picture

Most of these issues should be fixed in the 2.x version of the module. Be warned, though, there is currently not an upgrade path to 2.x, so only upgrade if your site is a new implementation.