Starbow Consulting
Home
Tao's Blog
Contact
Demo Site
Search
Secure Dynamic Forms and Subforms
Ahah Forms Demo Site
SimpleTest tips
Joys of Unit Testing
Excluding Node Types from Search
Ahah Session Slides
Setting up Eclipse PDT and XDebug
A dynamically expanding AJAX/AHAH Drupal form element.
Groking the Form API & Node API
Ahah_forms reloaded
CSS Drop Down Primary Links
AHAH Forms Framework released as a module
Request new password
ajax
Drupal
fapi
security
This article is a follow up to my first tutorial on the subject: A Dynamically Expanding AJAX /AHAH Drupal Form Element . The basic flow of that article is still correct, but two month ago I could not figure out how to do dynamic forms without grabbing what I needed out of $_POST, which removes all the great FAPI security. Now I have figured it out and present the dynamic_subform module in Ahah Forms v1.5 , which provides functions for securely creating and updating dynamic forms and subforms.
Add new comment
Read more
You can try out demos of the examples in the Ahah Forms package (Dynamic Polls, Views and Todo Lists) over at: http://demo.starbowconsulting.com .
testing
Enough ranting about testing, here are some useful tips for enjoying SimpleTest.
Back when I was a java programming I fell in love with test-first development, where you write you tests a little in advance of coding in a feature (or at least in concurrence with). I could babble on about all the benefits the approach brings, but the key to using it is that it has to be quick and easy. Unfortunately, with Drupal it is neither. But testing is possible, and still useful, since I the fragment work I am doing is kinda hairy and needs to be air-tight.
There are two major branches of automated testing; unit or white box vs functional or black box testing.
Ran into an ugly problem this morning. Drupal was indexing non-public nodes and showing their snippets in the search results, basically leaking private information. I am sure there is some clever access control way to deal with this, but I ended up just knocking them out on the theme level. Since I already had a phptemplate_search_item function in my template.php (for aesthetic reasons), it was just a question of adding this as the first line (as per http://drupal.org/node/84955 ):
<?php
Wow, the Summit was quite something. My head is still spinning from all the new info. I think my session went really well. Got some good questions, and feedback. Still need to figure out how to do the dynamic forms thing without opening up a security hole. More on that soon. Until then here are my slides:
Let's start with a review for those who have not already drunk the ahah forms framework kool-aid: Ahah forms is a utility for attaching Ajax-style partial page loading to Drupal forms without having to code any javascript. This is similar to Ruby on Rails' link_to_remote tag or form_remote_tag() function. The method I use to declare the binding is a custom extension to the formAPI.
views
Stepping up to the plate
Back to our story of Ajax vs the Drupal Form API. After modifying poll.module to work with ahah_forms in a couple of hours, I was feeling cocky, and decided to go for the gold ring: Views. I use views a lot and think it is one of the key drupal modules. And it is the perfect target for Ajax, because creating a View can take over a dozen page refreshes. I went in optimistic. If you read my first post on this topic ( http://starbowconsulting.com/blog/tao/dynamically-expanding-ajax-ahah-dr... ) you will remember that the hardest part of the process is getting your dynamic form to work without JavaScript, and views_ui already had that nailed. At the end of my first day's work I thought I was 90% of the way there. At the end of my second day, I knew I was in trouble.
Update: I have just released version 1.3 of ahah_forms, which includes a significantly simplified version of views_ui.module-example. I realized that since I was not able to accomplish my goal of per-section form processing, I can limit most of my changes to the theming functions. Most of the discussion below is still valid.
2 comments
css
Quick digression from Ajax. The was a thread on the developers' list about drop down menus, so I thought I would share my approach. This is an pure CSS solution (The .css is probably too site specific to be generally useful, but I included it as an example).
I am excited to announce the release of the work I have been doing to modify ahah_forms and views_ui to work together. It took weeks longer than I anticipated, and required extending ahah_form.js and tweaking maybe 20% of views_ui, but I am very happy with the result. You can check it out yourself at http://demo.starbowconsulting.com/admin/build/views . The views_ui rewrite is available in the examples directory of ahah_form 1.1 ( http://drupal.org/project/ahah_forms )