How to pass own variables on form without using input

问题: want to submit a form with name and quantity but i want to pass a get variable to the form without input. When the form is submitted the get variable for quantity is pass b...

问题:

want to submit a form with name and quantity but i want to pass a get variable to the form without input. When the form is submitted the get variable for quantity is pass but i want also to pass the name quantity which is displayed already. Can i do this either through action="site.php?name=theName" or how can i do this.

"<"form action='site.php?name={$name_row['name']}' method='GET'>


回答1:

Using GET method in forms is not recommended, maybe you want to use hidden inputs?

<form action='site.php' method='POST'>
  <input type="hidden" name="name" value="<?=$name_row['name']?>">
</form>

You can use it with GET too


回答2:

If you don't want the variable passed to be displayed, you can use a hidden input:

<input type="hidden" name="name" value="<?php echo $_GET['name'] ?>"/>

If you don't want to use any input, of course you can pass them in form action:

<form action="somewhere.php?name="<?php echo $_GET['name'] ?>" method="post">

回答3:

You have 3 most popular methods

i. Input type hidden

<input type='hidden' name='name' value='<?=$variabel?>'>

ii. Add on form GET method

<form action='site.php?xyz=<?=$variabel?>'>

</form>

iii. User $_SESSION

<?php $_SESSION['xyz'] = variabel; ?>
  • 发表于 2019-04-01 11:32
  • 阅读 ( 180 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除