Hello guys
I badly, need your help!
I have multiple textarea fields on a node form now each field needs a input format selection form and each field can have a different input format selection.
Now, I have been following Pro Drupal Development for it. It gives following code example:
function joke_form($node) {
// Get metadata for this node type
// (we use it for labeling title and body fields).
// We defined this in joke_node_info().
$type = node_get_types('type', $node);
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#weight' => -5
);
$form['body_filter']['body'] = array(
'#type' => 'textarea',
'#title' => check_plain($type->body_label),
'#default_value' => $node->body,
'#rows' => 7,
'#required' => TRUE
);
$form['body_filter']['filter'] = filter_form($node->format);
$form['punchline']['field'] = array(
'#type' => 'textarea',
'#title' => t('Punchline'),
'#required' => TRUE,
'#default_value' => $node->punchline,
);
$form['punchline']['filter'] = filter_form($node->punchline_format);
return $form;
}
But when I do print_r($node) in hook_insert filter for punchline does not show up there. Below is the out put from print_r($node) in hook_insert:
stdClass Object
(
[nid] =>
[vid] =>
[uid] => 1
[created] => 1195113010
[type] => joke
[changed] =>
[title] => JOKE TITLE
[body] => JOKE BODY
[format] => 3
[field] => JOKE PUNCLINE
[log] =>
[name] => admin
[date] =>
[status] => 1
[promote] => 1
[sticky] => 0
[revision] => 0
[preview] => Preview
[op] => Submit
[submit] => Submit
[form_token] => cd54ca373b3915f3d12b8af4684ae28c
[form_id] => joke_node_form
[comment] => 2
[menu] => Array
(
[title] =>
[description] =>
[pid] => 1
[path] =>
[weight] => 0
[mid] => 0
[type] => 86
)
)
The punchline field shows up as 'field' and filter for punchline does not show up. I checked out filter_form() function and looks like I need to pass a value for $parent argument to it. But I am not sure how to do it.
PS: I added a field punchline_format in the joke table.
I would be great if anybody could suggest a correct method of doing this.
Thanks
Comments
An update:
Looks like this works and I am able to store punchline and punchline_format in joke table. But filters are not working.
How's it coming?
I'm working on the same issue (using the same example from Pro Drupal Development). Did you finally get it to work? You said the filters weren't working, but I don't think filter_form is responsible for actually running the text through the filter ... maybe you have to manually do it in hook_view() ... but I haven't figured this out myself, seems like the authors left this bit out. Anyone care to comment?
Hi, I just stumbled upon the
Hi,
I just stumbled upon the same, and found the solution in the handbooks somewhere.
You are almost right: in hook_view() you should run your text through the check_markup() function (http://api.drupal.org/api/function/check_markup/5) for it to work.
So if you take the Pro Drupal Development 'punchline' example, you should change the following in theme_joke_punchline() function (see page 96 of the book)
to
This does the trick!
I am really really sorry for
I am really really sorry for leaving out this post. Actually, after I faced this problem, next day I had to take care of other project. So this thing completely went out of my mind.
Getting in touch with other devs , I found they solved they problem very next day by using the same method as shown by svendecabooter(from pro drupal development only).