E.D.A E.D.A - 8 days ago 5
PHP Question

Form to add variables in addition to existing

I'm creating a simple form which when filled out, it will add the variable and form content to the end of

https://www.example.com/clients/cart.php?a=add&pid=91


So the aim is to have a form with variable name
sld
and then adds this to the end of the above URL, so that it becomes
https://www.example.com/clients/cart.php?a=add&pid=91&sld=CONTENT


However, the form (code below) ignores the existing variables and simply defaults to
https://www.example.com/clients/cart.php (eg. cart.php?sld=CONTENT
.

Is there a way to keep the existing variables and submit the form content at the end of the provided URL?

<form action="https://www.example.com/clients/cart.php?a=add&pid=91" method="get">
<input type="text" name="sld" placeholder="google">.
<input type="text" name="tld" placeholder="com">
<input type="submit" value="submit">
</form>

Answer

You can add two hidden fields with the value:

<form action="https://www.example.com/clients/cart.php" method="get">
    <input type="text" name="sld" placeholder="google">.
    <input type="text" name="tld" placeholder="com">
    <input type="submit" value="submit">
    <input type="hidden" name="a" value="<?php echo $_GET['a']; ?>">
    <input type="hidden" name="pid" value="<?php echo $_GET['pid']; ?>">
</form>