How do I trigger a Drupal-Function with Javascript/jQuery? -
i have checkbox different values. when user change checkbox trigger drupal-function field_attach_update http://api.drupal.org/api/drupal/modules!field!field.attach.inc/function/field_attach_update/7
i know how check checkbox-change jquery how can trigger drupal-function then?
you'll want check out form api ajax options. think you'll want define ajax['callback'] function calls field_attach_update.
<?php function my_form_func($form, $form_state) { $my_checkbox_val = isset($form_state['values']['my_checkbox']) ? $form_state['values']['my_checkbox'] : null; $form['my_checkbox'] = array( '#type' => 'checkbox', '#title' => t('check me'), '#default_value' => $my_checkbox_val, '#return_value' => $nid, // assuming working node, entity '#ajax' => array( 'callback' => 'my_form_field_update_func', 'event' => 'click', ), ); return $form; } function my_form_field_update_func($form, $form_state) { if (isset($form_state['values']['my_checkbox'])) { $node = node_load($form_state['values']['my_checkbox']); field_attach_update('node', $node); } return $form['my_checkbox']; } ?>
Comments
Post a Comment