I am working in Drupal 7, and had to make an edit to a pre-existing module. The module was set to display a form if a certain variable was set to true. I had to add 3 additional variables, and now instead of showing the form, I see 'Array'. I didn't change anything other than the logic in the if/else to determine if the form should be pulled.
I found a similar problem, that was never answered here ( https://stackoverflow.com/questions/10130535/drupal-7-renderdrupal-get-formform-not-working )
My code is as such:
<?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;
}
The section that isn't working correctly is:
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;
}
Any help is much appreciated!
All drupal_get_form does is turn your form array into something renderable. If you want your form to be displayed as HTML, you should try something like:
<?php
$form = drupal_get_form(...);
$content .= drupal_render($form);
?>