Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to: question mark in form action

I want to use a button to link to a page. However, the page url is something like domain.com/page?action=register.

I really need this action added to my:

form action="domain.com/page?action=register"

Form attribute, but when I try it with these settings, it will only go to domain.com/page

I've tried encoding the ? into %3F but that doesn't work.

Any help?

like image 646
Daan Twice Avatar asked Jan 30 '12 02:01

Daan Twice


People also ask

What should I put in a form action attribute?

The HTML | action Attribute is used to specify where the formdata is to be sent to the server after submission of the form. It can be used in the <form> element. Attribute Values: URL: It is used to specify the URL of the document where the data to be sent after the submission of the form.

What is the action in form tag?

The action attribute specifies where to send the form-data when a form is submitted.

How do I add two actions to a form?

Let's learn the steps of performing multiple actions with multiple buttons in a single HTML form: Create a form with method 'post' and set the value of the action attribute to a default URL where you want to send the form data. Create the input fields inside the as per your concern. Create a button with type submit.


1 Answers

The ? values are set by the form, as long as the form's method is set to "get" (rather than "post", which doesn't submit the values in the URL). So, if you want to submit a form to page?action=register, you'd do the following:

 <form action="domain.com/page" method="get">
 <input type="hidden" name="action" value="register">

It will also pass the other form values along in the URL, creating something like:

domain.com/page?action=register&first_name=john&last_name=doe

EDIT: As @ninetwozero mentioned in a comment, the scenario you describe above should work:

<form action="domain.com/page?action=register" method="post">
[rest of form]

I just tested the above and it passed both the ?action=register and the form values from my form. So, whichever you prefer.

like image 136
Matt Stauffer Avatar answered Sep 30 '22 06:09

Matt Stauffer