I have created a module that writes a block with a very simple form in it.
The purpose of it is calculating distance between 2 adresses, one fixed, one asked by the form.
Now I can't get the results to show in the block itself, and I can't find any tutorials on how to do that.
The block shows, the form is in it also, but when i submit a postalcode it seems that nothing happens (also the postcode input field resets to emtpy).
the code that retrieves the distance works also (tested on commandline).
How can I approach this?
The code for my block:
function reiskosten_block_view($delta = '') {
$block = array();
switch ($delta) {
case 'reiskostenblock':
$block['subject'] = t('Reiskosten berekenen');
$block['content'] = drupal_get_form('reiskosten_form');
break;
}
The code for submitting the form:
function reiskosten_form_submit($form, &$form_state) {
/* REPLACE SPACE OR HTTP-REQUEST WILL BE MALFORMED */
$postcode = str_replace(' ','',$form_state['values']['postcode']);
$url = "https://maps.googleapis.com/maps/api/distancematrix/json?origins=1024AA|Netherlands&destinations=$postcode|Netherlands&mode=car&language=nl-NL&sensor=false&key=myKey";
$data = drupal_http_request($url);
$result = drupal_json_decode($data->data);
$destination = $result['destination_addresses'][0];
$distance = $result['rows'][0]['elements'][0]['distance']['text'];
$duraton = $result['rows'][0]['elements'][0]['duration']['text'];
drupal_set_message("$distance");
$form_state['rebuild'] = TRUE;
}
I want the output of $result to be shown below the submitbutton. It is driving me crazy this one, been puzzling for 5 hours now on this thing (what should be relatively simple imho).
edit: I also validate on postalcode with:
function reiskosten_form_validate($form, &$form_state) {
if ( empty($form_state['values']['postcode']) ) {
form_set_error('postcode', t('Postcode mag niet leeg zijn'));
}
}
It doesn't throw an error so it seems to me that 'postcode' has a value and the function should be processed.