Jump to content

Is it possible to write this function simpler


werushka

Recommended Posts

I am new to php and I need to write this code simpler..I would appreciate any help

 

function my_module_form_alter(&$form, &$form_state, $form_id) {
  	if ($form['field_age_value']) {
    $form['field_age_value']['#type'] = "select";
    $form['field_age_value']['#options'] = array(All=>"<All>",32=>"32",33=>"33");
    $form['field_age_value']['#default_value'] = No;
    $form['field_age_value']['#size'] = null;
  }
if ($form['field_burc_value']) {
    $form['field_burc_value']['#type'] = "select";
    $form['field_burc_value']['#options'] = array(All=>"Farketmez",Akrep=>"Akrep",Yay=>"Yay",Oglak=>"Oğlak");
    $form['field_burc_value']['#default_value'] = No;
    $form['field_burc_value']['#size'] = null;
  }
}

 

 

<?php
  function my_module_form_alter(&$form, &$form_state, $form_id)
  {
      if ($form['field_age_value']) {
          $type = 'field_age_value';
      } else {
          $type = 'field_burc_value';
      }
      $form[$type]['#type'] = "select";
      if ($type == 'field_age_value') {
          $form['field_age_value']['#options'] = array(All => "<All>", 32 => "32", 33 => "33");
      } else {
          $form['field_burc_value']['#options'] = array(All => "Farketmez", Akrep => "Akrep", Yay => "Yay", Oglak => "Oglak");
      }
      $form[$type]['#default_value'] = No;
      $form[$type]['#size'] = null;
  }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.