Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在wordpress中,get post方法不起作用_Php_Html_Wordpress - Fatal编程技术网

Php 在wordpress中,get post方法不起作用

Php 在wordpress中,get post方法不起作用,php,html,wordpress,Php,Html,Wordpress,我已经在Wordpress上建立了一个网站 在我的front page.php和我的index.php文件中,我输入了post和get方法,以便在page message.php文件中回显消息 当我点击订阅按钮时,会出现postspage:news。postspage:news在我的Wordpress设置中定义:dashboard=>settings=>reading=>FrontPage显示=>静态页面 在page message.php中,我想显示从该表单输入的数据。T 表格代码: <

我已经在Wordpress上建立了一个网站

在我的
front page.php
和我的
index.php
文件中,我输入了post和get方法,以便在
page message.php
文件中回显消息

当我点击订阅按钮时,会出现posts
page:news
。posts
page:news
在我的Wordpress设置中定义:dashboard=>settings=>reading=>FrontPage显示=>静态页面

page message.php
中,我想显示从该表单输入的数据。T

表格代码:

<h2>Sign to Newsletter</h2>
<form action="page-message.php" method="post">
    Name:<input class="input" type="text" name="name" value=""/><br/>
    Email:<input type="text" name="email" value=""/>
    <br/><input class="submit" type="submit" value="Subscribe"/>
</form>
<?php
    $name = $_POST["name"];
    $email = $_POST["email"];
    echo 'Congratulations!You have been successfully subscribed to our newsletter' .$name .$email;                
?>
登录新闻稿
名称:
电邮:
页面消息的代码。php:

<h2>Sign to Newsletter</h2>
<form action="page-message.php" method="post">
    Name:<input class="input" type="text" name="name" value=""/><br/>
    Email:<input type="text" name="email" value=""/>
    <br/><input class="submit" type="submit" value="Subscribe"/>
</form>
<?php
    $name = $_POST["name"];
    $email = $_POST["email"];
    echo 'Congratulations!You have been successfully subscribed to our newsletter' .$name .$email;                
?>

当我点击订阅按钮时,我的url变为
http://localhost/wordpress/page-message.php?name=stergios&email=something%40someone.com

使用post方法时,这似乎是正确的。问题在于内容

它总是加载新闻(posts页面从settings=>reading),而不是简单的回显消息


当我在url中写入页面以外的内容时,它总是显示posts页面。例如,url
localhost/wordpress/hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

我知道它不起作用的原因

action="page-message.php"
静态页面的路径应该是
/wp content/themes/{themename}/page message.php
你可以试试

 action="<?php echo get_template_directory(); ?>/page-message.php"
这是未经测试的。让我知道它是否有效

更新:当您将该页面设置为首页时,您的wordpress根url将是该页面的url(example.com或example.com/wpdirectory)。那就干脆去做,

action="/"

如果“page message.php”是主题中的自定义模板,则可以通过以下查询获得分配给它的页面ID:

$get_message_pageId = new WP_Query(array(
    'post_type'  => 'page',
    'meta_key'   => '_wp_page_template',
    'meta_value' => 'page-message.php'
));
然后,您可以使用以下设置操作:

action="<?php echo esc_url( get_permalink( $get_message_pageId->posts[0]->ID ) ); ?>"
action=“”

因此,您的表单中始终会有正确的URL,但只有当您有一个指定了此模板的页面时,它才会起作用。

不,它不起作用!我试过只尝试
index.php
/
我选中了
$\u get[]
方法,它以这种方式工作。我不想将我的page-message.php设置为自定义模板。但如果我是说我必须用这一页制作另一个自定义模板?因为我有一个自定义模板。我创建了一个页面消息,在仪表板中单击查看页面时,url是正确的,没有php扩展名。但是如果我进入首页,把数据放在我的表格中,正如我在上面的评论中提到的,url是不正确的。