[英]is it possible to read the action value of a form with php?
I'm wondering if there's a way to read, or extract, the value from the action parameter of a form tag in php? 我想知道是否有一种方法可以读取或提取php中表单标签的动作参数值?
<form name="..." method="post" action="*this*">
This code return each value of each element inside the form, but not from the form
-tag itself: 这段代码返回表单内每个元素的每个值,但不是从
form
-tag本身返回:
foreach($_POST as $_FORM_value){
$_FORM_values[] = $_FORM_value;
}
Any ideas? 有任何想法吗?
Now I'm just using a hidden field to execute the correct script: 现在,我只是使用一个隐藏字段来执行正确的脚本:
<input type="hidden" name="load-script" value="ScriptName" readonly>
And at the very top, before hta page is starting to load and any html is sent to the client, I'm checking to se if any form has been submittet: 最重要的是,在hta页开始加载并将任何html发送到客户端之前,我正在检查是否已提交任何表单:
if(isset($_POST['load-script'])){include dir_setup.'post.exec.php';}
And inside post.exec.php : 在post.exec.php内部:
# get name from submit-button
foreach($_POST as $_FORM_ELEMENT_name=>$_FORM_ELEMENT_value){
if (!strncmp($_FORM_ELEMENT_name,'submit_',7)){
$_FORM_ELEMENT_submit_name=explode('_',$_FORM_ELEMENT_name);
$_FORM_name=$_FORM_ELEMENT_submit_name[1];
}
}
//
# fetch script
if(empty($_POST['load-script'])){
$_SITE_notices[] = '<code><b>load-script</b></code> in <code><b>'.$_FORM_name.'</b></code> is empty.';
}else{
$_FORM_SCRIPT=$_POST['load-script'].'.script.php'; // script to search for.
if(file_exists(dir_scripts.$_FORM_SCRIPT)){ // check locally first.
include dir_scripts.$_FORM_SCRIPT; // include script from local folder - if found.
}else{ // script was not found locally.
if($_SITE_FRAMEWORK){
if(file_exists(ROOT_FRAMEWORK.dir_scripts.$_FORM_SCRIPT)){ // check framework.
include ROOT_FRAMEWORK.dir_scripts.$_FORM_SCRIPT; // include script from framework - if found.
}else{ // script was not found in either directory; quit searching and throw error.
$_SITE_notices[] = 'Could not locate <code><b>'.$_FORM_SCRIPT.'</b></code> in either <code><small><ROOT></small><b>/'.dir_scripts.'</b></code> or <code><small><FRAMEWORK></small><b>/'.dir_scripts.'</b></code>';
}
}else{ // framework is not activated; quit searching and throw error.
$_SITE_notices[] = 'Could not locate <code><b>'.$_FORM_SCRIPT.'</b></code> in <code><small><ROOT></small><b>/'.dir_scripts.'</b></code>';
}
}
}
//
My idea was to eliminate the need for the hidden load-script element, and just use the form action value to determen which script to load. 我的想法是消除对隐藏的load-script元素的需要,仅使用form action值确定要加载的脚本。 But that might not be possible?
但这可能不可能吗?
The action
defines the url of the script to be called. 该
action
定义了要调用的脚本的URL。 Therefore You can see all action's details in some $_SERVER
variables - maybe $_SERVER['PHP_SELF']
and $_SERVER['QUERY_STRING']
will be useful for You. 因此,您可以在某些
$_SERVER
变量中查看所有操作的详细信息-也许$_SERVER['PHP_SELF']
和$_SERVER['QUERY_STRING']
对您很有用。
No, by its very definition submitting a form only serializes all the values of the form
in question and sends those to the server by the defined method
. 不,就其定义提交表单只序列中的所有值
form
问题,并将由定义的那些服务器的method
。 In PHP you can check exactly what is in a postback with: 在PHP中,您可以使用以下命令检查回发中的内容:
var_dump($_POST); // assuming POST method
No other data from your HTML is returned whatsoever. HTML不会返回任何其他数据。
Relevant section in the HTML5 standards to be found here , specifically the form data set construction logic . 在此处可以找到HTML5标准中的相关部分 ,尤其是表单数据集的构造逻辑 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.