pass value from page 1 to page 2 and display the value - php

this my id num column with a value
<td>ID NUMBER:</td>
<td><input type="hidden" name="txtEmpID" value="<?php echo $this->getArr['id']?>">
<input type="text" <?php echo (isset($this->postArr['EditMode']) && $this->postArr['EditMode']=='1') ? '' : 'disabled'?> name="txtEmployeeId2" value="<?php echo (isset($this->postArr['txtEmployeeId']))?$this->postArr['txtEmployeeId']:$edit[0][5]?>" maxlength="50">
how can to pass value from column txtEmpID to another page(reset.php) and display the value in the reset.php
this is reset.php
<tr>
<td align="right">Employee ID </td>
<td align="left"><input name="staffid" type="text" class="textfield_login"
value="how to display the value from 1st page into here?"/></td>
</tr>
help me please

Wrap the elements in a form and post the form a page.Then you can access the post data via $_POST if your method is post and $_GET if your method in form is get.
<form method="post" action="reset.php">
<td>ID NUMBER:</td>
<td><input type="hidden" name="txtEmpID" value="<?php echo $this->getArr['id']?>">
<input type="text" <?php echo (isset($this->postArr['EditMode']) && $this->postArr['EditMode']=='1') ? '' : 'disabled'?> name="txtEmployeeId2" value="<?php echo (isset($this->postArr['txtEmployeeId']))?$this->postArr['txtEmployeeId']:$edit[0][5]?>" maxlength="50">
</td>
</form>
In reset.php
echo $_POST['txtEmpID'];//Will contain the value of txtEmpID

There are two ways I can think of to do this.
The first is to use a form.
<form action="reset.php" method="get">
<input type="text" id="txtEmployeeId2" <?php echo (isset($this->postArr['EditMode']) && $this->postArr['EditMode']=='1') ? '' : 'disabled'?> name="txtEmployeeId2" value="<?php echo (isset($this->postArr['txtEmployeeId']))?$this->postArr['txtEmployeeId']:$edit[0][5]?>" maxlength="50">
<input type="submit" value="Submit">
</form>
The second
is to use Javascript/jQuery to get the value and pass it through the URL as an equivalent GET request.
However, you will need some sort of trigger to call the javascript function, like a button, for example.
<button onclick="sendValue()">Submit</button>
<script type="text/javascript">
function sendValue()
{
parent.location = 'reset.php?txtEmployeeId2='+document.getElementById("txtEmployeeId2").value;
}
Note that this will require you to add the ID attribute to your textbox.
For both solutions, you simply have to change the line in your reset.php file:
This is assuming that both the name attribute of your input and the ID attribute are the same. Replace "txtEmployeeId2" with whatever name or ID you want to give to the text box inputs.
<input name="staffid" type="text" class="textfield_login" value="how to display the value from 1st page into here?"/>
To
<input name="staffid" type="text" class="textfield_login" value="<?php echo $_GET["txtEmployeeId2"];?>"/>

You can also use session. ($_SESSION superglobal array)

Related

Get input textbox value into a PHP variable in WordPress

I am trying to get a input textbox value in a PHP variable and then update a table based on this variable value in my custom WordPress page. I have written following code.
It is working but not updating the text input value. What is wrong with my code?
<form method="post" enctype="multipart/form-data">
<td>
<table> <tr><td> </td><input type="text" name="offeramt" style="height:15px"/> <td>
<input type="hidden" name="pid" value= "<?php echo $retrieved_data->id; ?>">
<input type="hidden" name="textamount" value="<?php echo htmlspecialchars($_POST['offeramt']);?>">
<input type="submit" name="update" value="update" /></td> </table></td>
</form>
<?php
if (isset($_POST['update'])) {
$sellamt=$_POST['textamount'];
if (empty($sellamt)){
echo "pls input a value in text box";
}
else{
$myid = $_POST['pid'];
?> <?php
$wpdb->update('wp_share', array('status'=>'onsell','offervalue'=>$sellamt),array('id'=>$myid));
}}
}?>
I was updating the text input value to a hidden field ["textamount"]then trying to get that hidden field ["textamount"] value to $sellamt. However I have removed the hidden field and took the value directly from textbox like this
$sellamt=$_POST['offeramt'];
where ['offeramt'] is the textbox itself
and its working.Thanks

form submit only giving last value in a loop codeigniter

Here is my view
<?php for($i=0;$i<count($acb['def']);$i++) { ?>
<input type="text" name="xyz" value="<?php echo $abc['def'][$i]?>" />?>
Here is my controller
$xxx=$this->input->post('xyz')
Now when i submit the form the last value only gets posted to controller
then i found that the name is same for all fields so it takes last value , so i changed the input name as
name ='xyz[$i]'
Now i need to post values , How to post values with this
You need to send name as array rename it to 'xyz[]' here
<input type="text" name="xyz[]" value="<?php echo $abc['def'][$i]?>" />?>
You use to below code...
<?php for($i=0;$i<count($acb['def']);$i++) { ?>
<input type="text" name="xyz[]" value="<?php echo $abc['def'][$i]?>" />
?>

Get the value of clicked text box from array of text boxes using PHP

i want to get the text box value which i selected from array of text boxes..
My code is like this:
Here am displaying the data on the browser from DB..
<?php
foreach($dataDecoded['categories'] as $key => $value)
{
?>
<tr>
<td><?php echo $value['CategoryName'];?></td>
<td>
<input type="text" name="categoryId[]" id="categoryId" value="<?php echo $value['CategoryId']?>">
<input type="text" name="categoryName[]" id="categoryName" value="<?php echo $value['CategoryName']?>">
<input type="submit" name="create" id="create" value="create">
</td>
</tr>
<?php
}
?>
The data will be displayed like:
categoryId1 categoryName1 <Create Button>
categoryId2 categoryName2 <Create Button>
categoryId3 categoryName3 <Create Button>
and so on like this..
Now, suppose When i click on Create Button of CategoryName2, i want to get the categoryId and categoryName of only CategoryName2..
Am using this code:
if(isset($_POST['create']) && $_POST['create']=="create")
{
$cat_id[]=$_POST['categoryId'];
$cat_name[]=$_POST['categoryName'];
}
But with this, am getting all the categoryId and categoryName into the array.. how to get only the selected textbox value..
I want to do it using only PHP and not with JavaScript / JQuery... Am a bit new to PHP... Can someone help me / give me a suggestion about how to do it...
Thanks in advance.
Wrap each one in its own form:
<td>
<form method="POST" action="somePage.php">
<input type="text" name="categoryId" value="<?php echo $value['CategoryId']?>">
<input type="text" name="categoryName" value="<?php echo $value['CategoryName']?>">
<input type="submit" name="create" value="create">
</form>
</td>
Since the content being posted in this case is just these two values, then that's the entire scope of a single form post. So each one is logically/semantically its own form. (There's no rule that says a page can have only one form. Unless you're ever using ASP.NET WebForms, which is a lie.)
Note also that I removed your id attributes. Multiple elements can't have the same id, that's invalid HTML and any behavior as a result becomes undefined.

PHP POST value from a looped table

Please help me out of this.....
I am designing a table which is inside a form.
the table is generated based on while loop.
In each row there is a download button.
when i click download the POST value should get the same row information.
But my POST variable is giving me the last row information only.
I tried using input-type as hidden... But it did not work
Here is the code for your reference
enter code here
<form name="simpleform" method="post" action="insert.php">
<?php
$data = "environment";
$user_name = $_SESSION['username'];
$serch = mysql_query("SELECT * FROM data WHERE (data_category = '" . $data . "') ");
while ($record=mysql_fetch_assoc($serch))
{?>
<tr class="warning">
<td >
<input type="text" value=<?php echo $record['data_ID'];?> readonly="readonly" >
<input type="hidden" value=<?php echo $record['data_ID'];?> name="dataid" />
</td>
<td >
<input type="text" value=<?php echo $record['data_name'];?> readonly="readonly" >
<input type="hidden" value=<?php echo $record['data_name'];?> name="dataname" />
</td>
<td >
<input type="text" value=<?php echo $record['data_downloads'];?> readonly="readonly">
<input type="hidden" value=<?php echo $record['data_downloads'];?> name="datadown" />
</td>
<td >
<input type="text" value="" >
<input type="hidden" value="" name="datause" />
</td>
<td>
<input type="submit" name="simplesubmit" value="Go to download" />
</td>
</tr>
<?php }
exit;
?>
</tbody>
</form>
The problem is that you are using the same name attribute for all your controls. Thus, when PHP receives the form, they get overwritten, and you only see the last value of the form.
The simplest way to avoid that is just appending [] to the end of your names -- eg name=dataid[]. This will make PHP take all arguments as an array, so you don't lose data.
The second problem, is that your submit button also has the same name - you should diversify it by using some row-specific data in its name, such as 'name="submit-'.$record['data_name'].'"'
For more info, more code from you is needed, such as what are the data you are printing like.
Every post button can have its name and value, so if you change your code to produce a traceable post button name you can just do whatever you want with that.
<table>
<tr>
<td>...</td>
<td>...</td>
<td><input type="submit" name="submit[1]" value="OK" />
</tr>
<tr>
<td>...</td>
<td>...</td>
<td><input type="submit" name="submit[2]" value="OK" />
</tr>
</table>
When the form is posted its very easy to capture which button is clicked;
if ($_POST["submit"]) {
$id = key($_POST["submit"]);
}
Thanks for info... and good response. As you said , i replaced the same and saw the post value is giving me all arguments as array. My purpose is to let the client download file that he clicks. so if the client click the first row button in the table, the post value should get only that Data_name. So that i can run a query to get the URL of that data_name and download

PHP post two values in one field, one of which is hidden

Is there a way that I can post two values at the same time from a single field in a table but hide one from the user?
I would like the following form to post the values ID and reason_name when it is submitted but have the user only be able to see (and edit in the text box) the reason_name.
<form name="add_positioning" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table border="1" class="autoTable_pos">
<tr>
<td>Positioning</td><td> </td></tr>
<?
$sql= "SELECT * FROM gradeReason WHERE reason_userID = $user_id AND category = 'positioning' AND current = 1";
$result = mysqli_query($mysqli,$sql) or die(mysqli_error($mysqli));
while($row = mysqli_fetch_array($result)){?>
<tr>
<td>
<input type="text" name="reason[]" size="25" value="<? echo $row['reason_name']; ?>"/>
</td>
<td>
<input type="button" value="Delete" class="delRow_pos"/>
</td>
</tr>
<?
}
?>
<tr>
<td>
<input type="text" name="reason[]" size="25"/>
</td>
<td>
<input type="button" value="Delete" class="delRow_pos"/>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="submit" value="Save" name="save_reasons"/>
</td>
</tr>
</table>
</form>
The form POST action so far (basic echo at the moment for my own sanity to check that it posts the values correctly, which it does...)
if(isset($_POST['save_reasons'])) {
foreach($_POST['reason'] as $item) {
echo $item.'<br/>';
}
}
This table displays the values that are held in a database but enables the user to add more values by dynamically adding a new row (using JQUERY I haven't included) to the table when they type in an empty one at the bottom and also allows them to edit or delete existing values.
For each value posted I intend to check if the ID value is empty, if it is it means that it is a new value and enter a new record into the database, if it isn't update the existing record in the database with the corresponding ID. I don't have a problem writing that bit, I just can't think how to get the ID value posted as well as the reason_name while keeping ID hidden from the user.
Add the ID to the name attribute of the Text boxes of the reasons loaded from the DB. Leave the other Text boxes added using JQ without the ID.
E.g.
Text box which shows the existing reason loaded from the DB
<input type="text" name="reason[][ID]" size="25"/>
Text box added with JQ
<input type="text" name="reason[]" size="25"/>
Then once you submit the form you get you will get the following array.
array
'reason' =>
array
0 =>
array
14 => string 'VAL1' (length=4)
1 => string 'VAL2' (length=5)
By checking for an array in the each element in the "reason" array, you can differentiate two type of Text Boxes.
Here is the complete code I have tested.
<?PHP
//var_dump($_POST);
foreach($_POST['reason'] as $item=>$value)
{
if(is_array($value)){
foreach($value as $ID=>$reason)
{
echo "Existing Reason : ".$ID." - ".$reason."<br>";
}
}
else{
echo "New Reason : ".$item." - ".$value.'<br/>';
}
}
?>
<form action="" method="POST">
<input type="text" name="reason[][14]" size="25" value="aaaa"/>
<input type="text" name="reason[]" size="25" value="bbbbb"/>
<input name="" type="submit">
</form>
Assuming the id is at $row['reason_id'] I think you want:
$i = 0;
while($row = mysqli_fetch_array($result)){?>
<tr>
<td>
<input type="hidden" name="reason_id[<? echo $i; ?>]" size="25" value="<? echo $row['reason_id']; ?>"/>
<input type="text" name="reason[<? echo $i; ?>]" size="25" value="<? echo $row['reason_name']; ?>"/>
</td>
<td>
<input type="button" value="Delete" class="delRow_pos"/></td></tr>
<? $i++ } ?>
This way you can later
if(isset($_POST['save_reasons'])) {
foreach($_POST['reason'] as $key => $item) {
$id = $_POST['reason_id'][$key];
echo $id . " " . $item.'<br/>';
}
}

Categories