pass form input value to action - html

I have a page (module-access.php).
On the page I have a form with one text input field. I'd like to set whatever is typed in this field to be part of the form's action.
<form action="module-access.php?company=THE-USERS-INPUT" method="post" name="company" id="company">
Company Name: <input type="text" name="textfield" id="textfield">
<INPUT TYPE="submit" name="submit" VALUE="Go"></FORM>
Thanks

Just change the input name from textfield to company and the action type to GET
<form id="myform" action="module-access.php" method="GET">
Company Name: <input type="text" name="company" id="company">
<input type="submit" name="submit" value="Go">
</form>

Why? Does it matter whether it's passed in the POST or GET? You can always just use REQUEST.
If it does matter then you'll need to use JavaScript to modify the action before you POST the form. Not very hard to do.

Related

How can I hide the value from a input, so that the value is still accesable but won't be displayed?

I have a simple input form from the type submit and it contains the value $username:
<form action="index.php" method="POST">
<input class="submit" type="submit" name="submitbtn" value="'.$username.'">
</form>
How can I hide the value, so that it will not be displayed on index.php, but I still can access this value?
To hide fields in form from displaying change their type to hidden. Keep in mind that hidden field is just not displayed but anyone can read it/change it with browser devtools.
<form action="index.php" method="POST">
<input type="hidden" name="user_name" value="'.$username.'">
<input class="submit" type="submit" name="submitbtn" value="Submit">
</form>

Redirect to selected site with variable which i got

<form action="/subsite/" method="GET">
<input type="text" name="" placeholder="Your Nick">
<input class="button" type="submit" />
</form>
I want to redirect I mean it should looks like
www/subsite/text
What should I use ? POST ?
The method="get" means that the parameters (and values) will be sent in the query string (the stuff after the question mark in the URL). eg.
/subsite?input_field_name=input_field_value
In your case, the input field doesn't have a name, which will cause problems. You probably want something like this:
<input type="text" name="nickname" placeholder="Your Nick">
So if you submit this form:
<form action="/subsite" method="get">
<input type="text" name="nickname" placeholder="Your Nick">
</form>
Then after submitting, the browser will go to:
/subsite?nickname=value_of_nickname_variable
If you use a method="post", then the form data (variables) will be sent along in the request body, not the query string. There are other differences between get/post, but that's one of them :)
If you just want to do a simple redirect when clicking the button, you could use javascript instead, eg.: window.location.href='/my_url_path_here'

How do I add a query to a get request with HTML?

I have made this:
<form action="links.php" method="get">
<input type="text" name="link" value="" style="height:25px;length:0px;font-size:8pt;"><br>
Direct: <input type="submit"><br>
Show: <input type="submit">
</form>
Is there any way I can pass a parameter when I press a different button? When I click now it sends me to links.php?link= which is good, but I want to do so that if I click one of the buttons, it sends me to links.php?link=&up=no.
I think I found a solution but it uses javascript, I want to do it with HTML only.
If you're looking to add a parameter based on what submit button was pressed, you can add a name to each of them:
<form action="links.php" method="get">
<input type="text" name="link" value="" style="height:25px;length:0px;font-size:8pt;"><br>
Direct: <input type="submit" name="direct"><br>
Show: <input type="submit" name="show">
</form>
Pressing the direct submit button will give:
?link=&direct=...
Pressing the show button will give:
?link=&show=...
edit
In the event that you want to pass a specific value for each button (which isn't tied to it's text like a submit input is), use the button tag instead of the input tag and pass it explicitly:
<form action="links.php" method="get">
<input type="text" name="link" value="" style="height:25px;length:0px;font-size:8pt;"><br>
Direct: <button name="direct" value="foo">Submit</button><br>
Show: <button name="name" value="bar">Submit</button>
</form>
which would result in: ?link=&direct=foo and ?link=&show=bar

form action parameter not working

Test
<br><br>
<form action="index.php?page=test">
<input type="text" placeholder="enter text"> </input>
<button type="submit">Send</button>
</form>
Why is the link working correctly while the form gets me the url http://example.com/index.php? in the adress bar of the browser?
Every parameter i define in the action attribute is getting cut off
you have to use this code.
Test
<br><br>
<form action="index.php" method="get">
<input type="text" placeholder="enter text"> </input>
<input type="hidden" name="page" value="test">
<button type="submit">Send</button>
</form>
You are submitting a GET form. The data in the form will be expressed as a query string and replace the one in the URL in the action.
Move the data from the query string into hidden inputs inside the form.

Two submit buttons

I have two forms on a same page and I have two submit buttons...so how do I check if the user filled out the first form before clicking the submit button on second form? The first form posts the data to php page which presents on a same page as the html and the second form sends the data to another PHP page with thank you message....I mean how do force the user to finish the first form before clicking the submit button on the second form? if the user hits the submit button on the second form, the form directs to thank you page with out checking if the user finished the first form..how do I stop that?
<html>
<body>
<form action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="submited" value="true" />
<label for="file">Choose Photo:</label>
<input type="file" name="file" onchange="file_selected = true;" required>
<input type="submit" value="Submit" name="submit">
</form>
<form action="Send.php" method="post">
First Name:<input type="text" name="fname" required><br>
Last Name:<input type="text" name="lname" required><br>
Choose Username:<input type="text" name="username" required><br>
Age:<input type="text" name="age" required><br>
<input type="submit" value="Submit" name="submit">
</form>
You can change the name field and then access the value on the server side.
For example:
<input type="submit" value="Submit" name="submitOne" />
If you're using php you could use something like this:
if(isset($_POST['submitOne'])){ /* first one pressed */ }
There are also some other options like using jQuery or javascript to validate first.
Try: http://bassistance.de/jquery-plugins/jquery-plugin-validation/