form_alter

How to remove preview button programmatically

This is how you can remove the Preview button programmatically on all node forms in a form_alter hook.


<?php
//in form alter hook

       //Removes preview button on all node forms
   
if(stripos($form_id, "node_form") > 0) {
      unset (
$form['buttons']['preview']);
    }

//or a specific form...

        //Removes preview button on a specific form
   
if(stripos($form_id, "[my-node-type]_node_form") > 0) {
      unset (
$form['buttons']['preview']);
    }
?>

How to make a validation and a calculation on CCK multiple field

This is how you can add validation and a calculation on a CCK field programmatically. i have a CCK field (integer) with unlimited number of items allowed. User can add the time in different formats and I have a restriction on min 15 minutes. The allowed format is:

[numeric]h[numeric]m like 3h15m

[numeric]h like 2h

[numeric]m like 45m

[numeric] like 60

Hide admin fields


/**
* Hide admin fields from form
* Called from _form_alter
*
* @param unknown_type $form
*/
function __hide_adminfields(&$form) {

$form['admin_only'] = array(
'#type' => 'fieldset',
'#title' => t('Admin settings'),
'#weight' => 100,
'#access arguments' => array('special_administration'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);

//Hide admin fields in one fieldset
$form['admin_only']['options'] = $form['options'];
$form['admin_only']['menu'] = $form['menu'];