Search page looks like this
<form method="post" action="response.php">
<input type="text" name="varianta" value="var_varianta">
<input type="submit">
</form>
<?php
session_start();
$var_varianta= $_POST['varianta'];
?>
The response page has the below line code:
$filters[] = array("filterType" => "resultLimit", "filterValue" => "varianta");
How i can i enter tn the "filterValue" => "**varianta**"); the $var_varianta that is inputed in the search field
Thanks
It's not clear what you're asking, but it seems like there's some confusion. $_POST contains the values that have been submitted, not the values that a user is entering. So, $_POST variables are set on the action page, not on the page showing the form. You can't set a $_POST variable in PHP on the page showing the form and expect the action page to know about that.
If I understand your question correctly, you should use $_POST['varianta'] on the action page to access whatever was submitted.
Related
I've already tried this stuff
$item=$_POST($val['item_id'])
And
$item=$_POST[$val['item_id']]
Any Idea on how to Post my inputted data ?
$_POST isn't a function, it is a special PHP array that reflects the data submitted from a form. So, the second line you got there can work only if the $val['item_id'] has a valid post name key. You should always first check if that key actually exists in the $_POST data array by using isset function like this:
if (isset($_POST[$val['item_id']]) {
$item = $_POST[$val['item_id']];
}
To debug and see all $_POST data, use this code:
<pre><?php
print_r($_POST);
?></pre>
1) form.html
Make sure your form uses POST method.
<form action="submit.php" method="post">
<input name="say" value="Hi">
<input name="to" value="Mom">
<input type="submit" value="Submit">
</form>
2) submit.php
var_export($_POST);
Will result in:
array (
'say' => 'Hi',
'to' => 'Mom',
)
$_POST is not a function, but an array superglobal, which means you can access submitted data thus:
print $_POST['field_name']
using codeigniter mvc pattern I create form in view that take only two values form user
<form action="<?php base_url(); ?> blogs/new_post" method="POST">
<label>Title</label>
<input type="text" name="post_title" />
<label>discription</label>
<input type="text" name="post_detail" />
<input type="submit" value="post" />
</form>
now when i submit the form, data goes to the controller now here confusion created in my code that i can't able to understand i use three cases in controller fist is if i use !empty($_POST) in controller and in view weather i fill the form or not fill the form message displayed in controller is post
my question is why always displaying post why not displaying not a post when i fill nothing in the form
if(!empty($_POST)) {
echo "post";
} else {
echo "not a post";
}
my second question is same related to the first condition now i use isset instead of !empty
public function new_Post() {
if(isset($_POST)) {
echo "post";
} else {
echo "not a post";
}
}
in this case either i fill form or not fill form when i submit the form the result always same that is "post"
and in third case if i use !isset the the result is always not a post eiter i fill or not fill the form
hope so you will understand my problem when i comes to if(!empty($_POST)) this condition then my mind is confuse what is the purpose of $_post
This is because you are using the whole global variable $_POST to check empty and isset(). $_POST is not empty when you click on the button. You just Print_r the $_POST it will have the value of submit button. You need to print the value of $_POST on click and see the values in the array
Well, in CodeIgniter (and most of the framework) doesn't allow you to access $_POST directly due to security reason.
You must access $_POST values through $this->input->post()
For more information read Input Class from CodeIgniter's docs
https://www.codeigniter.com/user_guide/libraries/input.html
$_POST is exist when you click on the button:
so empty and isset cant work Correctly
the value at the first is
Array
(
)
SO U should check
if($_POST)
instead
if(!empty($_POST)) OR if(isset($_POST))
AND best way is u check
if ($this->input->post())
I am having bad time getting SESSION to work in PHP.
I have a form the following action:
<form action="confirm.php" method="post">
And that has a button as such:
<button type="submit" id="submit">Proceed</button>
I have got session_start(); on all my pages. After the form button, I have this code:
<?php
if(!empty($_POST['submit']))
{
$_SESSION['name'] = $_POST['name'];
$_SESSION['address'] = $_POST['address'];
$_SESSION['strtnum'] = $_POST['strtnum'];
$_SESSION['height'] = $_POST['height'];
}
?>
On confirm.php I've got this:
<?php
print_r($_SESSION);
print_r($_POST);
?>
The POST array has correct values but the SESSION array is completely empty with no variables or values at all.
I would like help understanding how fix this.
Thank you.
EDIT: I'm quite sure that the code doesn't actually reach the inside of the if statement. I added an echo in there to print an alert (yes I used ) and it doesnt work. So I'm not 100% sure that it enters the if(!empty($_POST['submit']))
<form action="confirm.php" method="post">
^^^^^^^^^^^^^^^^^^^^
Your form is being submitted to confirm.php, thats where you should handle the $_POST and fill the $_SESSION values. Instead you are trying to do it in the same page that prints the form, but thats doing no good there because its not where the form data is being submitted to.
I have a form, which redirects the user to "page1.php" after the form is submitted. What I want to do is to redirect the user to "page2.php" after the form is submitted, but I need to make sure that the POST request was sent. Example:
<form action="page1.php" method="POST">
<input type="text" name="username" />
<input type="text" name="age" />
<input type="submit" value="" />
</form>
When the user clicks on Submit, it redirects him to page1.php. I want to redirect him to page2.php, but I need to make sure that the data is sent to the server. I can't use AJAX. Is there any way to do it with cURL or something like that? Any examples?
Thanks!
I guess this works !!
In page1.php
<?php
//do establish session
//and check for the input fields obtained via $_POST
if(isset($_POST['name_of_your_field']) && !empty($_POST['name_of_your_field'])){
if(!mail($to,$subject,$message)){
header('location:form.php?msg=error');
}else{
header('location:page2.php?msg=succes');
}
}
?>
You can check if the POST request was sent with something like:
if($_SERVER['REQUEST_METHOD'] == 'POST') {
// do something...
}
You can create a hidden input in your form and send additional info about the form that is submitted, e.g. action.
Inside you will do your magic and redirect user with:
header('Location: page2.php');
exit();
In your 'page1.php' processor, add a 'header' redirect to 'page2.php'.
header("Location: page2.php");
exit;
you could do a check if query is complete
example
<?php
$query=mysqli_query(".......your query statement")or trigger_error(mysqli_error());
if($query){
header("Location:page2.php");
}
else{
die('error');
}
?>
In your situation, you can just simple check for the posted data. Like
$username = $_POST['username'];
$age = $_POST['age'];
if($username&&$age){ /* This is to check if the variables are not empty */
// redirect to page2
}
It is logical that if those are not empty, meaning they are posted. Even if they are empty, as long as you get there, that means it was posted. There is no need to check if posted or not, what needs to be checked was, if posted data was there.
I hope I made it clear. ^_^ but making sure is not bad at all. Happy coding friend.
I'm wondering if it's possible to manually change the value of an isset value. That is, to do something like this:
isset($_POST['search_user']) = true;
Why I want to do this: I have two different "submit" forms on one page. When one form is submitted, I want to capture all the values of that form into SESSION variables. However, when the other form is submitted, the SESSION variables are wiped out (since the first form is not, technically, submitted anymore).
My idea was that, if the second form is submitted, then automatically set the value of the first form to true
If I understand your question correctly, if a second form is submitted, why not just destroy the current session and start new sessions using the variables posted from the new form?
http://php.net/manual/en/function.session-destroy.php
session_destroy();
...Or, you can set another session variable if the second form is submitted:
if (isset($_POST['search_user'])) {
$_SESSION['search_user'] = "true";
}
if ($_SESSION['search_user'] == "true") {
// Second form was submitted
}
You can try to define a name and a value for each submit button, so you retrieve this in the PHP file and do what you want, according you need. For instance:
HTML to the first form:
<form name="form1" action="page2.php" method="post">
<input type="submit" value="1" name="button01">
</form>
HTML to the second form:
<form name="form2" action="page2.php" method="post">
<input type="submit" value="1" name="button02">
</form>
Then you can detect the form thas was submited doing this in page2.php:
if($_POST['button01'] == "1")
{
// Do what you need based on form1 submit
}
elseif($_POST['button02'] == "1")
{
// Do what you need based on form2 submit
}
Try this and then leave some comment telling if it helps you.