Form POST not showing in controller - javascript

I am working with CodeIgniter, and I am trying to create a dynamically generated table that includes a checkbox, with values set to the id numbers of the row, in the first column of the row. When a single or multiple checkbox is checked, and the button clicked, I am trying to bring up a second form which consists of a couple of select fields and a textarea.
Ultimately, when I submit the form, I want the values of the checkboxes to be sent to my controller. However, currently I am only getting a false value when I check the values of the POST field in my controller.
Here is my current view code:
<form class="form" role="form" name="ticket_view" id="ticket_view" action="<?php echo site_url('example_controller/example_method'); ?>">
<div class='table-responsive text-left'>
<table class='table table-hover table-bordered table-condensed supportTable'>
<thead>
<th>Select</th>
<th>Id</th>
<th class="text-center">Status</th>
<th>Source</th>
</thead>
<tbody>
<?php foreach($examples as $example): ?>
<?php if ($example->type == "test): ?>
<tr class="<?php echo alternator('oddRow', '');?>">
<td class="text-center" style="width:60px;"><input type="checkbox" value="<?=$example->id;?>" name="supportTicketId[]" class="supportLogCheck"></td>
<td><a href=<?php echo site_url("example_controller/example_method/" . $example->idd); ?>>SUP-<?php echo $example->id; ?></a></td>
<td class="text-center">
<?php if ( ! $example->claimed): ?>
<span class="label label-danger">Unclaimed</span>
<?php else: ?>
<span class="label label-success">Claimed</span>
<?php endif; ?>
</td>
<td><?php if ($example->voicemail): ?>Voicemail <?php else: ?>Email <?php endif; ?></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</tbody>
</table>
</div>
<div class="text-center">
<a class="btn btn-primary" id="firstButton" href="javascript:void(0);">First Button</a>
</div>
<div id="secondForm" class="alert alert-info col-md-4 col-md-offset-4" style="display:none; margin-top:10px;">
<div class="form-group">
<label for="closeIssue">Issue:</label>
<select name="issue" id="issue" class="form-control">
<option value="">Select an Issue</option>
<?php foreach ($issues as $issue): ?>
<option value="<?php echo ($e->emailIssueId); ?>"><?php echo ($issue->emailIssueDescription); ?></option>
<?php endforeach; ?>
</select>
<label for="closeAction">Action:</label>
<select name="action" id="action" class="form-control">
<option value="">Select an Action</option>
<?php foreach ($actions as $action): ?>
<option value="<?php echo ($action->emailActionId); ?>"><?php echo ($action->emailActionDescription); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label for="assignNote">Note:</label>
<textarea name="assignNote" id="assignNote" class="form-control"></textarea>
</div>
<div class="text-center">
<input class="btn btn-primary" name="secondButton" type="submit" id="secondButton" value="second button">
</div>
</div>
</div>
</form>
So, in a nutshell, the table is wrapped in a form. The first button slides down a
div that is orginally hidden, that contains other form fields and a submit button. I want, when that submit button is clicked, for all form fields to post, including the id numbers of the checkboxes that are checked.
Any ideas why this isn't working? Any better suggestions?
Thank you for your help in advance!

You haven't defined method on your form, so it's probably passing the values via GET. You need to add the method="post" attribute in your form tag.

Related

Javascript inside PHP foreach

I made a loop using foreach, to show a list of products. Then I made a modal to edit each product. I need to get the value of product dimension and I'll make a dependent drop down between 'job drop down' and 'supply drop down'. At the moment, I can't continue it with Ajax because I got a problem at the first step to get value of dimension. In this code below I tried to get 'length' value of each product through javascript. But it returns the same value, it always is the value of the first product, even if I click on the 2nd, 3rd, 4th of product in the list.
<div class="table-responsive">
<table class="table table-hover" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Product</th>
<th>Supplier</th>
<th>Dimension</th>
<th>Edit</th>
</tr>
</thead>
<tbody>
<?php
$pcs_1 = 0;
$meter_1 = 0;
foreach ($stock as $s) { ?>
<tr>
<td class="small">
<?php echo $s->cat . ' - ' . $s->prod ?>
</td>
<td class="small">
<?php echo $s->spl ?>
</td>
<td class="small">
<?php echo $s->length . ' x ' . $s->width . ' x ' . $s->height . ' x ' . $s->diameter ?>
</td>
<td>
<a type="button" data-toggle="modal" class="btn btn-small" data-target="#modal_edit<?php echo $s->id ?>"><i class="fas fa-edit"></i></a>
<!--MODAL-->
<div class="modal fade" id="modal_edit<?php echo $s->id ?>" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<form class="form-horizontal" method="post" action="<?php echo site_url('admin/Stock/edit/') ?>">
<div class="modal-header">
<h5 class="modal-title" id="labelModal">EDIT STOCK</h5>
</div>
<div class="modal-body">
<input type="hidden" id="length_product" class="length_product" value="<?php echo $s->length ?>" />
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-sm-3">
<div class="form-group">
<?php echo form_label('JOB') ?>
</div>
</div>
<div class="col-sm-9">
<div class="form-group">
<select name="ref" id="ref" class="form-control" required onchange="GetData()">
<option value="">-- Select Job --</option>
<?php foreach ($job as $j) : ?>
<option value="<?php echo $j->id; ?>"><?php echo $j->id ?> - <?php echo $j->cust ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-3">
<div class="form-group">
<?php echo form_label('Supply') ?>
</div>
</div>
<div class="col-sm-9">
<select name="supply" id="supply" class="form-control" required>
<option value="">--Select Supply--</option>
</select>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-warning submitBtn">edit</button>
</div>
</form>
</div>
</div>
</div> <!-- modal -->
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
Here is the javascript :
<script type="text/javascript">
function GetData() {
var length_product = $("#length_product").val();
alert(length_product);
}
</script>
The list works well, but I don't know how to get the detail of each list on javascript (passing multiple values from 'modal inside the list' to 'Javascript').
for me it looks like that you are always getting value of
<input type="hidden" id="length_product" class="length_product" value="<?php echo $s->length ?>" />
rather than option from the select element.
Try the following:
$('#ref').on('change', function(event) {
event.preventDefault();
var length_product = $(this).val();
alert(length_product);
});
and for the PHP and HTML:
<div class="form-group">
<select name="ref" id="ref" class="form-control" required>
<option value="">-- Select Job --</option>
<?php foreach ($job as $j) { ?>
<option value="<?php echo $j["id"]; ?>"><?php echo $j["id"]; ?>-<?php echo $j["cust"]; ?></option>
<?php
}
?>
</select>
</div>
Hope this helps!

Clicking on any radio button in my created list results in only the first <select> field being activated

Here is the video in specific from what i mean. It is hosted on my personal drive
video
Here is my code
<?php
$pagetitle="Search Report";
include "includes/header.php";
include("config.php");
include("connection.php");
error_reporting(E_ALL ^ E_DEPRECATED);
$name=$_GET['filo'];
$ksm=$_GET['kisim'];
$drs=$_GET['hders'];
$ndrs=$_GET['dname'];
$tch=$_GET['tname'];
?>
<script>
//Here Is javascript code
function enable() {
document.getElementById('option').disabled=false;
}
</script>
<style type="text/css">
input[type="radio"]{
margin: 0px 4px 0px;
}
</style>
<div class="container">
<div class="row">
<div class="templatemo-line-header" style="margin-top: 0px;" >
<div class="text-center">
<hr class="team_hr team_hr_left hr_gray"/><span class="span_blog txt_darkgrey txt_orange"> </span>
<hr class="team_hr team_hr_right hr_gray" />
</div>
</div>
</div>
<div class="table-responsive">
<table class="ui celled table table table-hover">
<form action="check.php" method="get">
<thead>
<tr>
<th>Adı ve Soyadı</th>
<th>Dersin Adı</th>
<th>Dersin Saatı</th>
<th>Öğretim Elemanı</th>
<th>Durum</th>
<th>Sebepi</th>
<th>ID</th>
</tr>
</thead>
<tbody>
<?php
$query3=mysqli_query($connect,"select * from student where filo='$name' and kisim='$ksm' ORDER BY student_name");
$arra=-1;
while($row=mysqli_fetch_row($query3))
{
$arra++;
?>
<tr>
<td><?php echo $row[1] ?></td>
<input type="hidden" value="<?php echo $row[1] ?>" name="std_name[]">
<td><?php echo $ndrs ?></td>
<input type="hidden" value="<?php echo $ndrs ?>" name="ndrs[]">
<td><?php echo $drs ?></td>
<input type="hidden" value="<?php echo $drs?>" name="drs[]">
<td><?php echo $tch ?></td>
<input type="hidden" value="<?php echo $tch ?>" name="tch[]">
<td>
///////HERE IS ONE PART OF THE CODE
<input type="radio" name="attendance[<?php echo "$arra" ?>]" value="Mevcut" checked="checked" >Mevcut
<input type="radio" name="attendance[<?php echo "$arra" ?>]" onclick="enable()" value="Gayri">Gayrı
</td>
<td>
<select class="form-control" id="option" name="option[<?php echo "$arra" ?>]" disabled >
<option selected value="Mevcut">Mevcut</option>
<option value="Vizite">Vizite</option>
<option value="Hst Muayene">Hst Muayene</option>
<option value="Izinli">Izinli</option>
</select>
</td>
<td><?php echo $row[0] ?>
<input type="hidden" value="<?php echo $row[0] ?>" name="id[]">
</td>
</tr>
<?php } ?>
</tbody>
</table>
<button type="submit" class="btn btn-success btn-lg btn-block" name="submit2">Gönder</button>
</form>
</div><!--table-responsive-->
</div><!--row-->
</div><!--container-->
<?php include "includes/footer.php"; ?>
I try to explain my problem.
Scenario is like that. Some infos are taken from a submit form and with this infos i create a list then created list has 2 radio buttons and by default a disabled select area.
The problem is here. When i click on "Gayri" button field must be activated for every person in that list instead of that just the first field is activated.
Can anyone help me? I want for every possible person in the list when i click on "gayri" radio button the field to be activated.

How to display the list from database using selected value in drop down

manage_bank
Hi everyone,
Can someone help me, How to display the bank name based on selected drop down, when we choose
for example:- 50 records
then it will display 50 records of the bank name from database.
When we logout the value still remain the same 50 records.
<?php
// Includes the required files
include ("../ecompany/terms_includes.php");
?>
<?php
// Check user authority for this page
$ModuleName = "Manage Banks";
$ModuleAction = "view";
base_checkAuthority($ModuleName,$ModuleAction)
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
include PATH_INC_HEAD;
?>
<?php
//get page number
$page = $_GET["page"];
$record = $_GET["record"];
//get Miscellaneous detail
$MiscellaneousDetail = base_getMiscellaneousDetail();
?>
<?php
if(!isset($page))
{
$page = 1;
}
if(!isset($record))
{
$record = $MiscellaneousDetail['base_mis_default'];
}
//go to reload page
if(isset($_POST['load']))
{
$page = 1;
$record = $_POST['records_per_page'];
}
//go to add profile page
if(isset($_POST['add']))
{
echo '<script type="text/javascript">' . "\n";
echo 'window.location="../ecompany/add_bank.php";';
echo '</script>';
}
//go to home page
if(isset($_POST['cancel']))
{
echo '<script type="text/javascript">' . "\n";
echo 'window.location="../terms_base/home.php";';
echo '</script>';
}
?>
</head>
<body>
<div class="container">
<?php
include PATH_INC_HEADER;
?>
<div class="main_body1">
<div id="update_category"></div>
<div style="width:800px; margin:auto">
<?php
include PATH_INC_DESC;
?>
<div style="clear:both"></div>
<form name="bank_list_form" id="bank_list_form" method="post" action="">
<div style="width:800px; margin:auto; text-align:left">
<select name="records_per_page" id="records_per_page" >
<option value="<?php echo $record; ?>">Default Records/Page :</option>
<option value="1" title="1" >1</option>
<option value="3" title="3" >3</option>
<option value="5" title="5" >5</option>
<option value="10" title="10" >10</option>
<option value="20" title="20" >20</option>
<option value="30" title="30" >30</option>
<option value="50" title="50" >50</option>
<option value="100" title="100" >100</option>
<option value="200" title="200" >200</option>
<option value="500" title="500" >500</option>
<option value="1000" title="1000" >1000</option>
</select>
<input type="" size="4" style="width:25px" name="record"
id="record"value="<?php echo $record; ?>" readonly="readonly" />
<div id="searchbutton">
<input type="submit" id="load" name="load" value="Refresh">
</div>
</div>
<table cellspacing="1" class="tablesorter">
<thead>
<tr>
<th></th>
<th>Code</th>
<th>Name</th>
<th>Description</th>
<th>Remark</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<?php ecoy_listBank($page, $record) ?>
</tbody>
<tr>
<td align="center" colspan="8"><input type="submit" id="add"
name="add" value="Add Bank" /><input type="submit" id="cancel"
name="cancel" value="Cancel" /></td>
</tr>
</tfoot>
</table>
</form>
<br />
</div>
<div class="clearboth"></div>
</div>
<?php
include PATH_INC_FOOTER;
?>
</div>
</body>
</html>
Much appreciate, Thanks.
The title of your question is misleading. But if I got it right you actually succeed in querying your data correctly and refreshing the number of records with your refresh button.
You real question is how to persist the default value of the dropdown after a logout.
By mentioning your logout feature I assume you have users and a user table in your database.
From here you have two solutions I can think of:
1. Save the users preferences like the default value of your dropdown within your users table or create a separated table dedicated for this purpose.
2. Store users preferences in cookies

Adding labels for radio-boxes in Magento

Trying to use label for each radio-box(to customise them with css3), but there is javascript preventing the labels to work as they should. When I click on a label, the radio-box gets focused but not checked.
If you click straight on the radio-box, it validates and adds a class .validation-passed to the input. Maybe I need to make a validation for the label aswell?
Anyone faced this before and could help out to make it work?
<table class="data-table review-summary-table" id="product-review-table">
<tbody>
<?php foreach ($this->getRatings() as $_rating): ?>
<tr>
<td class="label">
<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>
</td>
<?php foreach ($_rating->getOptions() as $_option): ?>
<td class="value">
<label for="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>">
<?php echo $this->escapeHtml($_rating->getRatingCode()) ?> <?php echo $_option->getValue() ?>
</label>
<input type="radio" name="ratings[<?php echo $_rating->getId() ?>]" id="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>" value="<?php echo $_option->getId() ?>" class="radio" />
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<input type="hidden" name="validate_rating" class="validate-rating" value="" />
<script type="text/javascript">decorateTable('product-review-table')</script>
I see that all of radio boxes have different names.
If you want collate it to 1 group you should use same names for all radio buttons.
name="ratings"

Validate and Submit Multiple forms on a page using jquery validation plugin

I am facing trouble getting the multiple forms on a webpage submitted using the jquery validation plugin
Below is the code for generating multiple forms on a page
<?php for($index=1;$index<4;$index++) : ?>
<tr>
<td class="center">
<div class="box-content" id="share_rss_">
<form class="share_rss_form" id="share_rss_form_<?php echo $index; ?>" method="post" action="abc2_db.php?id=<?php echo $index; ?>" data-noty-options='{"text":"This is a success notification","layout":"topLeft","type":"success"}'>
<table class="table table-bordered table-striped table-condensed " id="tbl_<?php echo $index; ?>" >
<tr id='tr_<?php echo $index; ?>'><td><input type=text class="required" name='rss_title' id='title' style="width:400px;margin:0px" value="This is just a demo"></td>
</tr>
<tr id='tr_<?php echo $index; ?>'><td><textarea class="required" name='rss_description_<?php echo $index; ?>' style="width:400px;margin:0px" >Description series</textarea></td></tr>
<tr id='tr_<?php echo $index; ?>'><td><b>Featured</b> <input type='checkbox' name='rss_featuredArticle_<?php echo $index; ?>' value=1 />
<b>Rated</b> <input type='checkbox' name='rss_rated_<?php echo $index; ?>' value=1 />
<b>Expiry time</b> <input type='checkbox' name='rss_expirySelect_<?php echo $index; ?>' value=1 />
<select name='rss_expiry_<?php echo $index; ?>'><option value=15>15</option><option value=30>30</option></select></td>
</tr>
<tr id='tr_<?php echo $index; ?>'>
<td><select class="category" class="required" name="category_<?php echo $index; ?>" id="category_<?php echo $index; ?>">
<option value="" ><b>---Select---</b></option>
<?php foreach($category as $c) :?>
<option value="<?php echo $c; ?>" ><b><?php echo $c; ?></b></option>
<?php endforeach; ?>
<br>
</select>
</td>
</tr>
<tr id='tr_<?php echo $index; ?>'><td><div id="container_for_category_<?php echo $index; ?>"></div></td>
</tr>
</table>
</form>
</div>
</td>
<td class="center">
<button class="btn btn-info approveid" href="#" type="submit" id="approve_<?php echo $index; ?>"><i class="icon-edit icon-white"></i></button>
<button class="btn btn-danger trashid" href="#" type="submit" id="trash_<?php echo $index; ?>"><i class="icon-trash icon-white"></i></button>
</td>
</tr>
<?php endfor; ?>
Below is the jquery code to trigger the validation and submission of forms
$('.share_rss_form').each(function(index,e1){
$(e1).validate({
errorClass: "error",
validClass: "success",
submitHandler: function(form) {
//The below alert is triggered
alert(form.id) ;
form.submit();
return true;
//alert(e1);
//console.log(form);
}
});
});
The problem is the above jquery seems to work partially because alert(form.id) in the validation submitHandler code. However the form doesn't submit. I have added form.submit() in the code after which the form does submit but the entire page is reloaded.
According to me the jquery validation plugin should automatically submit the form after validation but it doesnt seem so. Can someone please help?
Thanks in advance!
My guess is when you use .each(), it tries to validate the elements one by one. Then the validator submits the invalid form and reloads the page in order to validate next form element. Basically calling validate again and again.
The answer to above was the use $(form).ajaxSubmit(); instead of simply form.submit().
$('.share_rss_form').each(function(index,e1){
$(e1).validate({
errorClass: "error",
validClass: "success",
submitHandler: function(form) {
//The below alert is triggered
alert(form.id);
$(form).ajaxSubmit();
}
});
});

Categories