- Entity Registration
- Commerce Registration
- Drupal 7
Our site connects with Salesforce to input Entity Registration data as Contacts. I'm building in the ability to have users login and have their registration forms prefilled with the data I grab from Salesforce.
I have the data, but the prefill isn't working. Commerce Registration buries the forms a bit, as you will see below in my code example. I decided to step out of using the Salesforce data and just use a static value and try to set it. Both default_value and placeholder do nothing. If I try to touch ['value'] the site crashes.
Here is the trimmed down version of what I have:
<?php
function createFieldMap(){
$fieldMapping = array(
"LastName" => "field_last_name",
"FirstName" => "field_first_name",
"Salutation" => "field_prefix"
);
}
function custom_module_form_commerce_checkout_form_registration_alter(&$form, &$form_state, $form_id) {
$fieldMap = createFieldMap();
foreach ($form['registration_information']['register_entities'] as $name => $data) {
foreach($form['registration_information'][$name] as $subname => $subdata) {
foreach ($fieldMap as $salesforceKey => $drupalMachine) {
if($drupalMachine == 'field_last_name'){
$form['registration_information'][$name][$subname]['field_last_name']['#default_value'] = "Johnston";
$form['registration_information'][$name][$subname]['field_last_name']['#attributes']['placeholder'] = t("Johnston");
}
}
}
}
}
Just to point out, $form['registration_information'][$name][$subname] is valid and is done that way because if you have multiple forms, the productID is used as the form ID, twice. I can access $form['registration_information'][$name][$subname]['field_last_name'] if I var_dump it out. ['value'] represents entity data for some reason, which is probably why it crashes if I try to adjust that.
I can get this to work fine by setting the default_value of select lists. But the text fields don't do anything.
und
is the language part of it