单击时提交表单的复选框
我正在使用 Codeigniter,想知道如何制作一个单击即可提交表单的复选框?
其次,此复选框将是充当过滤器的几个复选框之一,例如 products > > 20 美元,产品 < $30,我如何在网址中传递它?我在想/1+2+3
I'm using Codeigniter and wants to know how I can make a checkbox that submits the form on click?
Secondly, this checkbox will be one of several checkboxes that will act as a filter like products > $20, products < $30, how do i pass it in the url? I'm thinking /1+2+3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有太多使用 Codeigniter,但我可以回答如何使用 JS 检查复选框来提交表单:
Haven't worked with Codeigniter much, but I can answer how to make the form submit on checking the checkbox with JS:
javascript问题似乎已经解决了;让我们看看 codeigniter 的部分。
您可以通过这两种方式之一传递 url。
惯用但有限:如 /1/2/3/4/etc。处理该 url 的控制器函数都可以使用 func_get_args 来读取它们,或者,如果您已经知道最多将传递多少个参数,则为所有不必要的参数指定默认值 null;< /p>
不是 Codeigniterish,但对于搜索参数来说确实更好:在配置文件上启用查询字符串,像平常使用 GET 一样传递参数 (
min=2&max=3
等)并使用 CI 的输入类获取它们的值($min = $this->input->get('min')
)。The javascript questions seem to have been solved already; let's step to the codeigniter ones.
You can pass the url in one of those two ways.
Idiomatic but limited: as /1/2/3/4/etc. The controller function handling that url could both use
func_get_args
to read them or, if you already know how many parameters will be passed at the most, give a default value of null to all non-necessary paramenters;Not Codeigniterish but seriously better for search parameters: enable the query strings on your config file, pass arguments as you would normally with GET (
min=2&max=3
and so on) and get their value with CI's input class ($min = $this->input->get('min')
).这与 PHP 无关,也与 CodeIgniter 无关。解决办法是在元素的onclick事件中提交表单。
如果您愿意,可以使用表单的 OnSubmit 事件来很好地设置 url 的格式。
为此,您可以
location.href = yourniceurl
设置 url,请注意,这两种解决方案都需要启用 JavaScript。因此,有其他方式提交表单(提交按钮)是一件好事。不要依赖按 Enter 键提交。 Opera 将使用 Enter 键来切换复选框,而不是提交表单。
如果您愿意,您可以使用 Javascript 隐藏提交按钮,这样,拥有 Javascript 的用户将自动提交表单,而没有 Javascript 的用户可以使用该按钮。
您需要确保您的服务器端表单验证器不仅接受漂亮的网址,还接受丑陋的网址(发布诸如
?filterx=on
之类的值)。This has nothing to do with PHP, nor CodeIgniter. The solution is to submit the form in the onclick event of the element.
You can use the OnSubmit event of the form to nicely format the url, if you like.
To do this, you can
location.href = yourniceurl
,Note that both solutions require javascript to be enabled. So it is a good thing to have other means of submitting the form (submit button). Don't rely on submitting by pressing Enter. Opera will use the Enter key for toggling the checkbox instead of submitting the form.
If you like, you can hide the submit button using Javascript, that way, users having Javascript will have their form auto-submitted, while users without can use the button.
You will need to make sure that your server side form validator not only accepts the nice url, but the ugly url (which posts values like
?filterx=on
) too.