Drupal表单提交 [英] Drupal form submission
本文介绍了Drupal表单提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
function q_search_form(){
$ form ['qsearch'] ['category '] = array(
'#type'=>'select',
'#options'=>数组(0 =>'Any',1 =>'Automotive' =''Real Estate'),
'#attributes'=> array('class'=>'drop-box'),
'#prefix'=>'< table width =470>< tr>< td width =170>选择类别< / td>< td width =300>',
'#suffix'=> '< / td>< / tr>'
);
$ form ['qsearch'] ['city'] = array(
'#type'=>'select',
'#options'=>数组(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'=>数组('class'=>'drop-box'),
'#prefix'=>'< tr>< td width =170>属性< / td>< td width =300>',
'#suffix'= >'< / td>< / tr>'
);
$ form ['qsearch'] ['wanto'] = array(
'#type'=>'select',
'#options'=>数组(0 => ;'Any',1 =&''Sell',2 =&''Buy'),
'#attributes'=> array('class'=>'drop-box'),
'#prefix'=>'< tr>< td width =170>想要< / td>< td width =300>',
'#suffix' =>'< / td>< / tr>'
);
$ form ['qsearch'] ['submit'] = array(
'#type'=>'submit',
'#value'=> t(' ),
'#attributes'=> array('id'=>'Search','class'=>'srch-button'),
'#prefix'=& < tr>< td>< a class =adv-srchhref =#>高级搜索< / a>< / td>< td>',
'#suffix' =>'< / td>< / tr>< / table>'
);
return $ form;
}
解决方案
您可以在 form_submit
函数中做任何事情。
code> function q_search_form_submit($ form,& $ form_state){
$ category = $ form_state ['values'] ['category'];
$ city = $ form_state ['values'] ['city'];
// etc ..
//使用这些值来查询数据库表
$ query = db_select($ category,'c');
//将结果缩小到只在所选城市的用户:
$ query-> join($ city,'cy','c.city = cy.cid');
//更窄的结果 - > join语句
$ results = $ query
- > fields('c',array(要从类别表中的字段))
//其他表的字段...
- > execute();
//用$结果执行任何操作(打印在不同的页面上,在表格中打印等)。
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.
function q_search_form_submit($form, &$form_state) {
$category = $form_state['values']['category'];
$city = $form_state['values']['city'];
//etc..
//use these values to query your database tables
$query = db_select($category, 'c');
//narrow results to those only in the selected city:
$query->join($city, 'cy', 'c.city = cy.cid');
//narrow results further with more ->join statements
$results = $query
->fields('c', array(fields you want from the categories table))
//fields from other tables...
->execute();
//do whatever with the $results (print on a different page, print in a table, etc).
这篇关于Drupal表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文