Night
Night

Reputation: 749

PHP Form URL vars

I was wondering if it would be possible to have a variable in the URL created when submitting a form?

form:

    <form class="register_form" action="action.php" method="get">
        Team Name*: <input type="text" name="teamname" required />
        Team Region*: <input type="text" name="teamregion" maxlength="4" required />
        Team Leader*: <input type="text" name="teamleader" maxlength="16" required />
        Team Members: <input type="text" name="teammembers"  />
        <input name="register_submit" type="submit" value="Register" />
    </form>

I'd like the link to end up as: http://.../action.php?do=register

My reasoning for this is so that I can use action.php for more than one thing using if statements. Thanks ^^

Upvotes: 0

Views: 60

Answers (4)

Tun Zarni Kyaw
Tun Zarni Kyaw

Reputation: 2119

Yes, it is possible. You can use any one of following methods

1) You can set the name of your submit button "do"; As the value of your submit button is "Register"

<input type="submit" name="do" value="Register" />

OR

2) You can add a hidden field to your form

<input type="hidden" name="do" value="register" />

Upvotes: 0

brgs
brgs

Reputation: 806

Just append the variable you want to the action link.

    <form class="register_form" action="action.php?do=register" method="get">
    Team Name*: <input type="text" name="teamname" required />
    Team Region*: <input type="text" name="teamregion" maxlength="4" required />
    Team Leader*: <input type="text" name="teamleader" maxlength="16" required />
    Team Members: <input type="text" name="teammembers"  />
    <input name="register_submit" type="submit" value="Register" />
</form>

Or you can add a hidden field to your form:

<input type="hidden" name="do" value="register" />

Upvotes: 1

bastienbot
bastienbot

Reputation: 123

You need to add this to the form

<input type="hidden" name="do" value="register">

Upvotes: 0

John Conde
John Conde

Reputation: 219874

Sure, the form action URL can have a query string:

<form class="register_form" action="action.php?do=register" method="POST">

The form data will be sent via POST but do will still be available via GET.

Upvotes: 0

Related Questions