Ale*_*lex 2 php forms post scope include
我无法从我的php文件中获取从html表单发送的$ _POST ['name']值.我见过很多类似的问题,但没有任何帮助.我有很多包含,所以我认为这是一个范围问题,但我无法弄明白.
的index.php
print_r($_POST); //Returns nothing, tried other ways too
//lot's of variables being defined
include 'sql_data_handlers.php';
//instantiating some things
Run Code Online (Sandbox Code Playgroud)
sql_data_handlers.php
//some functions retrieving data from sql db and finally:
include($DOCUMENT_ROOT . "page.html");
Run Code Online (Sandbox Code Playgroud)
page.html中
//html stuff
<?php
//Some conditions
include($DOCUMENT_ROOT . "comment_form.html");
?>
Run Code Online (Sandbox Code Playgroud)
comment_form.html
<form action="index.php" name="comment_form" id="comment_form" method="post">
<input type="text" name="name" value="Anonymous" required><br>
//lot's of inputs
<input type="submit">
</form>
Run Code Online (Sandbox Code Playgroud)
我以前有,action="send_comment.php"但我意识到它可以变成一个函数,所以我ctrl + c并适应send_comments.php一个函数sql_data_handlers.php.问题是,现在我无法获取要在函数中使用的$_POST值(包括在内).index.phpsql_data_handlers.phpindex.php
我会使用,action="my_php_function_from_data_handlers.php($args)"如果有可能,但我想它不是.顺便说一下,我已经试过了action="".这可能看起来很乱,但这样我只需要一个.html用于站点布局,页面在sql上,而.php文件可以完成所有工作.
所有文件的完整来源(非常大,仍在使用它):http: //pastebin.com/2nRuCpNx
确保您没有任何重定向,因为您使用index.php来保存数据,您可能正在重新加载页面以显示更新的注释.如果你正在重新加载,那么print_r()上就没有关于$ _POST的数据.