Fer
Fer

Reputation: 31

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 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'>

Upvotes: 0

Views: 3185

Answers (3)

Shiv Singh
Shiv Singh

Reputation: 7201

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; ?>

Upvotes: 0

Seah Sky
Seah Sky

Reputation: 154

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">

Upvotes: 0

Snickfire
Snickfire

Reputation: 512

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

Upvotes: 1

Related Questions