如果所选值更改而没有按钮,则提交 WordPress 表单
我正在尝试提交没有提交按钮的表单。 此表单从 WordPress 中的自定义字段获取值,并在另一个页面中显示结果。我一直在尝试使用通常的 javascript 函数 onchange 但没有任何反应,我也尝试过使用函数...有谁知道这有什么问题或者是否有更好的方法来解决它?是不是和Wordpress或者post方法有关?这是表单的代码:
<form method="get" name="form" action="/busqueda/" >
<div class="search">
<select class="styled" name="author" onChange="this.form.submit();">
<option value="-1" selected>Authors</option>
<?php
$metakey = 'author';
$autores = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) );
if ($authors) {
foreach ($authors as $author) {
echo "<option VALUE=\"" . $author . "\">" . $author . "</option>";
}
}
?>
</select>
</div><!-- #search1 -->
</form>
顺便说一句,当使用标准提交按钮显示结果时,该表单工作正常。 欢迎任何可能出错的提示。多谢!
I'm trying to submit a form without a submit button.
This form takes values from custom fields in wordpress, displaying results in another page. I've been trying with the usual javascript function onchange and nothing happens, I've tried with functions as well...does anyone know what's wrong with this or if is there a better way to solve it? Can it be something related to Wordpress, or the post method? This is the code for the form:
<form method="get" name="form" action="/busqueda/" >
<div class="search">
<select class="styled" name="author" onChange="this.form.submit();">
<option value="-1" selected>Authors</option>
<?php
$metakey = 'author';
$autores = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT meta_value FROM $wpdb->postmeta WHERE meta_key = %s ORDER BY meta_value ASC", $metakey) );
if ($authors) {
foreach ($authors as $author) {
echo "<option VALUE=\"" . $author . "\">" . $author . "</option>";
}
}
?>
</select>
</div><!-- #search1 -->
</form>
BTW, the form works fine when displaying results with a standard submit button.
Any hint of what can be wrong is welcome. Thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我希望您能够通过 $_GET 正确检索发布后的值,因为当我在浏览器中运行代码时,该值在 URL 中很好地传递。检查您的检索代码,确保您使用的是 $_GET 而不是 $_POST。
I hope you are retrieving the value after the post correctly through $_GET because when i ran the code in my browser, the value is passing on in the URL quite nicely. Check your retrieval code make sure you are using $_GET and not $_POST.
试试这个:
用 jQuery 提交更新
更新的表单:
jQuery 脚本更改事件处理和表单提交:
您可以从提交测试 jQuery下拉框更改事件
Try this one:
Updated with jQuery submit
The updated form:
jQuery script change event handling and form submit:
You can test the jQuery from submit on drop box change event