Php 如何在网站正文中插入Drupal表单?
我正在编辑一个页面,我希望页面中有一个drupal表单 我知道如何制作drupal表单,但是当我编辑“body”块并插入一些php时,它会显示在模板之外 是否有一些参数可以像这样插入Php 如何在网站正文中插入Drupal表单?,php,drupal,drupal-forms,Php,Drupal,Drupal Forms,我正在编辑一个页面,我希望页面中有一个drupal表单 我知道如何制作drupal表单,但是当我编辑“body”块并插入一些php时,它会显示在模板之外 是否有一些参数可以像这样插入 $output = drupal_get_form(my_form, 'node 1') 还是什么 提前谢谢 $output=drupal_get_form(联系_form,'node 1') drupal_渲染($output) 功能联系人表单($form\u state){ $form['firstna
$output = drupal_get_form(my_form, 'node 1')
还是什么
提前谢谢
$output=drupal_get_form(联系_form,'node 1')
drupal_渲染($output)
功能联系人表单($form\u state){
$form['firstname']=数组(
“#键入”=>“文本字段”,
“#标题”=>t(“通知标题”),
“#大小”=>30,
“#必需”=>正确
$form['lastname']=数组(
“#键入”=>“文本字段”,
“#标题”=>t(“通知标题”),
“#大小”=>30,
“#必需”=>正确
$form['email_from']=数组(
“#键入”=>“文本字段”,
“#标题”=>t(“通知标题”),
“#大小”=>30,
“#必需”=>正确
$form['telephone']=数组(
“#键入”=>“文本字段”,
“#标题”=>t(“通知标题”),
“#说明”=>t(“可选”),
“#大小”=>30,
“#必需”=>正确
$form['comments']=数组(
“#键入”=>“文本区域”,
“#标题”=>t(“通知标题”),
“#大小”=>30,
“#必需”=>正确
$form['submit']=数组(
“#键入”=>“提交”,
“#value”=>t('Submit'),
);
返回$表格;
};
功能联系人\u表单\u验证($form,$form\u状态){
$error_message=“”;
$string_exp=“/^[A-Za-z.-]+$/”;
$email_exp='/^[A-Za-z0-9.[U%-]+@[A-Za-z0-9.-]+\[A-Za-z]{2,4}$/';
如果(!preg_match($email_exp,$email_from)){
$error_message.=“您输入的电子邮件地址似乎无效。
”;
}
如果(!preg_匹配($string_exp,$first_name)){
$error_message.='您输入的名字似乎无效。
;
}
如果(!preg_匹配($string_exp,$last_name)){
$error_message.=“您输入的姓氏似乎无效。
”;
}
if(strlen($comments)<2){
$error_message.=“您输入的注释似乎无效。
”;
}
如果(strlen($error_message)>0){
死亡($error_message);
}
};
功能联系人表单提交($form,$form\u state){
//构建电子邮件的正文
$body=“First Name:”.clean_string($First_Name)。“
。”“Last Name:”.clean_string($Last_Name)。“
。”“Email:”.clean_string($Email_from)。“
。”“电话:”.clean_string($Telephone)。“
”注释:“.clean_string($Comments);
//发送
$message=数组(
'至'=>'XXXXXXXXXXXXXXXX',
“主题”=>$email\u主题,
“body”=>$body,
'headers'=>数组(
'发件人'=>$email\u发件人,
'至'=>'XXXXXXXXXXXXXX',
“主题”=>$email\u主题,
);
drupal\u mail\u send($message);
};
我添加了全部代码,因为我得到的答案对我不起作用。假设您使用Webform创建了此表单 如果您只想在页面末尾显示表单,请转到表单高级设置并单击“可用为块” 然后在块部分,将其添加到“主内容部分”并配置块。
在“在特定页面上显示块”下,写下希望其显示的页面
以编程方式打印块
$block = module_invoke('webform', 'block_view', 'client-block-1'); //add your block id
print render($block['content']);
你需要使用
drupal_渲染($output)
这是一篇很好的文章,在
我刚刚用下面的代码创建了一个模块,您的数组没有正确关闭
function contact_test_form($form) {
$form['firstname'] = array(
'#type' => 'textfield',
'#title' => t('Title of Notice'),
'#size' => 30,
'#required' => TRUE,
);
$form['lastname'] = array(
'#type' => 'textfield',
'#title' => t('Title of Notice'),
'#size' => 30,
'#required' => TRUE,);
$form['email_from'] = array(
'#type' => 'textfield',
'#title' => t('Title of Notice'),
'#size' => 30,
'#required' => TRUE,);
$form['telephone'] = array(
'#type' => 'textfield',
'#title' => t('Title of Notice'),
'#description' => t("Optional"),
'#size' => 30,
'#required' => TRUE,);
$form['comments'] = array(
'#type' => 'textarea',
'#title' => t('Title of Notice'),
'#size' => 30,
'#required' => TRUE,);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
};
function contact_form_validate($form, $form_state) {
$error_message = "";
$string_exp = "/^[A-Za-z .'-]+$/";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
};
function contact_form_submit($form, $form_state) {
// build the body of the email
$body = "First Name: ".clean_string($first_name)."<br />"."Last Name: ".clean_string($last_name)."<br />"."Email: ".clean_string($email_from)."<br />"."Telephone: ".clean_string($telephone)."<br />"."Comments: ".clean_string($comments);
//send
$message = array(
'to' => 'xxxxxxxxxxxxxxxxxx',
'subject' => $email_subject,
'body' => $body,
'headers' => array(
'From' => $email_from,
'To' => 'xxxxxxxxxxxxxxxxx',
'Subject' => $email_subject,
),);
drupal_mail_send($message);
};
function contact\u test\u form($form){
$form['firstname']=数组(
“#键入”=>“文本字段”,
“#标题”=>t(“通知标题”),
“#大小”=>30,
“#必需”=>正确,
);
$form['lastname']=数组(
“#键入”=>“文本字段”,
“#标题”=>t(“通知标题”),
“#大小”=>30,
“#必需”=>TRUE,);
$form['email_from']=数组(
“#键入”=>“文本字段”,
“#标题”=>t(“通知标题”),
“#大小”=>30,
“#必需”=>TRUE,);
$form['telephone']=数组(
“#键入”=>“文本字段”,
“#标题”=>t(“通知标题”),
“#说明”=>t(“可选”),
“#大小”=>30,
“#必需”=>TRUE,);
$form['comments']=数组(
“#键入”=>“文本区域”,
“#标题”=>t(“通知标题”),
“#大小”=>30,
“#必需”=>TRUE,);
$form['submit']=数组(
“#键入”=>“提交”,
“#value”=>t('Submit'),
);
返回$表格;
};
功能联系人\u表单\u验证($form,$form\u状态){
$error_message=“”;
$string_exp=“/^[A-Za-z.-]+$/”;
$email_exp='/^[A-Za-z0-9.[U%-]+@[A-Za-z0-9.-]+\[A-Za-z]{2,4}$/';
如果(!preg_match($email_exp,$email_from)){
$error_message.=“您输入的电子邮件地址似乎无效。
”;
}
如果(!preg_匹配($string_exp,$first_name)){
$error_message.='您输入的名字似乎无效。
;
}
如果(!preg_匹配($string_exp,$last_name)){
$error_message.=“您输入的姓氏似乎无效。
”;
}
if(strlen($comments)<2){
$error_message.=“您输入的注释似乎无效。
”;
}
如果(strlen($error_message)>0){
死亡($error_message);
}
};
功能联系人表单提交($form,$form\u state){
//构建电子邮件的正文
$body=“First Name:”.clean_string($First_Name)。“
。”“Last Name:”.clean_string($Last_Name)。“
。”“Email:”.clean_string($Email_from)。“
。”“电话:”.clean_string($Telephone)。“
”注释:“.clean_string($Comments);
//发送
$message=数组(
'至'=>'XXXXXXXXXXXXXXXX',
“主题”=>$email\u主题,
“body”=>$body,
'headers'=>数组(
'发件人'=>$email\u发件人,
function contact_test_form($form) {
$form['firstname'] = array(
'#type' => 'textfield',
'#title' => t('Title of Notice'),
'#size' => 30,
'#required' => TRUE,
);
$form['lastname'] = array(
'#type' => 'textfield',
'#title' => t('Title of Notice'),
'#size' => 30,
'#required' => TRUE,);
$form['email_from'] = array(
'#type' => 'textfield',
'#title' => t('Title of Notice'),
'#size' => 30,
'#required' => TRUE,);
$form['telephone'] = array(
'#type' => 'textfield',
'#title' => t('Title of Notice'),
'#description' => t("Optional"),
'#size' => 30,
'#required' => TRUE,);
$form['comments'] = array(
'#type' => 'textarea',
'#title' => t('Title of Notice'),
'#size' => 30,
'#required' => TRUE,);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
);
return $form;
};
function contact_form_validate($form, $form_state) {
$error_message = "";
$string_exp = "/^[A-Za-z .'-]+$/";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
};
function contact_form_submit($form, $form_state) {
// build the body of the email
$body = "First Name: ".clean_string($first_name)."<br />"."Last Name: ".clean_string($last_name)."<br />"."Email: ".clean_string($email_from)."<br />"."Telephone: ".clean_string($telephone)."<br />"."Comments: ".clean_string($comments);
//send
$message = array(
'to' => 'xxxxxxxxxxxxxxxxxx',
'subject' => $email_subject,
'body' => $body,
'headers' => array(
'From' => $email_from,
'To' => 'xxxxxxxxxxxxxxxxx',
'Subject' => $email_subject,
),);
drupal_mail_send($message);
};
<?php
$output = drupal_get_form('contact_test_form');
return drupal_render($output);
?>