DrupalBin
Submit Code
About
Recent Posts
Code
1 hour 50 min
ago
Fix for my user handler
2 hours 12 min
ago
Fix for my user handler
2 hours 16 min
ago
my user handler
4 hours 4 min
ago
more
Tags
CCK
fapi
javascript
jquery
menu
module
Panels
simpletest
template.php
test
theme
views
more tags
User login
Log in using OpenID:
What is OpenID?
Username:
*
Password:
*
Create new account
Request new password
Log in using OpenID
Cancel OpenID login
Home
Fix for AHAH FAPI Callback Helper
View
Download
Fix
This fix will not be saved to the database until you submit.
Summary:
Tags:
Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Source code:
*
// Example usage. This is an AHAH callback function. function mymodule_ahah() { // Update the form and render only the wrapper inside the "Refund Settings" // fieldset. $form_update_callbacks['some_fieldset][important_data_wrapper'] = array( 'callback' => '_mymodule_form_important_data', 'callback arguments' => array($_POST['some_setting'], $_POST['another_setting'], 'and another one'), ); // Possibly more entries for $form_update_callbacks here. $form_element_to_render = 'some_fieldset][important_data_wrapper'; ahah_helper_render($form_update_callbacks, $form_element_to_render); } /** * This will become ahah_helper.module?! */ function ahah_helper_render($form_update_callbacks = array(), $form_element_to_render) { $form_state = array('submitted' => FALSE); $form_build_id = $_POST['form_build_id']; // Add the new element to the stored form. Without adding the element to the // form, Drupal is not aware of this new elements existence and will not // process it. We retrieve the cached form, add the element, and resave. $form = form_get_cache($form_build_id, $form_state); foreach ($form_update_callbacks as $form_element_name => $settings) { $form_element =& ahah_helper_get_form_element($form, $form_element_name); $form_element = call_user_func_array($settings['callback'], $settings['callback arguments']); } form_set_cache($form_build_id, $form, $form_state); // Rebuild the form. $form += array( '#post' => $_POST, '#programmed' => FALSE, ); $form = form_builder($_POST['form_id'], $form, $form_state); drupal_json(array( 'status' => TRUE, 'data' => drupal_render(ahah_helper_get_form_element($form, $form_element_to_render)), )); } function &ahah_helper_get_form_element(&$form, $parents) { // Allow $parents to be either an array of the element's parents or the name // of an element. if (strpos($parents, ']') !== FALSE) { $parents = explode('][', $parents); } // Recursively seek the form element. if (count($parents)) { $parent = array_shift($parents); return ahah_helper_get_form_element(&$form[$parent], $parents); } else { return $form; } }
Syntax highlighting mode:
ActionScript
ColdFusion
Diff
Drupal
Drupal 5
Drupal 6
HTML
Javascript
MySQL
PHP
Python
robots.txt
SQL
Text
Select the syntax highlighting mode to use.