使用php传递隐藏的输入值

Plu*_*uto -3 php forms

单击"提交"时,代码应显示函数中的值.以下是代码:

  <form method="post">
  <input type="hidden" name="HDN_FormClicked" value= <?php echo $clicked ?> />
   <?php 
   if($_POST){
     $clicked= "You have clicked the button";}
     ?>
  <input class="button" type="submit"/>
  </form>
Run Code Online (Sandbox Code Playgroud)

我是否需要使用$ _get来使代码工作?

Kys*_*lik 7

<?php 
    if(isset($_POST['submit_button']))
       $clicked = 'You have clicked the button';

?>

<form method="post">
<input type="hidden" name="HDN_FormClicked" value="<?php echo (isset($clicked)) ?  $clicked : '' ?>" />
<input class="button" name="submit_button" type="submit"/>
</form>
Run Code Online (Sandbox Code Playgroud)

替代

<?php 
    $clicked = '';

    if(isset($_POST['submit_button'])) 
       $clicked = 'You have clicked the button'; 
?>

<form method="post">
<input type="hidden" name="HDN_FormClicked" value="<?= $clicked?>" />
<input class="button" name="submit_button" type="submit"/>
</form>
Run Code Online (Sandbox Code Playgroud)