AHAH Resources
- Download the Example module and experiment with the AHAH Examples.
- The Drupal.org handbook page on Drupal 6 AHAH
- Forms API Documentation, AHAH section
- AHAH Helper module, which does some of the work for you on the callback
Note that this is currently maintained in the Examples project so the code here may not be the latest.
In this example we use a select control to determine how many checkboxes are generated.
(Experience this one at http://d6.drupalexamples.info/examples/ahah_example/autocheckboxes.)
<?php
/<strong>
* @file
* A Self-configure a form based on a select control
* Add the number of checkboxes specified in the select
*/
function ahah_demo_autocheckboxes(&$form_state) {
$default = !empty($form_state['values']['howmany']) ? $form_state['values']['howmany'] : 1;
$form['howmany'] = array(
'#title' => t('How many checkboxes do you want?'),
'#type' => 'select',
'#options' => array(1=>1, 2=>2, 3=>3, 4=>4),
'#default_value' => $default,
'#ahah' => array(
'path' => 'ahah_demo/autocheckboxes/callback',
'wrapper' => 'checkboxes',
'effect' => 'fade',
),
);
$form['checkboxes'] = array(
'#title' => t("Generated Checkboxes"),
'#prefix' => '<div id="checkboxes">',
'#suffix' => '</div>',
'#type' => 'fieldset',
'#description' => t('This is where we get automatically generated checkboxes'),
);
$num_checkboxes = !empty($form_state['values']['howmany']) ? $form_state['values']['howmany'] : 1;
for ($i=1; $i<=$num_checkboxes; $i++) {
$form['checkboxes']["checkbox$i"] = array(
'#type' => 'checkbox',
'#title' => "Checkbox $i",
);
}
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Click Me'),
);
return $form;
}
/</strong>
* Callback for autocheckboxes. Process the form with the number of checkboxes
* we want to provide
*/
function ahah_demo_autocheckboxes_callback() {
$form_state = array('storage' => NULL, 'submitted' => FALSE);
$form_build_id = $_POST['form_build_id'];
$form = form_get_cache($form_build_id, $form_state);
$args = $form['#parameters'];
$form_id = array_shift($args);
$form_state['post'] = $form['#post'] = $_POST;
$form['#programmed'] = $form['#redirect'] = FALSE;
// HACK: Select values changing never get recognized
unset ($form['howmany']['#value']);
drupal_process_form($form_id, $form, $form_state);
$form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
$checkboxes = $form['checkboxes'];
$output = drupal_render($checkboxes);
// Final rendering callback.
print drupal_json(array('status' => TRUE, 'data' => $output));
exit();
}
?>
Submitted by rfay on
I proposed 3 sessions for Drupalcon Paris at the beginning of September, and just hope I can get one in. There's one on Debugging Drupal, one on Ctools/Panels Plugins, and one on Upgrade-proofing your site. Looks like they're all kind of low in the running, but they've all gotten some votes. Surprisingly the one that I thought would be the lowest ranked is the highest - the "Upgrade-Proof Your Site: Best Practices to Avoid Major Version Upgrade Headaches".
If you're going and you like any of these topics, thanks for your VOTE!
Submitted by rfay on
I spent much of today updating the Simpletest Tutorial on Drupal.org. The tutorial has been revamped, with much more info, and there are downloadable sample modules for both Drupal 6 and Drupal 7.
Simpletest is making a big difference in the stability of Drupal, but we're going to have lots of work to do to get improved test coverage for the release of D7. Hopefully this will help in some small way.
Submitted by rfay on
I finally got the Ctools Plugin Example module and documentation updated and submitted. Merlin of Chaos seems happy with the idea, so I'm hoping it can make it as a module distributed with Ctools, which is a fundamental part of Panels.
One of the nicest things about Panels (now provided by Ctools) is the ability to write relatively simple pieces that extend it. But it's been kind of hard to figure out the magic. Hopefully this module + documentation will help out.
Update 19 August: It's been committed, so it will be in the upcoming full release of CTools.
Submitted by rfay on
I just got an email that my Debugging Drupal session for Drupalcon Paris is a go! I had already been told that none of my sessions went, so it was quite a surprise. Should be a good session. And the CTools Plugin session, which didn't go, will be done as a BOF add-on to the big session by MerlinOfChaos on CTools in general.
Debugging Drupal is not that much different from any kind of debugging or problem-solving, and the topics we'll cover are the same regardless of your level of Drupal or PHP expertise.
Here we'll cover three topics:
Although you may be here for #3, the first two will probably have more of an impact on your success, so we're going to spend some good time on them first.
Before beginning a debugging effort, turn on your brain. Ask yourself some questions:
Almost any piece of software or any debugging problem is too large to understand all at once. So you have to figure out ways to divide the problem. If you can divide the problem in half a couple of times you'll rapidly have a more understandable problem.
There are many ways to divide up a problem:
Many of the items in this tutorial may require you to learn a new technique or two. Commit to breaking out of the stalemate. Don't let skills that you haven't yet mastered keep you from really resolving a problem. Learn them, even if it means investing in them in the midst of a crisis. Never let a mysterious site remain mysterious. Commit the resources you need to shine the light on your Drupal installation. It's worth it - it will pay off in no time.
If you invest in your infrastructure ahead of time, life will be so much easier. If you know how to load and dump the database quickly and how to get a file copy of a production database in moments, and you know how to revert to an earlier version of the code, life will be so much better. Learn how to do these things, whether you do "code" or not: