ページを編集していて、ページに drupal フォームが必要です。
drupal フォームの作成方法は知っていますが、'body' ブロックを編集して PHP を挿入すると、テンプレートの外側に表示されます。
次のように挿入できるパラメーターはありますか
$output = drupal_get_form(my_form, 'node 1')
か何か?
前もって感謝します
$output = drupal_get_form(contact_form, 'ノード 1');
drupal_render($出力);
function contact_form($form_state) {
$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);
};
私が得た答えがうまくいかなかったので、コード全体を追加しました。