code snipits

Radios + AHAH + Table = Fun

Hooray! I'm wrong! See update at the bottom of the post.

Theming forms in Drupal is a challenge. Getting checkboxes and radios buttons into a table with other data can whip a small band of squirrels into a bird feeder frenzy. Add AHAH into the mix, and well, you've got grounds for a stiff drink and a nap. While I'm not sure I have done it "right" I'm posting some of my code here to give other people some grounds to fall into different pitfalls rather than mine.

Radios + AHAH + Table = Fun

Theming forms in Drupal is a challenge. Getting checkboxes and radios buttons into a table with other data can whip a small band of squirrels into a bird feeder frenzy. Add AHAH into the mix, and well, you've got grounds for a stiff drink and a nap. While I'm not sure I have done it "right" I'm posting some of my code here to give other people some grounds to fall into different pitfalls rather than mine.

So what I wanted was a table which had checkboxes for a series of files. Each checkbox would fire an AHAH request to populate data into another table. Seems easy enough- there are lots of examples of how to theme checkboxes into tables in Drupal.

Radios + AHAH + Table = Fun

Theming forms in Drupal is a challenge. Getting checkboxes and radios buttons into a table with other data can whip a small band of squirrels into a bird feeder frenzy. Add AHAH into the mix, and well, you've got grounds for a stiff drink and a nap. While I'm not sure I have done it "right" I'm posting some of my code here to give other people some grounds to fall into different pitfalls rather than mine.

So what I wanted was a table which had checkboxes for a series of files. Each checkbox would fire an AHAH request to populate data into another table. Seems easy enough- there are lots of examples of how to theme checkboxes into tables in Drupal.

Auto Link TinyMCE Images

Unless I am just completely missing it, the support for auto linking images back to their source for TinyMCE is just not intuitive. Since I generally upload a larger image than what I can use on a page, I want to have the image on the page link back to the larger one. Having to create a link after you have placed an image does not really make sense to me. So an obvious hack enters the room. Since we know that at least in Drupal, imaes that are in content areas of a post are likely to have been uploaded by a user, we can make a general assumption that these are likely to want to lnk to the original. jQuery of course gives us just enough power to be dangerous:

Overflow: auto + ajax + Safari + hack = joy

The problem:
Using the ajaxLoader which I wrote to do easier content replacement with Drupal and jQuery, I was running into a very strange issue with Safari. FF and IE would load fresh content into a div that I had defined with the overflow: auto property and display scroll bars to see all of the content, but in Safari, the content was just cut off. The css for this seems as though it should be straight forward:


/* AJAX content replacement */

fflAjaxContent{

margin: 5px 0px 10px 0px;

AJAX Poll App

I wrote a quick ajax poll application that uses mysql to store poll questions and data and cookies to prevent multiple votes. Quick, but should be useful to somebody.

Download file

xAJAX file uploader

I'm doing a quick project to some text manipulation for Jason via some ajax. He wanted to have a way to have a file uploaded and then manipulated. Not wanting to break my ajax pages, I tried to figure out how to do this with the limitations that javascript and file handling has. I think I have a pretty workable solution. I posted this over at the xAJAX fourms here.

Dealing with Spam Injection

I use lots of mail scripts in php. Unfortunately, if you allow users to enter their email address, suddenly you are vulnerable to spam injection. For an explanation as to why, see this really good article.

There's a simple way to fix this for your mail scripts.

Just using some quick replacement on your strings, you can do the following:


$email = $_POST['email'];
$strip_chars = array("\r","\n");
$email = str_replace($strip_chars, "", $email);

Custom Link Display for Drupal

If you want to do link display in drupal, but not rely on the link processing that drupal does automatically, it's not to hard to setup some code to display a link list that handles things slightly differently.

I wanted to do a display where the last item of the list was displayed differently. Turns out it's really simple. I borrowed the idea from http://www.heydon.com.au/?q=node/661

<

blockquote class="terminal">


foreach ($primary_links as $singlelink) {
  print "
  • "; if ($singlelink == end($primary_links)) {
  • Template Toolkit Javascript Image Navigator

    I built a little javascript/TT image navigator that allows you to load images from a directory, display them as thumbnails and zoom them as you click on them. This is nice for doing things like selecting images for various web applications. It relies on some javascript, but to my knowledge it's totally cross browser compliant.

    Here's the javascript you'll need:
    [code]

    // this is used to toggle a specific div's display status
    function div_toggle (thisdiv) {
    var the_div = document.getElementById( thisdiv );
    if (the_div.style.display == 'block') {
    the_div.style.display='none'; }

    Pages