werushka Posted April 7, 2010 Share Posted April 7, 2010 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; } } Quote Link to comment https://forums.phpfreaks.com/topic/197943-is-it-possible-to-write-this-function-simpler/ Share on other sites More sharing options...
newbtophp Posted April 8, 2010 Share Posted April 8, 2010 <?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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/197943-is-it-possible-to-write-this-function-simpler/#findComment-1038690 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.