user3312792
user3312792

Reputation: 1111

using form to post one variable, how to add more variables to URL without using the form?

I have a form that submits the variable id

search.php?id=1

I have 2 defined variables that need to be added to this URL

search.php?id=1&definedvar=$definedvar&definedvar2=$definedvar2

I have tried adding a href to the button as a type button, this will only submit the defined variables

If the button is type submit it will only submit the id variable

how do I combine both?

Upvotes: 0

Views: 224

Answers (2)

Rohit Awasthi
Rohit Awasthi

Reputation: 686

<form method="GET" action="search.php">
<input name="id" value="1" />
<input type="hidden" name="definedvar" value="<?php echo $definedvar; ?>" />
<input type="hidden" name="definedvar2" value="<?php echo $definedvar2; ?>" />
<input type="submit" value="Submit" />
</form>

Upvotes: 0

SajithNair
SajithNair

Reputation: 3867

You can add any number of hidden inputs

<input type="hidden" name="definedvar1" value="<?php echo $definedvar1;?>"/>
<input type="hidden" name="definedvar2" value="<?php echo $definedvar2;?>"/>
<input type="hidden" name="definedvar3" value="<?php echo $definedvar3;?>"/>

If your form is POST you can also pass any number of GET parameters in action

<form action="search.php?definedvar=<?php echo $definedvar1;?>&definedvar2=<?php echo $definedvar2;?>">

Upvotes: 1

Related Questions