1

I am created a Drupal module and added the form alter function:

    MY_MODULE_form_alter(&$form, &$form_state, $form_id){
     if(($form_id === 'commerce_checkout_flow_multistep_default') &&
     ($form['#step_id'] === 'order_information')){

      $form['contact_information']['email']['#value'] = $email; // This is working

      ...

I also added this code:

$form['payment_information']['billing_information']['address'][0]['address']['given_name']['#value'] = $ime;
$form['payment_information']['billing_information']['address'][0]['address']['family_name']['#value'] = $prezime;
$form['payment_information']['billing_information']['address'][0]['address']['address_line1']['#value'] = $adresa;
$form['payment_information']['billing_information']['address'][0]['address']['postal_code']['#value'] = $ptt;
$form['payment_information']['billing_information']['address'][0]['address']['locality']['#value'] = $grad;

but this don't work for me. Any idea?

EricLavault
  • 12,130
  • 3
  • 23
  • 45
Santo Boldizar
  • 1,255
  • 14
  • 17
  • What does not work exactly ? Are $grad, $prezime, etc.. variables or strings ? PHP won't expand simple quoted variables like `'$grad'`. Don't quote variables unless it is really necessary and in this case use double quotes. Secondly, `#value` is used to set values that cannot be edited by the user, is this really what you want here ? – EricLavault Nov 18 '17 at 15:39
  • I want to get data from commerce checkout form, and I want to set default value if user is authenticated. These are strings, and I use without ' ', I was wrong here. – Santo Boldizar Nov 20 '17 at 08:25

1 Answers1

0

PHP does not expand simple quoted variables like '$grad'. Don't quote variables unless it is really necessary and in this case use double quotes : "$grad". See PHP strings and variable expansion

Secondly, #value is used to set values that cannot be edited by the user. Use #default_value instead. See Drupal Form API

EricLavault
  • 12,130
  • 3
  • 23
  • 45