I am submitting this from and in the same page getting the values of the $_POST['id] and displaying them but its getting the wrong id not the ones I am selecting from the row in the table:
<tbody>
<?php if (!empty($found_devices)) {
foreach ($found_devices as $devs) : ?>
<tr>
<td>
<input type="checkbox" id="myCheck" onclick="display_hide_selectClient(this)" name="devices[<?php echo $devs["id"] ?>]" value="<?php echo $devs["id"] ?>">
</td>
<td>
<?php echo $devs["serial_imei"] ?>
</td>
<td>
<?php echo $devs["serial_no"] ?>
</td>
<td>
<?php echo $devs["created_date"] ?>
</td>
<td>
<input hidden name="edit_device_imei" value="<?php echo $devs["serial_imei"] ?>">
<input hidden name="edit_device_serial" value="<?php echo $devs["serial_no"] ?>">
<input hidden name="edit_device_id" value="<?php echo $devs["id"] ?>">
<button type="submit" name="edit_device">Edit</button>
</td>
</tr>
<?php endforeach;
} ?>
</tbody>
So, when submitting this form with the button edit_device I am receiving the wrong values in PHP.
PHP Ccode:
if (isset($_POST['edit_device']) && !empty($_POST['edit_device_id'])) {
$get_selected_Devices = e($_POST['edit_device_id']);
$get_selected_Devices_s = e($_POST['edit_device_serial']);
$get_selected_Devices_i = e($_POST['edit_device_imei']);
}
Related
I want to send an Id by the form in foreach loop but when I click on each button it sends me the first form.
It means when I click on the second button it sends me the value of the first form the value of input hidden is right but the first value every time sent.
<?PHP
if ($transactions) {
foreach ($transactions as $transaction) {
?>
<td class="text-left">
<?php echo $transaction['invoice_id']; ?>
</td>
<td class="text-left">
<?php echo $transaction['invoice_type']; ?>
</td>
<td class="text-left">
<?php echo $transaction['ref_id']; ?>
</td>
<td class="text-left">
<?php echo $transaction['gateway']; ?>
</td>
<td class="text-left">
<?php echo $transaction['payment_date']; ?>
</td>
<td class="text-right">
<?php
if($transaction['payment_status'] == 'not paid') {
?>
<form
method="POST"
action="<?php echo $gate_url; ?>"
>
<input type="hidden" name="invoiceId" value="<?php echo $transaction['invoice_id']; ?>">
<button class="btn btn-md btn-primary" type="submit" >
<?php echo $pay; ?>
</button>
</form>
<?php
}
?>
</td>
<?php
}
You have an array of the values, so this:
<input type="hidden" name="invoiceId" value="<?php echo $transaction['invoice_id']; ?>">
replace with:
<input type="hidden" name="invoiceId[]" value="<?php echo $transaction['invoice_id']; ?>">
I am passing a table data value within a for each loop to the php script. The problem here is that when I try to echo $exchange;. I don't get any values of the specific product name. The product name being displayed in the form is item1.
<form action="exchangeItem" method="post">
<tbody>
<?php
$query = "SELECT * FROM product";
$data = $MySQLi_CON->query($query);
foreach ($data as $key ) {
?>
<tr>
<td class="id"><h3><input type="hidden" name="productName" ><?php echo $key['product_Name'];?></h3>
</td>
<input name = "id" type = "hidden" value="<?php echo $id; ?>">
<td id="exchange_button">
<input value="Exchange" name="exchange_submit" type="submit" class="btn btn-primary btn-md raised exchange_submit">
</td>
</tr>
<?php
}
?>
</tbody>
</form>
exchangeItem.php
<?php
$exchange = $_POST['productName'];
echo $exchange;
exit;
?>
This
<td class="id"><h3><input type="hidden" name="productName" ><?php echo $key['product_Name'];?></h3>
Should be:
<td class="id"><h3><input type="hidden" name="productName" value="<?php echo $key['product_Name'];?>" ></h3>
first, edit your td
<td class="id"><h3><input type="hidden" name="productName[]" value="<?php echo $key['product_Name'];?>" ></h3>
your name => productName should be in array thats why you need bracket [ ], because you use foreach. then your post will be in array too.
exchangeItem.php
<?php
print_r($_POST['productName']);
exit;
?>
I have added & changed your 2 input name productName[] , id[] and your form action exchangeItem.php if you get product name must be used input name with array like [] because you are used foreach loop.
<form action="exchangeItem.php" method="post">
<tbody>
<?php
$query = "SELECT * FROM product";
$data = $MySQLi_CON->query($query);
foreach ($data as $key ) {
?>
<tr>
<td class="id">
<h3><input type="hidden" value="<?php echo $key['product_Name'];?>" name="productName[]" ><?php echo $key['product_Name'];?></h3>
<input name="id[]" type="hidden" value="<?php echo $id; ?>">
</td>
</tr>
<?php
}
?>
</tbody>
<tfoot>
<tr>
<td id="exchange_button">
<input value="Exchange" name="exchange_submit" type="submit" class="btn btn-primary btn-md raised exchange_submit">
</td>
</tr>
</tfoot>
</form>
exchangeItem.php
<?php
if(isset($_POST['exchange_submit'])) {
$exchange = $_POST['productName'];
foreach($exchange as $product_name) {
echo $product_name;
}
}
?>
The problem you facing here is with this code
<td class="id">
<h3><input type="hidden" name="productName" ><?php echo $key['product_Name'];?></h3>
</td>
here in the input field you didn't have added the value, that's why when you trying to print the posted value in your action file it's showing none. So just add add value to the input field
<td class="id">
<h3><input type="hidden" name="productName" value="<?php echo $key['product_Name'];?>"></h3>
</td>
Set value for you hidden element... No need to place the hidden element in the header tag. Use productName[] for posting array of values.
<td class="id">
<h3><?php echo $key['product_Name'];?></h3>
<input type="hidden" name="productName[]" value="<?php echo $key['product_Name'];?>">
</td>
foreach all posted values to print.
<?php
$exchange = $_POST['productName'];
foreach($exchange as $key) {
echo $key;
}
exit;
?>
Update for select
Change yout html for select values..
<td class="id">
<h3><input type="checkbox" name="productName[]" value="<?php echo $key['product_Name'];?>"><?php echo $key['product_Name'];?></h3>
</td>
This is my dynamic form
<input type="checkbox" class="thebox" value="selected<?php echo"$x"; ?>"/>
</td>
<td>
<input type="text" class="thebox" name="id<?php echo"$x"; ?>" value="<?php echo $row['member_id']; ?>" />
</td>
<td>
<input type="text" class="thebox" name="fn<?php echo"$x"; ?>" value=" <?php echo $row['first_name']; ?>"/>
</td>
<td>
<input type="text" class="thebox" name="ln<?php echo"$x"; ?>" value="<?php echo $row['last_name']; ?>"/>
</td>
<td>
<input type="text" class="thebox" name="sd<?php echo"$x"; ?>" value="<?php echo $row['start_date']; ?>"/>
</td>
</tr>
<?php
$x++;
endwhile;
?>
<tr align="center">
<td>
</td>
<td>
<input type="submit" name="delmem" class="myButton" value="Delete member "/>
</td>
</tr>
</table>
</form>
</div>
I am trying to get the selected check box variables only. I have tried everything. I know I am a php noob someone help me please. How can I retrieve the selected check box attributes?
<?php
if(isset($_POST['delmem']))
{
$i = 1;
while($i <= $_SESSION['stuff'])
{
$a = $_POST["fn"."$i"]."<br />";
echo $a;
$i++;
if(isset($_POST["selected"."$i"]))
{
echo $_POST["$fn"."$i"]."<br />";
echo $_POST["$ln"."$i"];
}
}
}
}
I think you made mistake in post Variable
$_POST["$fn"."$i"] to $_POST["fn"."$i"]
if(isset($_POST["selected"."$i"]))
{
echo $_POST["$fn"."$i"]."<br />";
echo $_POST["$ln"."$i"];
}
To
if(isset($_POST["selected"."$i"]))
{
echo $_POST["fn"."$i"]."<br />";
echo $_POST["ln"."$i"];
}
how to save radio button has been selected at the time the page is reloaded? suppose I have selected some of the radio button and then reload the browser page. but after the page is reloaded radio buttons have been still the same. I use Codeigniter.
here is my view code
<div class="container">
<?php
$no=1;
foreach($hasil->result() as $row):
?>
<form action="<?php echo base_url();?>mahasiswa/hasil" method="post" class="form" enctype="multipart/form-data" name="form" onsubmit="stopCounter();">
<input type="hidden" name="id_soal[<?php echo $row->id_soal;?>]" value="<?php echo $row->id_soal;?>" />
<table>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td><b><?php echo $no.'. ';?></b></td>
<td><?php echo $row->pertanyaan;?></td>
</tr>
<tr>
<td rowspan="5"> </td>
<td><span class="radio"><label><input type="radio" name="jawab[<?php echo $row->id_soal;?>]" value="A" />a. <?php echo $row->a;?></label></span></td>
</tr>
<tr>
<td><span class="radio"><label><input type="radio" name="jawab[<?php echo $row->id_soal;?>]" value="B" />b. <?php echo $row->b;?></label></span></td>
</tr>
<tr>
<td><span class="radio"><label><input type="radio" name="jawab[<?php echo $row->id_soal;?>]" value="C" />c. <?php echo $row->c;?></label></span></td>
</tr>
<tr>
<td><span class="radio"><label><input type="radio" name="jawab[<?php echo $row->id_soal;?>]" value="D" />d. <?php echo $row->d;?></label></span></td>
</tr>
<tr>
<td><span class="radio"><label><input type="radio" name="jawab[<?php echo $row->id_soal;?>]" value="E"/>e. <?php echo $row->e;?></label></span></td>
</tr>
<?php
$no++;
?>
<input type="hidden" name="id_sesi" value="<?php echo $row->id_sesi;?>" />
<input type="hidden" name="jumlah" value="<?php echo $jumlah;?>" />
<?php
endforeach;
?>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Selesai" class="btn btn-default"/></td>
</tr>
</table>
</form>
</div>
here my controller code
public function mulai_tes(){
$id=$this->uri->segment(3);
$this->load->model('m_mahasiswa');
$result=$this->m_mahasiswa->data_mahasiswa();
foreach($result->result() as $row):
$data['user']=$row->username;
$data['nama']=$row->nama;
endforeach;
$cek=$this->m_mahasiswa->validasi_tes($id,$data['user']);
foreach($cek->result() as $c){
if($c->id_sesi==$id){ ?>
<script type="text/javascript" language="javascript">
alert("Anda telah mengikuti tes soal ini");
</script>
<?php
echo "<meta http-equiv='refresh' content='0; url=".base_url()."mahasiswa/tes'>";
}
}
$data['hasil']=$this->m_mahasiswa->mulaites($id);
$data['jumlah']=$data['hasil']->num_rows();
$data['judul']='Mulai Tes';
$this->load->view('elearning/template',$data);
}
How I set cookie and where I can put cookie code in controller?
Check which radio(s) was selected in controler (http://ellislab.com/codeigniter%20/user-guide/libraries/input.html).
Pass this data to view (http://ellislab.com/codeigniter/user-guide/general/views.html).
Mark radio(s) as selected within view depending on data passed by controller (Assign an initial value to radio button as checked).
Im having a page that shows monthly subscriptions of a user which is created using codeigniter. what i want to do is when a the user clicks on make payment pass the values in the hidden files to the controller.
<?php echo form_open('options/done');?>
<table class="tables">
<thead>
<tr>
<th>Ref Code</th>
<th>Month</th>
<th>Year</th>
<th>action/th>
</tr>
</thead>
<tbody>
<?php foreach ($payments as $s =>$payment):?>
<?php $month = $payment['month'];?>
<input type="hidden" value="<?php echo $month;?>" name="month_<?php echo $s;?>" />
<input type="hidden" value="<?php echo $payment['ref_code'];?>" name="ref_<?php echo $s;?>" />
<tr>
<td><?php echo $payment['ref_code'];?></td>
<td><?php echo $month;?></td>
<td><?php echo $payment['year'];?></td>
<td><input type="submit" value="MAKE PAYMENT" class="red" /></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php echo form_close();?>
so when someone hits the submit button how can i pass only the hidden values which are relevant to that table row?
add form just inside the <tr> elements inside your loop (see below with your code)
<?php foreach ($payments as $s =>$payment):?>
<?php $month = $payment['month'];
?>
<tr>
<form action="target.php" method="post" name="formName_<?php echo $s;?>" >
<input type="hidden" value="<?php echo $month;?>" name="month_<?php echo $s;?>" />
<input type="hidden" value="<?php echo $payment['ref_code'];?>" name="ref_<?php echo $s;?>" />
<td><?php echo $payment['ref_code'];?></td>
<td><?php echo $month;?></td>
<td><?php echo $payment['year'];?></td>
<td><input type="submit" value="MAKE PAYMENT" class="red" /></td>
</form>
</tr>
<?php endforeach; ?>