是否可以检查隐藏字段或文本字段后的形式


Is it possible to check Hidden field or text field in post of a form?

这可能吗?

我的问题是:

我有一个像这样的字段的表单:

<input type="hidden" id="chargetotal_reload_uk" name="chargetotal" value="12.01" />
<input type="text" id="name" name="name" value="xyz" />

和另一种形式:

<input type="hidden" id="chargetotal_reload_uk" name="chargetotal" value="12.01" />
<input type="text" id="name" name="name" value="xyz" />

print_r($_POST);

给我:

array(
 'chargetotal'=>'12.01',
 'name'=>'xyz',
);    

是否可以识别$_POST中的隐藏字段,即chargetotal是表单中的隐藏字段?

如上所述,您可能已经知道隐藏字段的名称,但是从技术上讲,您可以将字段类型与名称一起传入,然后在脚本中的$_POST键上爆炸。

<input type="hidden" id="chargetotal_reload_uk" name="charge total::hidden" value="12.01" />
<input type="text" id="name" name="name" value="xyz" />
PHP

<?php
$vars = array();
foreach($_POST as $key => $val){
    if(sibstr_count($key, '::') > 0){
        $key = explode('::'. $key);
        $vars[$key[0]] = array('fieldType' => $key[1]. 'value' => $val);
    } else {
        $vars[$key] = $val;
        // or $vars[$key] = array('fieldType' => ''. 'value' => $val); if you need to keep the same format
    }
}

根据您对用法的评论,您可以使用PHP sessions

你需要在$_SESSION['value'] = "12.01";中设置你的值才能工作。

<?php
session_start();
$_SESSION['value'] = "12.01";
?>
<?php
if (isset($_SESSION['value']) || !empty($_SESSION['value'])) { 
echo "The value is: " . $_SESSION['value'];
}
    else {
        echo "<div id='session_name'>No value set.</div>";
      }
?>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
    $(document).ready(function(){
var thevalue = "<?php echo $_SESSION['value']; ?>";
// alert (thevalue);
    });
</script>
<br><br>
<input type="hidden" id="chargetotal_reload_uk" name="chargetotal" value="<?php echo $_SESSION['value']; ?>" />
<div id="session_name">The value is: <?php echo $_SESSION['value']; ?></div>

HTML源代码/输出:

The value is: 12.01
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
    $(document).ready(function(){
var thevalue = "12.01";
// alert (thevalue);
    });
</script>
<br><br>
<input type="hidden" id="chargetotal_reload_uk" name="chargetotal" value="12.01" />
<div id="session_name">The value is: 12.01</div>