doutang7661 2015-06-23 17:07
浏览 56

在wordpress中获取post方法不起作用

I have made a site in Wordpress.

In my front-page.php and in my index.php files I entered both post and get methods just to echo a message in page-message.php file.

When I click the subscribe button the posts page:news appears.The posts page:news is defined in my Wordpress settings: dashboard=>settings=>reading=>Front page displays=>a static page.

In page-message.php I wanted to show the data I had entered from this form. T

Code for the forms:

<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>

Code for page-message.php:

<?php
    $name = $_POST["name"];
    $email = $_POST["email"];
    echo 'Congratulations!You have been successfully subscribed to our newsletter' .$name .$email;                
?>

When I click the subscribe button my url changes to http://localhost/wordpress/page-message.php?name=stergios&email=something%40someone.com.

This seems to be correct when using the post method. The problem is the content!

It always loads the news (posts page from settings =>reading) and not the simple echo message?

It always shows the posts page when I write anything beyond my pages in the url. For example the url localhost/wordpress/hhhhhhhhhhh (a page that does not exist) does load the posts page and not a message error!

  • 写回答

2条回答 默认 最新

  • douji9816 2015-06-23 17:18
    关注

    I know the reason why it is not working.

    action="page-message.php"
    

    your static page's path should be /wp-content/themes/{themename}/page-message.php u can try it,

     action="<?php echo get_template_directory(); ?>/page-message.php"
    

    But I don't think it will work. You can try

     action="/index.php"
    

    It is untested. let me know if it work.

    Update: As you set that page as front page, then your wordpress root url will be that page's url (example.com or example.com/wpdirectory). Then simply do it,

    action="/"
    

    or

    action="/wpdirectory"
    
    评论

报告相同问题?

悬赏问题

  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题