sha*_*nth 3 php wysiwyg drupal drupal-6
我在自定义drupal6模块中创建了一个自定义表单,表单有一个textarea.我输出的表单是嵌入在php代码中的html,如下所示:
function custom_my_form()
{
$f = '<form name="add_user" action="" method="post">
<label> Name </label>
<p><input type="text" name="name" value="" /></p>
<label>About Yourself</label>
<p><textarea name="desc"></textarea></p>
<input type="submit" name="submit" value="Add">
</form>';
return $f;
}
Run Code Online (Sandbox Code Playgroud)
我已经安装并启用了WYSIWYG模块.我的默认输入格式是"Filtered HTML",我为此输入格式选择了FCK编辑器.
现在我想在此表单中为textarea字段启用WYSIWYG.我怎么能继续这个呢?
小智 9
好吧,你怎么创造表格取决于你,这取决于它是否曾经回来咬你的屁股......
看一下评论模块.我注意到可以为注释选择输入格式,当选择完整/过滤HTML时,WYSIWYG编辑器就会启动.以下是相关代码:
$form['comment_filter']['comment'] = array(
'#type' => 'textarea',
'#title' => t('Comment'),
'#rows' => 15,
'#default_value' => $default,
'#required' => TRUE,
);
if (!isset($edit['format'])) {
$edit['format'] = FILTER_FORMAT_DEFAULT;
}
$form['comment_filter']['format'] = filter_form($edit['format']);
Run Code Online (Sandbox Code Playgroud)
因此,您定义了一个包含两个元素的数组,其中一个是textarea本身,另一个是filter_form生成的格式选择器,这就是全部.
这是来自http://groups.drupal.org/node/104604
对于D7来说,它甚至简单.我们得到了一个名为text_format的新类型.
$form['comment'] = array('#type' => 'text_format',
'#format' => 'full_html',
'#title' => t('Description'),
'#required' => TRUE);
Run Code Online (Sandbox Code Playgroud)