Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
There is a href tag:
Send
or a button (needs form tag)
<form action="file.php" method="GET">
<button type="submit">Send</button>
</form>
that will redirect to file.php URL.
I want to send id parameter to another PHP file. How do I do that?
==========================================================================
To send that data where must be provided input params (ex. hidden input) or in-url parameter.
ex.
<form action="file.php" method="GET">
<button type="submit">Send</button>
<input type="hidden" name="id" value="YOUR_ID"
</form>
or
Send
You want to transfer the id only to the next file? Use this in the first:
link_to_2
or
<form...>
<input name="id" type="hidden" value="1">
<button type="submit">btn_to_2</button>
</form>
And in your second file use this for both cases:
<?= $_REQUEST['id'] ?>
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
this is some stupid but i dont know.
How i can export the action to two differents sections from submit button?
I want the cancel button to take me to one page and the accept button to take me to another. How can I apply a conditional that takes different actions?
My buttons are Accept and Cancel...
<section>
<form action="/news">
<input type="submit" id="button" value="Accept"> <input type="submit" class="button2" value="Cancel">
</form>
</section>
<!doctype html>
<html>
<head>
</head>
<body>
<form action="submit.html">
<label for="name">Name</label>
<input type="text" name="name">
<label for="lastname">Last Name</label>
<input type="text" name="lastname">
<button type="submit" id="submit">submit</button>
<button type="cancel" formaction="cancel.html">cancel</button>
</form>
</body>
</html>
Basically with html you can make different action in form like this
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
So I have a page with 2 different PHP code
example;
<?php
blablabla...
?>
<?php
testtestest...
?>
and I have 1 form with 2 submit buttons but I dont know how I can link 1 button to execute php code 1 and the other button to execute php code 2.
Now the 2 buttons only execute php code 1 which is not what i want.
Give a name to your buttons, and check the name which is submitted :
<?php if (isset($_POST['submit_1'])) { ... } else if (isset($_POST['submit_2'])) { ... } ?>
<form action="" method="post">
<input type="submit" name="submit_1">
<input type="submit" name="submit_2">
</form>
First answer:
create two seperate forms
<form action="page1.php">
<input type=button name=button1>
</form>
<form action="page2.php">
<input type=button name=button2>
</form>
Answer after OP commented:
use a "hidden" field in HTML which will contain the button which is pressed (keep it simple and use a single number like 1 is button 1 and 2 is the other button)
You put a javscript function on both buttons that will change the value of this field when being pressed.
In your PHP Script page where you land if you press the button you just do
if ($_POST[hiddenfield]>1)
{//button1 is pressed
}else
{//button2 is pressed
}
if you need help with the hidden field or javascript, comment and I'll show you the code
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
NOTE: Possible duplicate question is not helpful, as it does not compensate for multiple options for different pages while also passing form information.
I need to take user input from the current page (for now, this is just a single text field), and there are three buttons. The three buttons are supposed to go to different pages respectively, but all three need the value from the text field to do their job.
Essentially, I need to "pass" the value from the text field to either of the three pages that the buttons should redirect to. Currently, the buttons are unable to redirect as I do not know how to do that.
This is my code thus far:
<html>
<body>
<form name="form" action="" method="post">
Name: <input type="text" name="name" value="<?php echo $name;?>">
</form>
<button type="button">button1</button>
<button type="button">button2</button>
<button type="button">button3</button>
</body>
</html>
No JavaScript please.
<?php
if(isset($_POST['button1'])){
$link='index_1.php?name='.$_POST['name'];
header('location:'.$link);
}elseif(isset($_POST['button2'])){
$link='index_2.php?name='.$_POST['name'];
header('location:'.$link);
} elseif(isset($_POST['button3'])){
$link='index_3.php?name='.$_POST['name'];
header('location:'.$link);
}
?>
<form action="" method="POST">
Name: <input type="text" name="name" value="">
<button type="submit" name="button1" value="button1">button1</button>
<button type="submit" name="button2" value="button2">button2</button>
<button type="submit" name="button3" value="button3">button3</button>
</form>
The page where a form leads to is defined in its action attribute of the formtag. Just write the filepath + filename into that attribute and after submitting, you'll be redirected to that page and can use the POST parameter values there.
But you'll need to add a submit button - one, not three, and as an input tag
Use the submit type, and the check the value for the submitted (or the name you want to put it) in the PHP file, if the value is "button1" do something, if its "button2" etc.
<form action="/action_page.php" method="POST">
Name: <input type="text" name="name" value="<?php echo $name;?>">
<button type="submit" name="submited" value="button1">button1</button>
<button type="submit" name="submited" value="button2">button2</button>
<button type="submit" name="submited" value="button3">button3</button>
</form>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
<form action="../index.php?option=com_rsform&formId=3" method = "get">
<input type="hidden" name='form[Name]' value="1">
<input type="submit" value="Submit">
</form>
and i need this result:
http://localhost/index.php?option=com_rsform&formId=3&form[Name]=1
but i get this result:
http://localhost/index.php?form%5BName%5D=1
where is the problem?
This seems to be expected behavior regarding form actions when a combination of action URL parameters and form fields are present, and at the moment I'm not finding anything in a spec which tells otherwise.
The practical solution seems to be to just put the values you want in the form itself:
<form action="../index.php" method="get">
<input type="hidden" name='option' value="com_rsform">
<input type="hidden" name='formId' value="3">
<input type="hidden" name='form[Name]' value="1">
<input type="submit" value="Submit">
</form>
Check this: submitting a GET form with query string params and hidden params disappear
The GET parameters of "action" are overwrited by the form. So, the answer of David is correct.
Other solution: make a POST form and keep your URL ;)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
i have a problem, i will send a POST with PHP but i will
send a GET Parameter with the form value:
<form action="/Eventsuche/" method="post">
<table>
<tr>
<td>
<input id="Headsucheort" name="Headsucheort" type="text" value="" />
</td>
<td>
<button type="submit" name="Submit" id="Headsuchestart" value="Headsuchestart">»</button>
</td>
</tr>
So, on submit he bring me to /Eventsuche/ but i would like to
go here: /Eventsuche/Value of Headsucheort
Thanks! :)
<button onclick="window.location.href='/Eventsuche/' + document.getElementById('Headsucheort').value">»</button>
Didn't test but
If you really must do it in PHP, add this to Eventsuch:
if ( isset($_POST['Headsucheort']) ) {
header('location:http://www.your-url.com/Eventsuche/'.$_POST['Headsucheort']);
exit;
}
I see two ways to the that.
first:
you can add your variable to the end of your action value such as: action="Eventsuche?var=somevalue"
and second one would be:
as a hidden input and even tho it is hidden, php will capture it on submit as in:
<input type="hidden" name="myvar_name" value="my_var_value" />
i think this should do it.