如何基于Wordpress中的下拉菜单创建自定义URL-表单提交 [英] How to create a custom URL based on dropdown in Wordpress - form submission
问题描述
我需要根据从下拉菜单中选择的哪个选项在URL上附加一个单词,以创建自定义确认屏幕URL.我使用哪种联系方式都没关系(联系方式7,重力等).我一直在网上寻找有关此问题的解决方案,但发现可能有帮助的解决方案:
I need to apend a certain word to the URL based on which option from a dropdown is selected, to create a custom confirmation screen URL. It doesn't matter which contact form I use (Contact Form 7, Gravity, etc). I've been looking online for solutions to this and found one that may help:
header( "Location: http://mysite.com/result/?" . $_POST['dropdown_name'] );
但是我不确定放在哪里.在Contact Form 7的submissions.php中,我有以下内容:
but I'm not sure where to put it. In Contact Form 7's submissions.php, I have this:
<input type="text" name="submit" class="tag" readonly="readonly" onfocus="this.select()" />
我可以在这里使用它以某种方式基于所选的下拉值重定向到页面吗?我可以预定义要传递的URL值.
Could I use that in here somehow to redirect to a page based on the dropdown value selected? I am ok with pre-defining the URL values to be passed.
推荐答案
下拉列表是<select>
元素,而不是<input>
.
当然可以做到这一点,我建议为此做一个小插件,然后将重定向添加到init
操作中.
A dropdown is a <select>
element not an <input>
.
Of course this can be done I would recommend making a small plugin for this and adding the redirect to the init
action something like this.
<?php
/*
Plugin name: redirect on post
Desciption: http://stackoverflow.com/questions/13686245/how-to-create-a-custom-url-based-on-dropdown-in-wordpress-form-submission
*/
function redirect_on_submit() {
// check if the post is set
if (isset($_POST['dropdown_name']) && ! empty ($_POST['dropdown_name'])) {
header( "Location: http://mysite.com/result/?" . $_POST['dropdown_name'] );
}
}
add_action('init', redirect_on_submit);
将其添加到plugin文件夹中的新文件中,然后在plugin菜单中将其激活.
add this to a new file in the plugin folder and activate it in the plugin menu.
这篇关于如何基于Wordpress中的下拉菜单创建自定义URL-表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!