Unable to add --select--value at the top of drop down drupal entity registration module required field -


i using registration entity module in drupal website.and have dropdowns of home phone , mobile no on form.home phone no required , doesn't show --select-- value @ top of dropdown.while mobile no not required , hence show --select-- @ top.

now want alter form , add --select-- option value @ top of home phone no.and writing code in custom module.

function custom_va_form_alter(&$form, $form_state, $form_id) {   if($form_id == 'commerce_checkout_form_registration'){    if($form['registration_information']['prod-va_application']['prod-va_application-reg-0']['field_phone']['und'][0]['field_home_phone']['und']['#required'] == 1){    dsm($form);     $form['registration_information']['prod-va_application']['prod-va_application-reg-0']['field_phone']['und'][0]['field_home_phone']['und'][0]['country_codes']['#options']= '--select--';    return $form;    }  } } 

but unable add --select-- @ top of dropdown.what doing wrong?

is there way other alter form in custom module

#options expect array, if want add @ begining use array_unshift function :

array_unshift($form['registration_information']['prod-va_application']['prod-va_application-reg-0']['field_phone']['und'][0]['field_home_phone']['und'][0]['country_codes']['#options'], '--select--'); 

array_unshift documentation : http://php.net/manual/en/function.array-unshift.php


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -