Note that there are some explanatory texts on larger screens.

plurals
  1. POdrupal field widget not saving submitted data
    primarykey
    data
    text
    <p>I'm trying to create a custom widget but when I submit, Drupal doesn't seem to save any data. When using <code>hook_field_attach_submit()</code> to display what data I've pasted, it is listed as null. </p> <p>Strangely, if i change the <code>#type</code> to be a single textfield instead of a fieldset it will save only the first character of the string that has been entered.</p> <p>This seems like a validation issue, but I'm not sure how to hook into it or to debug the problem. Where can I go from here?</p> <pre><code>&lt;?php function guide_field_widget_info(){ dpm("guide_field_widget_info"); return array( 'guide_text_textfield' =&gt; array( 'label' =&gt; t('test Text field'), 'field types' =&gt; array('text'), 'settings' =&gt; array('size' =&gt; 60), 'behaviors' =&gt; array( 'multiple values' =&gt; FIELD_BEHAVIOR_CUSTOM, 'default value' =&gt; FIELD_BEHAVIOR_DEFAULT, ), ) ); } function guide_field_widget_form(&amp;$form, &amp;$form_state, $field, $instance, $langcode, $items, $delta, $element) { $field_name = $instance['field_name']; $required = $element['#required']; $item =&amp; $items[$delta]; $element += array( '#type' =&gt; 'fieldset', '#title' =&gt; t('helloooooooo'), ); $required = $element['#required']; $item =&amp; $items[$delta]; $element['nametest'] = array( '#title' =&gt; t('Name'), '#type' =&gt; 'textfield', '#required' =&gt; $required, // use #default_value to prepopulate the element // with the current saved value '#default_value' =&gt; isset($item['nametest']) ? $item['nametest'] : '', ); $element['checkme'] = array( '#title' =&gt; t('Check this box or dont'), '#type' =&gt; 'checkbox', '#default_value' =&gt; isset($item['checkme']) ? $item['checkme'] : '', ); //When changing the above code to have a single field, $value is no longer null but will display the first character of the string. I've pasted the code I used to test beloe /* $element+= array( '#title' =&gt; t('Name'), '#type' =&gt; 'textfield', '#default_value' =&gt; isset($item['nametest']) ? $item['nametest'] : '', ); */ return $element; } //hooking this here is required given that after submit, the value is a multidimensional array, whereas the expected value of text is, well, text :-) function guide_field_attach_submit($entity_type, $entity, $form, &amp;$form_state){ dpm($form,"guide_field_attach_submit data"); //shows $form[field_test_field][und][0] [value] as being null } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload