How to add forms in content?
Amarnath - May 1, 2007 - 13:29
Hi,
I am trying to add a form in a story content. This form is used only in this content (so, no need of using CCK or Webform modules). Any help is greatly appreciated.
Hi,
I am trying to add a form in a story content. This form is used only in this content (so, no need of using CCK or Webform modules). Any help is greatly appreciated.
I think you're missing something...
...as I believe that if you are wanting to put a form or something like it into a node, then you are no longer going to be using the "story" content type, and you *will* need to either use CCK, Webform, or another custom module to collect the data for you.
I can't personally see another way to do it, but I could be wrong...
Edit: I guess you could have a form in a block and embed the block in the "content" region, but I still don't know how you'd process the form without one of the above solutions...
How do you add forms (webform for example) to content blocks?
Hi,
I'm new to Drupal. How exactly do you add a form to a block (webform for example) as you described? I can't find a straightforward way to do it. I only see an option of creating a form (whether it's webform or contact page) as a node. I'm able to add blocks of content to this node, but I haven't figured out how to create a webform as a block that I can place anywhere in multiple nodes. I was able to copy the generated HTML from a form I created into a block, then stick it on any page I wanted, and that worked just fine. Of course my block won't get updated if I update the webform (adding new fields, edits, etc.). Is there a way by some sort of reference (or call) within the block to generate a webform (or contact form) I've already created so I can have the form on multiple nodes? I was unable to find this in the Webform instructions (maybe I didn't search hard enough?).
Thanks.
is this wat you are talking about???
<?php
function module_block($op = 'list', $delta = 0, $edit = array())
{
$str_content = 'your stuffs...';
switch ($op) {
case 'view':
if ($delta == 0) {
$str_content .= drupal_get_form('form_in_block');
$arr_block['content'] = $str_content;
return $arr_block;
break;
}
}
}
function form_in_block()
{
$arr_form['name'] = array(
'#title'=>t('Your Name'),
'#type'=>'textfield'
);
$arr_form['submit'] = array(
'#value'=>t('Submit'),
'#type'=>'submit'
);
return $arr_form;
}
?>
Maybe
I don't know. I don't yet understand these hooks. I was hoping it was something simple (like changing a setting for the webform module to process the form in a block instead of a node).
If life were that simple! Anyway, I'll play around with what you sent and see if I can get it to do what I want....Many thanks!
if you are familiar with php
if you are familiar with php stuffs then have a look at this drupal handbook
http://drupal.org/node/508
:)
I believe you can just use this in a php block if you know the form id: http://api.drupal.org/api/function/drupal_get_form/5
Hope this helps.
That works!
The drupal_get_form works great for a single page form (like the Contact page). It gets a little more complicated for the webform module that's expecting the form call from the current node and uses $node->$nid to pick the form, etc. I did find that node_view gets around this problem and does exactly what I wanted, and still posts the form back to the correct node, etc. Though I didn't try it, I assume that you can use node_view to list the contents from any type node within any block (if it works for forms, it should work for anything). And the best part is - it's only one line of code!
Thanks again for all the suggestions.
yeah
I think you're correct in your assumption about node_view, it pretty much just renders a node. So as long as it *is* a node that you're trying to "get out there", I think you're pretty much golden on that.