Heb een custom module gemaakt met een form. Dit werkt.
Enkel de controle of het veld distance[postal_code] ingevuld is wordt niet gecontroleerd.
(De overige velden zijn hidden ingesteld om de rest vd url aan te vullen!)
Wie kan mij verder helpen?
De code:
Code:
<?php
function location_search_menu() {
$items = array();
$items['markten'] = array( //this creates a URL
'title' => 'Markten, nog toegankelijker!', //page title
'page callback' => 'drupal_get_form', //this is the function that will be called when the page is accessed. for a form, use drupal_get_form
'page arguments' => array('location_search_form'), //put the name of the form here
'access callback' => TRUE
);
return $items;
}
function location_search_form($form, &$form_state) {
$form['#prefix'] = '<div id="postal-code-search"><h2>Markten vandaag in de buurt...</h2>';
$form['#sufix'] = '</div>';
$form['#attributes'] = array('id' => 'postal-code-form');
$form['#method'] = 'get';
$form['#action'] = '/location-list'; // make url
$form['#after_build'][] = 'location_search_form_modify';
$form['distance[postal_code]'] = array(
'#type' => 'textfield', //postal code field
'#size' => 10,
'#maxlength' => 10,
'#required' => TRUE, //make this field required
'#attributes' =>array('placeholder' => t('Postal code')),
);
$form['distance[search_distance]'] = array(
'#type' => 'hidden', //distance field
'#value' => '50',
);
$form['distance[search_units]'] = array(
'#type' => 'hidden', //distance units field
'#value' => 'km',
);
$form['submit_button'] = array(
'#type' => 'submit',
'#value' => t('Search'),
'#name' => '', // unset 'op'
);
return $form;
}
function location_search_form_modify($form){ // remove form_token, form_build_id, form_id from url
unset($form['form_token']);
unset($form['form_build_id']);
unset($form['form_id']);
return $form;
}
function location_search_validate($form, &$form_state) {
$pc = $form_state['values']['distance[postal_code]'];
if(empty($pc) || $pc == '') {
form_set_error('distance[postal_code]', t('Postal code is required!'));
}
}