字preSS改写基于表单的隐藏字段 [英] WordPress Rewrite based on form hidden field

查看:89
本文介绍了字preSS改写基于表单的隐藏字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有什么是一种形式:

<form method="POST" action="/path1/path2/">
<input type="hidden" name="usr" value="firstname-lastname">
<input type="image" src="/pathtoimage/image.jpg" alt="Submit Form" />
</form>

在表单提交/路径1 /路径/名字 - 姓氏获得附加到URL的到底是什么,我想是的,所以我结束了/路径1 /路径/名字 - 姓氏。在大多数情况下,我可以做什么用的.htaccess重写规则,但是这道preSS所以我得到的是一个404我应该从哪里开始呢?我看到一些帖子指向的变化functions.php文件,但我似乎无法得到任何工作。

What I would like is once the form is submitted to /path1/path2/ firstname-lastname get appended to the end of the url, so I end up with /path1/path2/firstname-lastname. In most cases I could do something with a .htaccess rewrite rule but this is WordPress so all I get is a 404. Where should I start? I see some posts that point to changes in the functions.php file but I can't seem to get anything to work.

您的帮助是非常AP preciated。

Your help is much appreciated.

推荐答案

一个替代方法.....你需要建立一个URL重定向到。你尝试的方式的问题是,WP显然试图解决你给它的地址。如果你想克服这一点,你可以设置一个重写规则相匹配路径1 /路径(见ltasty回答上面是否存在在数据库中的网页,或点击这里<一href="http://stackoverflow.com/questions/25238480/add-custom-page-without-page/25239381#25239381">Add &QUOT;自定义页面&QUOT;没有页面,如果你想跳过数据库的条目)

a alternative way.....you need to build a url to redirect to. The problem with the way you are trying is that wp will obviously try and resolve the address you give it. If you want to overcome this you can set a rewrite rule to match path1/path2 (see ltasty answer above if your page exists in the db or here Add "custom page" without page if you want to skip the db entry)

一旦你有一个排序,你可以建立URL路径1 /路径/名称,并重定向到它收到或你当然可以再次改变形式的行动路径1 /路径,并从那里重定向到自身$ _ POST的时候。

Once you have that sorted you can build the url path1/path2/name and redirect to it when $_POST is received or You could of course change the form action to path1/path2 again and redirect to itself from there.

<?php
if($_POST):
  $name=sanitize_text_field($_POST['usr']);
  $url= get_site_url().'/path1/path2?name='.$name;// using query var method..change if you decide to use the rewrite rule. 
  wp_redirect($url);
  exit();
endif;

?>
<form method="POST" action="#">
<input type="hidden" name="usr" value="firstname-lastname">
<input type="image" src="/pathtoimage/image.jpg" alt="Submit Form" />
</form>

您可以使用 $ _ SERVER ['REQUEST_URI'] 拉URL和str_replace转换你不需要的部分。

you can use $_SERVER['REQUEST_URI'] to pull the url and str_replace the part you dont need

这篇关于字preSS改写基于表单的隐藏字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆