开发者

How to make drupal known submitting custom content

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, 开发者_如何学Pythonfor 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜