Node form template FATAL ERROR
gracearoha - February 6, 2007 - 11:11
Help!
I am running Drupal 5.1 and just enabled nodeform template.
When i go into admin/content types to add a form template, i receive the following error message:
Fatal error: Cannot pass parameter 1 by reference in D:\Program Files\xampp\htdocs\drupal\sites\all\modules\nodeformtemplate\nodeformtemplate.module on line 72
any ideas?
grace

PHP5 problem
This looks like a PHP5 problem. In PHP5, you have to be more careful about how parameters are passed than in PHP4. Could you post the code from this module here?
Dave
code for Node form template
Here is the code. I am quite a noob and have not yet learned any php so any insights you could provide would be most helpful. thanks
<?php
// $Id: nodeformtemplate.module,v 1.8.2.1 2007/01/27 10:36:39 egonbianchet Exp $
/**
* @file
* Allow users to configure a default template for each node type.
*/
/**
* Implementation of hook_help()
*/
function nodeformtemplate_help($section) {
switch ($section) {
case 'admin/content/types/' . arg(3) . '/nodeformtemplate':
return t("Write the text that you want to be used as a template when creating new %type nodes. Words starting with a % sign will be replaced with the query string parameter having the same name.", array('%type' => node_get_types('name', arg(3))));
}
}
/**
* Implementation of hook_perm()
*/
function nodeformtemplate_perm() {
return array('administer form templates');
}
/**
* Implementation of hook_menu()
*/
function nodeformtemplate_menu($may_cache) {
$items = array();
if (!$may_cache && node_get_types('name', arg(3))) {
$items[] = array (
'path' => 'admin/content/types/' . arg(3) . '/nodeformtemplate',
'title' => t('Form template'),
'callback' => 'drupal_get_form',
'callback arguments' => array(arg(3) . '_template_node_form'),
'access' => user_access('administer form templates'),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
);
}
return $items;
}
/**
* Implementation of hook_forms()
*/
function nodeformtemplate_forms() {
$forms = array();
foreach (node_get_types() as $type) {
$forms[$type->type . '_template_node_form'] = array(
'callback' => 'nodeformtemplate_template_form',
'callback arguments' => array($type)
);
}
return $forms;
}
/**
* Prepare template forms
*/
function nodeformtemplate_template_form($type) {
$node = new stdClass();
$node->type = $type->type;
// We use this flag to know wether we are in a real node form in hook_nodeapi
$node->formtemplate_settings = true;
$form = drupal_retrieve_form($node->type . '_node_form', $node);
foreach (module_implements('form_alter') as $module) {
$function = $module .'_form_alter';
$function($node->type . '_node_form', $form);
}
$form['#id'] = $node->type . '_template_node_form';
$form['#base'] = 'nodeformtemplate_template_form';
$form['reset'] = array('#type' => 'submit', '#value' => t('Reset'), '#weight' => 40);
// unset some known unsupported fields
foreach (array('author', 'options', 'taxonomy', 'menu') as $field) {
foreach (element_children($form[$field]) as $key) {
$form[$field][$key]['#disabled'] = TRUE;
}
}
foreach (element_children($form['body_filter']['format']) as $key) {
$form['body_filter']['format'][$key]['#disabled'] = TRUE;
}
unset($form['preview']);
// remove node validation code and disable non-text fields
_nodeformtemplate_prepare_template_form($form, $values);
return $form;
}
/**
* Filters a standard node form
*/
function _nodeformtemplate_prepare_template_form(&$form, &$values) {
foreach ($form as $key => $value) {
if (is_array($form[$key])) {
if (element_child($key)) {
// disable validation
unset($form[$key]['#validate']);
$form[$key]['#required'] = FALSE;
// disable all non-text fields
if (isset($form[$key]['#type']) && (!in_array($form[$key]['#type'], array('textfield', 'textarea', 'submit')) || isset($form[$key]['#autocomplete_path']))) {
$form[$key]['#disabled'] = TRUE;
}
}
// recurse form fields
_nodeformtemplate_prepare_template_form($form[$key], $values);
}
}
}
/**
* Saves a template
*/
function nodeformtemplate_template_form_submit($form_id, $form_values) {
switch ($form_values['op']) {
case t('Submit'):
foreach (array('nid', 'vid', 'uid', 'created', 'changed') as $field) {
unset($form_values[$field]);
}
$types = node_get_types();
if ($types[$form_values['type']]) {
variable_set('nodeformtemplate_' . $form_values['type'], serialize($form_values));
drupal_set_message(t('Template saved'));
}
break;
case t('Reset'):
$types = node_get_types();
if ($types[$form_values['type']]) {
variable_del('nodeformtemplate_' . $form_values['type']);
drupal_set_message(t('Template cleared'));
}
break;
}
}
/**
* Implementation of hook_nodeapi()
*/
function nodeformtemplate_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
switch ($op) {
case 'prepare':
if (!$node->nid && variable_get('nodeformtemplate_' . $node->type, 0)) {
$template = unserialize(variable_get('nodeformtemplate_' . $node->type, 0));
// Don't do if we are on the form template settings page
if (!$node->formtemplate_settings) {
_nodeformtemplate_replace_placeholders($template);
}
foreach ($template as $key => $value) {
$node->$key = $value;
}
$node->uid = $GLOBALS['user']->uid;
$node->name = $GLOBALS['user']->name;
}
break;
case 'submit':
if (variable_get('nodeformtemplate_' . $node->type, 0) && module_exists('token')) {
$node->body = token_replace($node->body, 'node', $node);
}
break;
}
}
/**
* Replaces placeholder with $_GET values
*/
function _nodeformtemplate_replace_placeholders(&$template) {
foreach ($template as $field => $value) {
if (is_array($value)) {
// recurse
_nodeformtemplate_replace_placeholders($template[$field]);
}
else {
// try to insert query parameters if a placeholder is found
foreach ($_GET as $key => $var) {
if ($var != '') {
$template[$field] = str_replace('%' . $key, $var, $template[$field]);
}
}
// clean remaining placeholders
$template[$field] = preg_replace('/%([a-z]+|[A-Z]+|[0-9]+)+/', '', $template[$field]);
}
}
}