I have created a form in drupal. I don't know how to handle the submission. I want to do some selection from database with the values i get from form. Here is my code to create form
function q_search_form() {
$form['qsearch']['category'] = array(
'#type' => 'select',
'#options' => array(0 => 'Any', 1 => 'Automotive', 2 => 'Real Estate'),
'#attributes' => array('class' => 'drop-box'),
'#prefix' => '<table width="470"><tr><td width="170">Select Category</td><td width="300">',
'#suffix' => '</td></tr>'
);
$form['qsearch']['city'] = array(
'#type' => 'select',
'#options' => array(0 => 'Any', 1 => 'Calicut', 2 => 'Kochi'),
'#attributes' => array('class' => 'drop-box'),
'#prefix' => '<tr><td width="170">City</td><td width="300">',
'#suffix' => '</td></tr>'
);
$form['qsearch']['property'] = array(
'#type' => 'select',
'#options' => array(0 => 'Any', 1 => 'House', 2 => 'Land'),
'#attributes' => array('class' => 'drop-box'),
'#prefix' => '<tr><td width="170">Property</td><td width="300">',
'#suffix' => '</td></tr>'
);
$form['qsearch']['wanto'] = array(
'#type' => 'select',
'#options' => array(0 => 'Any', 1 => 'Sell', 2 => 'Buy'),
'#attributes' => array('class' => 'drop-box'),
'#prefix' => '<tr><td width="170">Want to</td><td width="300">',
'#suffix' => '</td></tr>'
);
$form['qsearch']['submit'] = array(
'#type' => 'submit',
'#value' => t('Search'),
'#attributes' => array('id' => 'Search', 'class' => 'srch-button'),
'#prefix' => '<tr><td><a class="adv-srch" href="#">Advance Search</a></td><td>',
'#suffix' => '</td></tr></table>'
);
return $form;
}
You can do pretty much anything you want in the
form_submit
function.This is pretty simple. You just have to implement the
form_submit
function. From the function above, I assume the name of your module to beq_search
. So, here is what the submit function would look like:If you also want to validate the user inputs before the actual submit, you should add a validation function which would look like:
You can use form_set_error, in the validate function if the validation fails.
You can write following submit function,