Hi,
I'm creating a shipping method for Drupal Commerce Kickstarter. I've created a type of shipping method with a flat rate etc. but I want to create a search via a 'zipcode' where a user can enter a zipcode and get the results from the service via an XML response that I'm printing out as radio values. I am using an AJAX callback to replace the search form with a new radio input, but I can't get it to print out. All I can get to print out from the radio input is the description, nothing more. How can I print out the whole input?
Another thing: I tried getting the $form['postitoimipaikka'] to the callback with $form_state['values']['postitoimipaikka'], but for some reason it doesnt pass that value on either.
I am using a static search value to test this out. I also know the XML response is a funky one but it's the only method I got it to work.
/**
* Shipping service callback: returns the example shipping service details form.
*/
function commerce_shipping_itella_service_details_form($pane_form, $pane_values, $checkout_pane, $order, $shipping_service) {
$form = array();
$form['postitoimipaikka'] = array(
'#type' => 'textfield',
'#title' => t('Postitoimipaikka'),
'#description' => t('Syötä postitoimipaikkasi.'),
'#default_value' => '',
'#required' => TRUE,
);
$form["submit"] = array(
"#type" => "submit",
"#value" => "Search",
"#ajax" => array(
"callback" => "commerce_shipping_itella_service_form_callback",
"wrapper" => "commerce-shipping-service-details",
"effect" => "fade"
)
);
return $form;
}
/**
* Shipping service callback: increases the shipping line item's unit price if
* express delivery was selected.
*/
function commerce_shipping_itella_service_form_callback($form, &$form_state) {
$postitoimipaikat = array();
// Replace Helsinki with a form_state
$url = "https://ohjelmat.posti.fi/pup/v1/pickuppoints?zipname=Helsinki&top=3";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_TIMEOUT, 130);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
curl_close($curl);
$xml = json_decode($response, true);
foreach($xml as $key => $value)
{
$postitoimipaikat[] = $value['PublicName'] . ", " . $value['PostCode'];
}
$form['postitoimipaikat'] = array(
'#type' => 'radios',
'#description' => t('Valitse toimipaikka, johon lähetys toimitetaan'),
'#options' => $postitoimipaikat,
'#required' => TRUE,
);
return $form['postitoimipaikat'];
}