Drupal_get_form 显示 'Array'
Drupal_get_form displaying 'Array'
我在 Drupal 7 中工作,不得不对预先存在的模块进行编辑。如果某个变量设置为 true,模块将设置为显示表单。我不得不添加 3 个额外的变量,现在我看到的不是显示表格,而是 'Array'。除了 if/else 中的逻辑以确定是否应拉取表单外,我没有更改任何其他内容。
我发现了一个类似的问题,这里从未回答过 ()
我的代码是这样的:
<?php
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function du_r2t4_block_confirm_view() {
$provider = du_r2t4_get_provider();
//drupal_set_message("<pre>provider: ".var_export($provider,TRUE)."</pre>");
$term = $provider->getCurrentTerm();
//drupal_set_message("<pre>term: ".var_export($term,TRUE)."</pre>");
if(!$term) return du_r2t4_get_msg_wrapped("no_term");
global $user;
$person = $provider->getPerson($user->name, ($term ? $term->code : NULL));
//$person->termCode = NULL;
//$person->satisfied = TRUE;
//$person->satisfied = FALSE;
//$person->satisfied = NULL;
//drupal_set_message("<pre>person: ".var_export($person,TRUE)."</pre>");
$enrollment = $provider->getEnrollment($person->username, $term->code);
//$enrollment = array();
//drupal_set_message("<pre>enrollment: ".var_export($enrollment,TRUE)."</pre>");
$registered = $term->code && $term->code == $person->termCode && !empty($enrollment);
if(!$registered) return du_r2t4_get_msg_wrapped("no_reg");
$content = "";
if($person->satisfied === TRUE) $content .= du_r2t4_get_msg_wrapped("satisfied");
elseif($person->satisfied === FALSE) $content .= du_r2t4_get_msg_wrapped("required");
else $content .= du_r2t4_get_msg_wrapped("unknown");
$confirmed = $provider->getLastConfirmation($person);
if($confirmed) $content .= du_r2t4_get_msg_wrapped("confirmed");
/*
* TODO move details to form builder
*/
$content .= "<table style=\"width:auto;\"><tbody style=\"border:0;\">";
$content .= "<tr><td valign=\"top\">Name:</td><td valign=\"top\">{$person->firstName} {$person->lastName}</td></tr>";
$content .= "<tr><td valign=\"top\">Id:</td><td valign=\"top\">{$person->identity}</td></tr>";
$content .= "<tr><td valign=\"top\">Term:</td><td valign=\"top\">{$term->description}</td></tr>";
$content .= "<tr><td valign=\"top\">Classes:</td><td valign=\"top\">";
/**
* Session 2
*/
$se2 = FALSE;
$s4e = FALSE;
$s4m = FALSE;
$s4l = FALSE;
/**
*
* Session 2
*
*/
foreach ($enrollment as $k => $v) {
switch ($v->sessionCode){
case "SE2":
$se2 = TRUE;
$content .= $v->crn ." ". $v->subjectCode.$v->courseNumber ." ".$v->courseTitle ." (" . $v->sessionDescription.")<br />";
break;
case "S4E":
$s4e = TRUE;
$content .= $v->crn ." ". $v->subjectCode.$v->courseNumber ." ".$v->courseTitle ." (" . $v->sessionDescription.")<br />";
break;
case "S4M":
$s4m = TRUE;
$content .= $v->crn ." ". $v->subjectCode.$v->courseNumber ." ".$v->courseTitle ." (" . $v->sessionDescription.")<br />";
break;
case "S4L":
$s4l = TRUE;
$content .= $v->crn ." ". $v->subjectCode.$v->courseNumber ." ".$v->courseTitle ." (" . $v->sessionDescription.")<br />";
break;
default:
$content .= "You're not enrolled in any classes.";
}
}
$content .= "</td></tr>";
$content .= "</table>";
//if($_SESSION["du_r2t4_success"]) $content .= "<p>You have intent to attend confirmation has been submitted.</p>";
//else $content .= drupal_get_form("du_r2t4_form_confirm",$term,$person);
$content .= "<p>".du_r2t4_get_form_confirm_precontent()."</p>";
//if(!$se2 || !$s4e || !$s4m || !$s4l || $_SESSION["du_r2t4_success"]) $_SESSION["du_r2t4_success"] = false;
//else $content .= drupal_get_form("du_r2t4_form_confirm",$term,$person,$enrollment);
//
if ($se2 || $s4e || $s4m || $s4l || !$_SESSION["du_r2t4_success"])
{
$content .= drupal_get_form("du_r2t4_form_confirm",$term,$person,$enrollment);
}
else
{
$_SESSION["du_r2t4_success"] = false;
}
//$content .= drupal_get_form("du_r2t4_form_confirm",$term,$person);
return $content;
}
无法正常工作的部分是:
if ($se2 || $s4e || $s4m || $s4l || !$_SESSION["du_r2t4_success"])
{
$content .= drupal_get_form("du_r2t4_form_confirm",$term,$person,$enrollment);
}
else
{
$_SESSION["du_r2t4_success"] = false;
}
非常感谢任何帮助!
全部drupal_get_form does is turn your form array into something renderable。如果您希望您的表单显示为 HTML,您应该尝试这样的操作:
<?php
$form = drupal_get_form(...);
$content .= drupal_render($form);
?>
我在 Drupal 7 中工作,不得不对预先存在的模块进行编辑。如果某个变量设置为 true,模块将设置为显示表单。我不得不添加 3 个额外的变量,现在我看到的不是显示表格,而是 'Array'。除了 if/else 中的逻辑以确定是否应拉取表单外,我没有更改任何其他内容。
我发现了一个类似的问题,这里从未回答过 ()
我的代码是这样的:
<?php
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function du_r2t4_block_confirm_view() {
$provider = du_r2t4_get_provider();
//drupal_set_message("<pre>provider: ".var_export($provider,TRUE)."</pre>");
$term = $provider->getCurrentTerm();
//drupal_set_message("<pre>term: ".var_export($term,TRUE)."</pre>");
if(!$term) return du_r2t4_get_msg_wrapped("no_term");
global $user;
$person = $provider->getPerson($user->name, ($term ? $term->code : NULL));
//$person->termCode = NULL;
//$person->satisfied = TRUE;
//$person->satisfied = FALSE;
//$person->satisfied = NULL;
//drupal_set_message("<pre>person: ".var_export($person,TRUE)."</pre>");
$enrollment = $provider->getEnrollment($person->username, $term->code);
//$enrollment = array();
//drupal_set_message("<pre>enrollment: ".var_export($enrollment,TRUE)."</pre>");
$registered = $term->code && $term->code == $person->termCode && !empty($enrollment);
if(!$registered) return du_r2t4_get_msg_wrapped("no_reg");
$content = "";
if($person->satisfied === TRUE) $content .= du_r2t4_get_msg_wrapped("satisfied");
elseif($person->satisfied === FALSE) $content .= du_r2t4_get_msg_wrapped("required");
else $content .= du_r2t4_get_msg_wrapped("unknown");
$confirmed = $provider->getLastConfirmation($person);
if($confirmed) $content .= du_r2t4_get_msg_wrapped("confirmed");
/*
* TODO move details to form builder
*/
$content .= "<table style=\"width:auto;\"><tbody style=\"border:0;\">";
$content .= "<tr><td valign=\"top\">Name:</td><td valign=\"top\">{$person->firstName} {$person->lastName}</td></tr>";
$content .= "<tr><td valign=\"top\">Id:</td><td valign=\"top\">{$person->identity}</td></tr>";
$content .= "<tr><td valign=\"top\">Term:</td><td valign=\"top\">{$term->description}</td></tr>";
$content .= "<tr><td valign=\"top\">Classes:</td><td valign=\"top\">";
/**
* Session 2
*/
$se2 = FALSE;
$s4e = FALSE;
$s4m = FALSE;
$s4l = FALSE;
/**
*
* Session 2
*
*/
foreach ($enrollment as $k => $v) {
switch ($v->sessionCode){
case "SE2":
$se2 = TRUE;
$content .= $v->crn ." ". $v->subjectCode.$v->courseNumber ." ".$v->courseTitle ." (" . $v->sessionDescription.")<br />";
break;
case "S4E":
$s4e = TRUE;
$content .= $v->crn ." ". $v->subjectCode.$v->courseNumber ." ".$v->courseTitle ." (" . $v->sessionDescription.")<br />";
break;
case "S4M":
$s4m = TRUE;
$content .= $v->crn ." ". $v->subjectCode.$v->courseNumber ." ".$v->courseTitle ." (" . $v->sessionDescription.")<br />";
break;
case "S4L":
$s4l = TRUE;
$content .= $v->crn ." ". $v->subjectCode.$v->courseNumber ." ".$v->courseTitle ." (" . $v->sessionDescription.")<br />";
break;
default:
$content .= "You're not enrolled in any classes.";
}
}
$content .= "</td></tr>";
$content .= "</table>";
//if($_SESSION["du_r2t4_success"]) $content .= "<p>You have intent to attend confirmation has been submitted.</p>";
//else $content .= drupal_get_form("du_r2t4_form_confirm",$term,$person);
$content .= "<p>".du_r2t4_get_form_confirm_precontent()."</p>";
//if(!$se2 || !$s4e || !$s4m || !$s4l || $_SESSION["du_r2t4_success"]) $_SESSION["du_r2t4_success"] = false;
//else $content .= drupal_get_form("du_r2t4_form_confirm",$term,$person,$enrollment);
//
if ($se2 || $s4e || $s4m || $s4l || !$_SESSION["du_r2t4_success"])
{
$content .= drupal_get_form("du_r2t4_form_confirm",$term,$person,$enrollment);
}
else
{
$_SESSION["du_r2t4_success"] = false;
}
//$content .= drupal_get_form("du_r2t4_form_confirm",$term,$person);
return $content;
}
无法正常工作的部分是:
if ($se2 || $s4e || $s4m || $s4l || !$_SESSION["du_r2t4_success"])
{
$content .= drupal_get_form("du_r2t4_form_confirm",$term,$person,$enrollment);
}
else
{
$_SESSION["du_r2t4_success"] = false;
}
非常感谢任何帮助!
全部drupal_get_form does is turn your form array into something renderable。如果您希望您的表单显示为 HTML,您应该尝试这样的操作:
<?php
$form = drupal_get_form(...);
$content .= drupal_render($form);
?>