Pregunta

I'm trying to get a Drupal 7 Field working programmatically and it's not going well. I simply want to create a module that creates a Field with a checkbox. The module is working, the field is working but the checkbox will not save.

Here is my hook_field_widget_form:

<?php
function add_to_basket_field_widget_form(&$form,&$form_state,$field,$instance,$langcode,$items,$delta,$element)
{
    $element += array(
        '#type' => 'checkbox',
        '#title' => t('Add to basket?'),
        '#default_value' => isset($item['add_to_basket_cfield']) ? $item['add_to_basket_cfield'] : '',
    );
    return $element;
}
?>

When I run it as part of my module it works but wont save a tick or no tick. I've tried everything I can think of to get this working but after 3 days with nothing to show it's time to ask the experts

Thanks

¿Fue útil?

Solución

hope this helpful for you

$form[$group]['ex_account'] = array(
    '#type' => 'checkbox',
    '#title' => t('your title'),
    '#default_value' => variable_get('ex_account', 1) ? 1 : 0,
    '#description' => t('desc.'),
  );
return system_settings_form($form); or return $form;

Otros consejos

Try the example module and look at the field_example portion. Make sure that your custom field has a schema described in the .install file so that the value you are putting in your custom field actually saves.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top