Drupal_get_form显示'数组'

时间:2015-03-24 13:51:43

标签: php drupal-7

我在Drupal 7中工作,并且必须对预先存在的模块进行编辑。如果某个变量设置为true,则模块设置为显示表单。我不得不添加3个额外的变量,而现在我没有显示表格,而是看到了数组'。除了if / else中的逻辑之外,我没有更改任何内容以确定是否应该提取表单。

我发现了一个类似的问题,这里从未回答过(https://stackoverflow.com/questions/10130535/drupal-7-renderdrupal-get-formform-not-working

我的代码是这样的:

<?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;
        }

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:1)

所有drupal_get_form都会将您的表单数组转换为renderable。如果您希望将表单显示为HTML,则应尝试以下操作:

<?php

$form = drupal_get_form(...);
$content .= drupal_render($form);

?>