Old data gets wiped from POST when I use GET - php

So I am having an issue. I used POST to send data to a new page. I use get to send data to a function but it seems the POST data get wiped. Here some code to help explain.
POST CODE to send to form vieworder (works perfect!)
<form method="post" action="vieworder.php">
<input type="hidden" name ="user_id" value="<?php echo $_SESSION['user_id']; ?>">
<input type="hidden" name ="id" value="<?php echo $data1[$x]['id']; ?>">
<input type="submit" name="submit" value="View"> </td>
</form>
So on the vieworder page I want used to be able to update the data using this form.
This form works as well except i need that value "id" from the orginal post. It works and the "id"has the data until I use this form.
<form name="approveform" method="get" action="">
Index Number*: <input type="text" name="IndexNum">
<input type="submit" value="Approve" action="">
</form>
I would also prefer to use the POST method but using GET was my first solution to no deleting the data from POST.
Anyways I then just send the data to a function to update two fields.
Any way to get correct the code?

<?php
$id=$_POST['user_id'];
?>
<form name="approveform" method="get" action="">
Index Number*: <input type="text" name="IndexNum">
<input type='hidden' value='<?php echo $id;?>'>
<input type="submit" value="Approve" action="">
</form>

Related

variables containing Post elements get empty after another post called

i have a problem keeping a post element in variables before calling one more time post in a second form .
briefly:
variable below contain elements from previous post
$img=isset($_POST['image'])?$_POST['image']:false;
$table=isset($_POST['tabl'])?$_POST['tabl']:false;
Then i have as next to the lines above the form below :
<form method="post" action="" style="padding-top:200px;padding-bottom:200px;padding-left:500px">
<div><span>Email</span></div> <input type="text" value="" name="user"/><br><br>
<div><span>Password</span></div> <input type="password" value="" name="pass"/><br><br>
<input type="submit" value="send" name="submit"/>
</form>
and right after pressing submit $img and $table are both empty .
how can i keep the values in $imgand $table even after calling post again ?
any clue ?
Thanks
You aren't sending the variables you want in the POST data in your second form.
You could use a hidden field to send it,
A bit like this.
<form method="post" action="" style="padding-top:200px;padding-bottom:200px;padding-left:500px">
<input type="hidden" name="img" value="<?php echo $img;?>" />
<input type="hidden" name="table" value="<?php echo $table;?>" />
<div><span>Email</span></div> <input type="text" value="" name="user"/><br><br>
<div><span>Password</span></div> <input type="password" value="" name="pass"/><br><br>
<input type="submit" value="send" name="submit"/>
</form>

Wordpress form posting

I am facing a problem while self posting form data, when I hit submit button the page should display the data inserted in the input box,
but it does not show the data....
Here is my example form
<?php
if($_SERVER['REQUEST_METHOD']=='POST')
{
$mail = $_POST['mail'];
echo $mail;
}
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="myForm">
Mail : <input id="mail" name="mail" type="text"/>
<input type="submit" value="Submit"/>
</form>
This should obviously display the mail value from the input box. But it does not work. Then I tried to change the action attribute value to "mywordpress/index.php/customer-details-2/"
Since I am new with Wordpress, any help would be highly appreciated.
Add the posted value in your input text box as :
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" name="myForm">
Mail : <input id="mail" name="mail" type="text" value="<?php echo (isset($_POST['mail'])) ? $_POST['mail'] : '' ?>" />
<input type="submit" value="Submit" />
</form>
I am assuming that you want to show data inside input text box.
Hope it helps you.

Php get method resseting url

i am submitting form using get method to a url which already contain parameter like
localhost/myfile.php?section=console
my form code is
<form method="GET" action="<?=basename($_SERVER['PHP_SELF'])?>/section=console">
<input type="text" name="cmd" />
<input type="submit" value="execute" />
</form>
when i submit this data through post type it submit data then it submit like myfile.php?cmd=blahblah
but i want to submit it to myfile.php?section=console&cmd=blahblah.
i can do this by using hidden field but i am insearch of other better way
Simply add a hidden field into your form
<input type="hidden" name="section" value="console">
If you are not interested in using hidden fields then rewrite your form like this
<form method="GET" action="<?php basename($_SERVER['PHP_SELF']) ?>/?section=console">
You should use a hidden input within your form
<form method="GET" action="<?php echo basename($_SERVER['PHP_SELF']); ?>">
<input type="hidden" name="section" value="console">
<input type="text" name="cmd">
<input type="submit" value="execute">
</form>

Having Two Self Submitting Forms

Is it possible for me to have two self submitting forms on a single page. If yes how do I allot different blocks of code to each form ?
Have a hidden input with two different values.
<form action="" ...>
<input type="hidden" name="form_no" value="0">
...
</form>
<form action="" ...>
<input type="hidden" name="form_no" value="1">
...
</form>
On the server side, different on the basis of $_REQUEST['form_no']
Or you could also add it as a name parameter in submit element.
<input type="submit" name="form0">
Use isset($_REQUEST['form0']) to differentiate.
Another way of doing it is to append a GET parameter to differentiate
<form action="<?php echo $_SERVER['PHP_SELF'];?>?form_no=0" ...>
...
</form>
<form action="<?php echo $_SERVER['PHP_SELF'];?>?form_no=1" ...>
...
</form>
Use $_GET['form_no'] to differentiate.
Name your first form form_one, and the second form form_two.
<?php
if (isset($_POST['form_one'])) {
// First form was submitted
}
if (isset($_POST['form_two'])) {
// Second form was submitted
}
?>
Two forms can be placed in a code by giving them different names and keeping their target _blank
<form action="action.asp" method="get">
First name: <input type="text" name="fname" /><br />
Last name: <input type="text" name="lname" /><br />
<input type="submit" name="submit1" value="Submit" />
</form>
<form action="action.asp" method="get">
First name: <input type="text" name="fname" /><br />
Last name: <input type="text" name="lname" /><br />
<input type="submit" name="submit2" value="Submit" />
</form>
<?php
if(isset($_GET['submit1'])){
// first form was submitted
}
if(isset($_GET['submit2'])){
// second form was submitted
}
?>
Each form has a different script specified in this example, but keep in mind that you can simply use the same php file for both actions, specifying a different block of code for each form (that's the php part above).
Someone may have a better answer, but this method has served me well in the past.

how to pass values from one page to another on jquery form submit

I'm trying to build a form using php & jquery, but I'm a little confused as to what to do with the jquery portion of it...
Basically, when the user submits the first form, I want to direct them to the "next step" form, but I want to retain the values submitted from the first one in a hidden input field...
If someone can either show me how or point me to a good tutorial, I'd appreciate it...
I don't have any of the php or jquery yet, and this is just a simplified version of the html markup...
//first.php
<form name="form1" method="post" action="second.php">
<input type="text" name="name" value="" />Name
<input type="submit" name="step1" value="Next" />
</form>
//second.php
<form name="form2" method="post" action="process.php">
<input type="hidden" name="name" value="{$_POST['name']}" />
<input type="text" name="message" value="" />message
<input type="submit" name="step2" value="Finish" />
</form>
<input type="hidden" name="name" value="{$_POST['name']}" />
should be,
<input type="hidden" name="name" value="<?php echo $_POST['name']}; ?>" />
and also sanitize the input, if you want
I don't no if there is a better way to do that.
But, when I need to do such thing, I do in this way:
<script>
<?php
foreach($_POST as $key => $valule)
{
echo "$('$key').val('$value')";
}
?>
</script>
So, in your nextstep file, all you'll need to do is set up the hidden fields and then just loop through the post vars and set each one via jquery.

Categories