Folks,

The upgrading themes and modules to 4.7 pages have been largely helpful.
I'm working on porting the CivicSpace theme (my derivate is a layout) to 4.7
and I've gotten a decent bit done. The FORMS API bit is where I am at.

I used the FormsUpdater to convert the civicspace function
phptemplate_comment_form to 4.7 compatible. (in template.php)

Problem: when I click the add comment link to a node, I now get a new error which
does not look like a form_* related (4.6) error, but it is an error in drupal_get_form().

**
Fatal error: Unsupported operand types in /home/.olympia/editors/bopnetwork.org/includes/form.inc on line 87
**

Here are the last 4 lines of the updated function. It's failing in the call
inside drupal_get_form which much return the form HTML to $output.

~~
$form['#method'] = 'post';
$form['#action'] = url('comment/reply/'. $edit['nid']);
$output = drupal_get_form('comment_form', $form);

return theme('box', $title, $output);
~~

The line in form.inc is within the function drupal_get_form() where the
failure is happening. It is this:
~~
$form += _element_info('form');
~~

Can someone tell me what's going on? I've told the CivicSpace folks that
I will make this work for my site and then hand off the changes/patches
to them for 4.7. Appreciate any help. I can post the whole converted function
here if you want.

thanks.

-S
(p.s. two other folks have seen this for cac_lite and tac_lite but those threads
don't seem to have a resolution for this issue.)

Comments

heine’s picture

Please post the whole $form array (or the whole converted function).
--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.

heine’s picture

I'm replying to myself here, because the code is very long, and better left at the bottom.

I'm certainly not a forms api expert, but I believe your approach is fundamentally flawed(*). You're actually trying to build a form in a theme function, where you should only output HTML. drupal_get_form calls your theme function to get the form rendered, but instead you call it again, if _element_info didn't fail, you'd get a lot of recursion.

$edit actually contains the entire forms array from comment_form().

Try

function phptemplate_comment_form($form) {
  $output = form_render($form);
  return $output;
  // or return theme('box', $title, $output);
}

It's possible to render individual form fields, see for example http://drupal.org/node/47582

(*) That means, it doesn't make sense to me.
--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.

slazenger’s picture

Thanks for the tip. I think I'm moving in the direction here. I've been using the regular FormsAPI documentation and didn't read enough of the distinction betwee theme related Forms API and module related Forms API.

I changed the code to

  // clip from phptemplate_comment_form() 
  $form['#method'] = 'post';
  $form['#action'] = url('comment/reply/'. $edit['nid']);
  // $output = drupal_get_form('comment_form', $form);
  $output = form_render($form);

  return theme('box', $title, $output);

This makes that unsupported operands problem go away, and a new warning comes up:

~~~
warning: uasort(): The argument should be an array in /home/.olympia/editors/bopnetwork.org/includes/form.inc on line 455.
~~~

The $form being passed is an array, and the complaint is coming from
form_render()'s fourth line itself the uasort() function.

// clip from forms.inc, 
function form_render(&$elements) {
  if (!isset($elements)) {
    return NULL;
  }
  $content = '';
  uasort($elements, "_form_sort");

Importantly, the comment form itself does not render at the
bottom of the story. A box with 'Reply' title gets put out and
here's the HTML I see in view source.

<div class="box">
  <h2>Reply</h2>
  <div class="content">
    <form action="/comment/reply/26"  method="post" id="comment_form">
<div><div class="box">
  <h2></h2>
  <div class="content">
      </div>
</div>
</div></form>
  </div>
</div>

(I could not figure how to post the HTML into the comment box here,
to box code got rendered by mistake here, sorry!)

It seems that even though form_render is the correct API that theme functions
must call, perhaps something went wrong in the form array setup. Any advice
will help greatly. Thanks again for the key tip.

[fixed tags - Heine]

heine’s picture

I should have expressed myself clearer. You do not need to built the form array in phptemplate_comment_form anymore; it comes prebuilt. The only thing you have to do is generate output.

To see for yourself, modify the function:
function phptemplate_comment_form($form) {
var_dump($form);

?>

As you can see #method and #action are already defined.

PS You can post HTML between <code> tags.
--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.

slazenger’s picture

Appreciate that, it's working and now the commenting form renders and I can post/reply. I think I got the hang of this now. comment.module is already filling out everything like you said and it is calling drupal_get_form() and then itself calls theme('box', $title...) et al. So in 4.7 phptemplate_comment_form, needs to be much simpler it seems, and only has to invoke form_render() and return the output.

Here's the function that worked like you said:

function phptemplate_comment_form($form) {
  $output = form_render($form);
  return $output;
}

// I've renamed the outdated comment_form function to _old for now 

function phptemplate_comment_form_old($edit, $title) {
  global $user;
//clipped

I'm getting some warning on the screen now

~~
warning: implode(): Bad arguments. in /path/to/site/themes/sitetheme/template.php on line 386.
~~
It's happening in the function phptemplate_links($links, $delimiter = ' · ').

It looks like many/all of the phptemplate_XXXX functions in template.php for
civicspace need to be revised for 4.7. I've been using the Converting
theme from 4.6 to 4.7 note in http://drupal.org/node/25297 as a guide,
but it's not enough. I'd be happy to update that page when I'm done porting.
In anycase, I'll post a consolidated note there at least.

many thanks, again.

heine’s picture

If you keep it this simple:

function phptemplate_comment_form($form) {
  $output = form_render($form);
  return $output;
}

Then you can just use the defaults, if I'm not mistaken.
--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.

slazenger’s picture

Yes. I commented out the entire function phptemplate_comment_form() and
the form still renders the cleanly. So much for simplicity.

-S

hannibalector’s picture

Hi,
can anyone tell me what I have to change now in the form.in? i am getting this error:
Fatal error: Unsupported operand types in /home/www-data/htdocs/hannibalector/art/includes/form.inc on line 88
the same error as you got. i read all comments, but i just don't understand what i have to change.
the error appears when i'm trying to comment:
http://hannibalector.redio.de/art/?q=comment/reply/9#comment_form
may you help me? thx.

edit: i changed my template.php as shown in your comment of the 27th april.

slazenger’s picture

Here's the modifed function.



function phptemplate_comment_form($edit, $title) {
  global $user;

  $form .= "<a id=\"comment\"></a>\n";

  // contact information:
  if ($user->uid) {
        $form['contact'] = array(
          '#type' => 'item',
          '#title' => t('Your name'),
          '#default_value' => theme('username',$user),
        );
  }
  else if (variable_get('comment_anonymous', 0) == 1) {

        $form['name'] = array(
          '#type' => 'textfield',
          '#title' => t('Your name'),
          '#default_value' => $edit['name'] ? $edit['name'] : variable_get('anonymous', 'Anonymous'),
          '#size' => 20,
          '#maxlength' => 60,
        );

        $form['mail'] = array(
          '#type' => 'textfield',
          '#title' => t('E-mail'),
          '#default_value' => $edit['mail'],
          '#size' => 20,
          '#maxlength' => 64,
          '#description' => t('The content of this field is kept private and will not be shown publicly.'),
        );

        $form['homepage'] = array(
          '#type' => 'textfield',
          '#title' => t('Homepage'),
          '#default_value' => $edit['homepage'],
          '#size' => 20,
          '#maxlength' => 255,
        );
  }
  else if (variable_get('comment_anonymous', 0) == 2) {

        $form['name'] = array(
          '#type' => 'textfield',
          '#title' => t('Your name'),
          '#default_value' => $edit['name'] ? $edit['name'] : variable_get('anonymous', 'Anonymous'),
          '#size' => 20,
          '#maxlength' => 60,
          '#description' => NULL,
          '#attributes' => NULL,
          '#required' => TRUE,
        );

        $form['mail'] = array(
          '#type' => 'textfield',
          '#title' => t('E-mail'),
          '#default_value' => $edit['mail'],
          '#size' => 20,
          '#maxlength' => 64,
          '#description' => t('The content of this field is kept private and will not be
         shown publicly.'),
          '#attributes' => NULL,
          '#required' => TRUE,
        );

        $form['homepage'] = array(
          '#type' => 'textfield',
          '#title' => t('Homepage'),
          '#default_value' => $edit['homepage'],
          '#size' => 20,
          '#maxlength' => 255,
        );
  }

  // subject field:
  if (variable_get('comment_subject_field', 1)) {
        $form['subject'] = array(
          '#type' => 'textfield',
          '#title' => t('Subject'),
          '#default_value' => $edit['subject'],
          '#size' => 50,
          '#maxlength' => 64,
        );
  }

  // comment field:
        $form['comment'] = array(
          '#type' => 'textarea',
          '#title' => t('Comment'),
          '#default_value' => $edit['comment'] ? $edit['comment'] : $user->signature,
          '#cols' => 70,
          '#rows' => 10,
          '#description' => '',
          '#attributes' => NULL,
          '#required' => TRUE,
        );
  // format selector
  $form .= filter_form('format', $edit['format']);

  // preview button:
        $form['cid'] = array(
          '#type' => 'hidden',
          '#value' => $edit['cid'],
        );
        $form['pid'] = array(
          '#type' => 'hidden',
          '#value' => $edit['pid'],
        );
        $form['nid'] = array(
          '#type' => 'hidden',
          '#value' => $edit['nid'],
        );

        $form['submit'] = array(
          '#type' => 'submit',
          '#value' => t('Preview comment'),
        );
  // Only show post button if preview is optional or if we are in preview mode.
  // We show the post button in preview mode even if there are form errors so that
  // optional form elements (e.g., captcha) can be updated in preview mode.
  if (!variable_get('comment_preview', 1) || ($_POST['op'] == t('Preview comment')) || ($_POST['op'] == t('Post comment'))) {
        $form['submit'] = array(
          '#type' => 'submit',
          '#value' => t('Post comment'),
        );
  }

  $form['#method'] = 'post';
  $form['#action'] = url('comment/reply/'. $edit['nid']);
  $output = drupal_get_form('comment_form', $form);

  return theme('box', $title, $output);
}

The original function is in template.php with the
civicspace theme that distributed with 4.6.x (It has a cvs line: /* $Id: template.php,v 1.8.2.5 2005/11/30 21:06:47 robinmonks Exp $ */)

slazenger’s picture

A note to say that the primary issue raised in this thread was resolved, thanks in no small part to Heine.