Problem seeing PHP code as it was entered

ashembers - February 15, 2008 - 17:53

Hello,

I have been trying to wrap my head around the forms api, which is difficult for me not being fluent with PHP. My problem is that when I paste the sample PHP code (from the Form API Quickstart Guide - http://api.drupal.org/api/5/file/developer/topics/forms_api.html) into my sample contact page (a static page), and set the input format to "PHP code". After I submit or preview the page, nothing shows in the preview, but what I find to be odd is that the code in the page body doesn't match the sample code at all! What I see is:

<p>
t('Enabled'), '0' =&gt; t('Disabled'));
  $form['access'] = array(
    '#type' =&gt; 'fieldset',
    '#title' =&gt; t('Access log settings'),
    '#tree' =&gt; TRUE,
  );
  $form['access']['log'] = array(
    '#type' =&gt; 'radios',
    '#title' =&gt; t('Log'),
    '#default_value' =&gt;  variable_get('log', 0),
    '#options' =&gt; $options,
    '#description' =&gt; t('The log.'),
  );
  $period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval');
  $form['access']['timer'] = array(
    '#type' =&gt; 'select',
    '#title' =&gt; t('Discard logs older than'),
    '#default_value' =&gt; variable_get('timer', 259200),
    '#options' =&gt; $period,
    '#description' =&gt; t('The timer.'),
  );
  // Description
  $form['details'] = array(
    '#type' =&gt; 'fieldset',
    '#title' =&gt; t('Details'),
    '#collapsible' =&gt; TRUE,
    '#collapsed' =&gt; TRUE,
  );
  $form['details']['description'] = array(
    '#type' =&gt; 'textarea',
    '#title' =&gt; t('Describe it'),
    '#default_value' =&gt;  variable_get('description', ''),
    '#cols' =&gt; 60,
    '#rows' =&gt; 5,
    '#description' =&gt; t('Log description.'),
  );
  $form['details']['admin'] = array(
    '#type' =&gt; 'checkbox',
    '#title' =&gt; t('Only admin can view'),
    '#default_value' =&gt; variable_get('admin', 0),
  );
  $form['name'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; t('Name'),
    '#size' =&gt; 30,
    '#maxlength' =&gt; 64,
    '#description' =&gt; t('Enter the name for this group of settings'),
  );
  $form['hidden'] = array('#type' =&gt; 'value', '#value' =&gt; 'is_it_here');
  $form['submit'] = array('#type' =&gt; 'submit', '#value' =&gt; t('Save'));
  return $form;
}

function test_page() {
  return drupal_get_form('test_form');
}
?&gt;
</p>

Where before it was:

<?php
function test_form() {
 
// Access log settings:
 
$options = array('1' => t('Enabled'), '0' => t('Disabled'));
 
$form['access'] = array(
   
'#type' => 'fieldset',
   
'#title' => t('Access log settings'),
   
'#tree' => TRUE,
  );
 
$form['access']['log'] = array(
   
'#type' => 'radios',
   
'#title' => t('Log'),
   
'#default_value' =>  variable_get('log', 0),
   
'#options' => $options,
   
'#description' => t('The log.'),
  );
 
$period = drupal_map_assoc(array(3600, 10800, 21600, 32400, 43200, 86400, 172800, 259200, 604800, 1209600, 2419200, 4838400, 9676800), 'format_interval');
 
$form['access']['timer'] = array(
   
'#type' => 'select',
   
'#title' => t('Discard logs older than'),
   
'#default_value' => variable_get('timer', 259200),
   
'#options' => $period,
   
'#description' => t('The timer.'),
  );
 
// Description
 
$form['details'] = array(
   
'#type' => 'fieldset',
   
'#title' => t('Details'),
   
'#collapsible' => TRUE,
   
'#collapsed' => TRUE,
  );
 
$form['details']['description'] = array(
   
'#type' => 'textarea',
   
'#title' => t('Describe it'),
   
'#default_value' =>  variable_get('description', ''),
   
'#cols' => 60,
   
'#rows' => 5,
   
'#description' => t('Log description.'),
  );
 
$form['details']['admin'] = array(
   
'#type' => 'checkbox',
   
'#title' => t('Only admin can view'),
   
'#default_value' => variable_get('admin', 0),
  );
 
$form['name'] = array(
   
'#type' => 'textfield',
   
'#title' => t('Name'),
   
'#size' => 30,
   
'#maxlength' => 64,
   
'#description' => t('Enter the name for this group of settings'),
  );
 
$form['hidden'] = array('#type' => 'value', '#value' => 'is_it_here');
 
$form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
  return
$form;
}

function
test_page() {
  return
drupal_get_form('test_form');
}
?>

So I'm already rather confused with the forms api in general, but really don't understand this odd automatic code rewriting.

I should probably mention that I am using widgEditor to simplify pagemaking for my coworkers that do not know HTML, if that has anything to do with it.

Thanks for your time!

Never mind - it was widgEditor

ashembers - February 15, 2008 - 18:10

I see that once I disabled widgEditor, the code stays the way it was entered. Never mind, but thanks for checking anyway!

 
 

Drupal is a registered trademark of Dries Buytaert.