PHP - Send a GET Parameter by POST with formvalue [closed] - php

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.

Related

Display the value of form input [closed]

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 3 years ago.
Improve this question
I have a form with a input field like this:
<input type="hidden" id="name" name="name" value="">
Value of this input is changing trough some javascript function.
Now i would like to displays this value dynamicaly. For example:
<h1>This is the name: *input name value here*</h1>\
I know that you can use the value from different elements on a form when submiting, using the $_POST["name"]. But what about getting the value on same page dynamicaly.
<input type="text" id="name" name="name" value="" onblur="myFunction()">
<h1 id="fname"> </h1>
<script>
function myFunction() {
document.getElementById("fname").innerHTML = document.getElementById("name").value;
}
</script>

How to send data to another PHP file? [closed]

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'] ?>

Post and get method not show correct url [closed]

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 ;)

php post to variable and then append to txt [closed]

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 9 years ago.
Improve this question
I'm having this problem where I can't manage to accomplish this simple script. Basically, I want to take a post from a form, assign it to a variable, and then append the variable to a preexisting example.txt file. I apologize for the lack of examples, I switched to my phone after I went out to dinner with my inlaws. Could anyone post a simple example andd allow me to build off of that foundation? thanks in advance
The following should give you a foundation to start.
<?php
// Check to see if the form was submitted
if(isset($_POST['action']) && $_POST['action'] == 'add'){
$file = 'example.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
$current .= $_POST['test'];
// Write the contents back to the file
file_put_contents($file, $current);
}
?>
<form method="POST">
<!-- This becomes PHP variable $_POST['test'] -->
<input type="text" name="test" />
<input type="hidden" name="action" value="add" />
<input type="submit" value="Add"/>
</form>
Check out http://us3.php.net/file_put_contents for more information.
If your html form has a text field like this
<input type="text" name="firstName" value="Name">
you can access that value in your php script using
$_POST['firstName'];.
If you want to append text in php, you can simply do it using "."
Ex: $post_string = 'Ex:' . $post_string;

Dynamic function in php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Hello I am a beginner in php.
I've recently learned a bit about functions. But how do I dynamically insert data into the (). I've tried using get and post but that didn't work (Perhaps I just did something wrong). Any examples on how i could do it?
Thanks
action.php
<form action="action.php" method="post">
<p>Your name: <input type="text" name="name" /></p>
<p>Your age: <input type="text" name="age" /></p>
<p><input type="submit" /></p>
</form>
<?php
function myFunction($argOne, $argTwo) {
echo "inside function argOne=".$argOne;
}
if (isset($_POST['name']) {
//call the function only if the form is submited
myFunction($_POST['name'], $_POST['age']);
}
?>
I think you want to pass some data to your function
The post just send the data to your php page.
If you want to send some data to your function you should do that as a parameter.
Example:
$myvar = $_POST;
dumpData($data){
var_dump($data);
}
dumpData($myvar);
//OR
dumpData($_POST);
You can't just send the post to your function, you need to call that and use it as a param.

Categories