如何插入“复选框”值到 SQL
好吧,我对如何将“复选框”值插入 SQL 感到困惑 这是我的代码
$form['last'] = array(
'#type' => 'checkboxes',
'#title' => "Just title",
'#options' => array(
'opt1' => "Option 1",
'opt2' => "Option 2",
),
,你可以看到我的表单由两个复选框组成,那么如何获取值并插入到 sql 语言中。任何人都可以在这里给出一个例子或提示
我用来获取值的方法(我知道这是非常错误的)
function fasil_form_submit($form,&$form_state){
global $user;
$entry = array(
'uid' => $user->uid,
'test1' => $form_state['values']['1first'],
$jenis = 'aa_test';
$return = insert_form($entry,$jenis);
}
ps:抱歉我的英语不好
well i'm confused on how to insert "Checkboxes" values to SQL
here's my code
$form['last'] = array(
'#type' => 'checkboxes',
'#title' => "Just title",
'#options' => array(
'opt1' => "Option 1",
'opt2' => "Option 2",
),
as you can see my form consist of two checkbox, so how to get the value and insert to sql language. anyone can give an example or hint
here the method that i'm used to get the value (i know its very wrong)
function fasil_form_submit($form,&$form_state){
global $user;
$entry = array(
'uid' => $user->uid,
'test1' => $form_state['values']['1first'],
$jenis = 'aa_test';
$return = insert_form($entry,$jenis);
}
ps : sorry for my bad english
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不是 100% 确定您要做什么,但我认为您正在尝试在数据库中为每个选中的复选框插入一个值?如果是这样,这是最快的方法:
正如另一个答案中已经提到的,查看需要从表单中获取内容的最简单方法是在提交函数中输出
$form_state['values']
来查看从表单传递的内容。然而,不要使用难看的
print_r
并可能通过过早调用exit
来搞乱表单提交(在 Drupal 7 中drupal_exit()
应该始终是无论如何使用而不是exit
),我强烈建议您下载并安装 Devel module 并使用它的dpm()
函数将变量打印到屏幕上。传递给 dpm() 的任何变量都会输出到标准 Drupal 消息区域,并成为易于导航的该变量的屏幕层次结构,如下所示:
您绝对可以在 Drupal 代码中的任何地方使用它,例如
Devel 模块非常好,对于任何严肃的 Drupal 开发来说绝对是必不可少的。
希望有帮助。
I'm not 100% sure what you're trying to do but I think you're trying to insert a value in the database for each of the checkboxes ticked? If so this is the quickest way:
As already mentioned in another answer the simplest way to see what you need to get from the form is to output
$form_state['values']
in your submission function to see what was passed from the form.However, rather than use the unsightly
print_r
and potentially messing up the form submission by callingexit
prematurely (in Drupal 7drupal_exit()
should always be used instead ofexit
anyway), I strongly recommend you download and install the Devel module and use it'sdpm()
function to print the variable to the screen.Any variable passed to
dpm()
is outputted to the standard Drupal messages area, and becomes an easy to navigate on-screen hierarchy of that variable like this:You can use it absolutely anywhere in code within Drupal, e.g.
The Devel module is very good, and absolutely essential for any serious Drupal development.
Hope that helps.
这是我喜欢查看表单输出的快速方法
现在这 3 行应该可以清楚地说明 Drupal 如何提交数据。
我相信您需要循环遍历 $form_state['values']['last'] 并测试该键是否未设置为 0。
Here's a quick way I like to look at my form output
Now those 3 lines should make it clear how Drupal is submitting the data.
I believe you will need to loop through $form_state['values']['last'] and test that the key is not set to 0.