tags:

views:

326

answers:

2

I have mastered creating custom data types and adding fields with CCK. Then I created and deployed a custom module with _form and _validate and _submit hooks.

I am not happy with the amount of massaging required with css and permissions to make the form usable, but this is not my question.

Now I would like to create a more sophisticated form with jquery to submit form and add content to page. I am at a bit of loss as how to get to this next level. I have been looking at tpl.php files, but this looks very rigid and more complicated as well. Can any provide a model or tutorial or point me in right direction.

A: 

Will the ajax module do what you want?

CSS massaging is not usually needed, unless you're doing unusual custom stuff, and in that case it's not really massaging, it's adding custom CSS for your custom stuff. Might be a good idea to post a question on that topic, or do some digging on drupal.org. In other words you might be Doing It Wrong :)

intuited
thanks for your prompt reply. I am just getting a bit frustrated with this program. !! Here is a more focused question: with a custom form module (ei with _form, _validate, _submit), how can I drop in a DIV or SPAN tag programatically that jQuery can use? or am I approaching this all wrong?
bert
intuited
Yes googling helps a lot. That tutorial looks like the best that I've seen. Maybe I'm paranoid but I'm worried about piling up too many modules. Will it ever be possible to upgrade if authors don't keep up with new versions? Also my dev box is getting very slow when caching is turned off.
bert
Although module compatibility is guaranteed within major versions (eg 6.16 to 6.17), upgrading major versions (eg 6.x to 7.x) can be treacherous. Modules that are widely used pretty much always get re-released for new major versions, either by their author or by somebody who's taken over maintenance. The more obscure ones are a bit hit and miss; often they're replaced by new modules that incorporate that functionality or by that functionality being rolled into Drupal core, which is what seems to be happening with that ajax module.
intuited
It might end up being quicker for you to keep caching turned on and just clear the cache when you need to test something. The command line tool `drush` (http://drupal.org/project/drush) is great for this, and many other things. It can help to speed things up a lot.
intuited
I just read the agaric tutorial. It basically covers what I am already doing in the code. I create a form function, a $form array, input and submit controls, then add css and js. What I want to know is how to add div and span's from my module.
bert
You're probably going to want to use hook_form_alter. There's some detail on that here: http://www.lullabot.com/articles/modifying-forms-drupal-5-and-6 Also reading the Forms API documentation if so that might be easier than coding it in a theme_your_form_name_form function from within your module. Also what @googletorp mentions is useful too.
intuited
I started g0ing through the agaric tutorial listed above and realized that hook_form_alter only alters the form that I created 20 lines earlier. hook_form_alter seems great to change existing forms but does not give me anything that I already don't have. Creating a .tpl.php seems like an option but the syntax looks a bit wonky. I will have to give it a try. I just put my day's efforts here http://tinyurl.com/yekbpxk . Would appreciate your feedback.
bert
+1  A: 

If you want to customize how Drupal outputs your form, you have a few options.

  1. You can add some markup with the #prefix and #suffix attributes. You can also create form elements that is just markup if you need it.
  2. If you need more control over the form, you can create your own theme function for the form, or override the existing one with the #theme form attribute. In your theme function you have free hands to create more or less any markup you like. You might need to override some of the default theme functions that is used to render the form items.
googletorp
#prefix and #suffix and suffix work like a charm!
bert