views:

86

answers:

1

Hi,
I know this is not a drupal forum but, as I’m not getting any response there, I decided to give it a shot here.

I’m creating a web site that accepts custom content from users. So, for that matter, this site has a form and a custom module. Instead of using admin theme, this form is placed inside custom template which is created to have a uniform look with the rest of the pages. As a result, creating form elements through hook_form is out of question. Here’s where my problems lie. As this form uses custom theme, I’m not sure as to what can I do to make drupal know that user is submitting new content data when the form is submitted?

  • Would I need to use same query string that of content submission page of admin page like - ?q=node/add/page for action attribute of the html form? (OR)

  • the only way is to map the url to my custom function and invoke some sort of hook inside of it?

Thanks

+3  A: 

You can literally create any markup you want for your form, all you need to do is use the #theme attribute when you define the form. With it you can set theme functions for the form itself and any of the elements.

It is a very bad idea, not to use Drupal's FAPI. It solves so many problems for you, and not using it would be the first step to take if you want to open up a security hole in your site. A development framework like Drupal is not of much worth, if you don't use it's APIs.

Edit:
First thing to do, is to go to Drupal's FAPI reference. You can learn almost everything about the FAPI there.

You could use a template if you want, is just basic Drupal theming, but I would advise against it. It would be a lot more maintainable if you created theming functions for all the elements and used that instead, you could just loop through all the elements and render them like Drupal does, instead of having to edit a template file each you need to change the form. It might be a but more work now, but there's a reward to that work: cleaner and more maintainable code.

In code it looks something like this:

$form['item'] = array(
    ...
    '#theme' => 'theme_function',
);

Doing this, the element will be rendered using the "theme_function". You can see an example of such a theme function for textfields.

googletorp
Is it possible to use template instead of function?Because my form is quite complicated in a way that it has 40+ elements inside and I probably need to add more in future. I'd be glad if you could give me a pointer to the reference you've suggested cuz the one I found in drupal site doesn't tell me much about #theme.
Andrew