I have fetched some 10 records from database and accessed in view page using foreach.But i can only give approve to first record not other records.Why it is not happening.
this is my view page
<tr><tbody>
<?php`enter code here`
if(isset($result))
{
foreach($result as $value){?>
<td><?php echo $name;?> </td>
<td><?php echo $value->date1;?> </td>
<td><?php echo $value->purpose;?> </td>
<td><?php echo $value->amount;?> </td>
<td><?php echo $value->rep_date;?> </td>
<?php if($value->temp==1){?>
<td> Approved </td>
<td><?php echo $value->id;?> </td>
<?php } else {?>
<td>
<form method="POST" action="<?php echo base_url().'Admin/updatestatus';?>">
<input type="hidden" name ="hid" id="hid" value="<?php echo $value->id;?>">
<input type="submit" name="sub" id="sub" class="btn green" value="Approve" >
</td>
<?php }?>
<td> chat </td>
</tr>
<?php } }?>
</tbody>
This is my controller
function updatestatus()
{
$this->load->database();
$this->load->library('session');
$this->load->model('lpmodel');
$frmdate=$this->session->userdata('from');
$todate=$this->session->userdata('to');
$status=$this->session->userdata('stat');
$emp_id=$this->session->userdata('id');
$hidid=$this->input->post('hid');
echo $hidid;
$data=array(
'temp'=>'1');
$query=$this->lpmodel->ad_aprove_data($emp_id,$data,$hidid);
if($query==true)
{ //echo "hi";
?> <script>
alert('Approved');
</script><?php
//$value['result']=$this->lpmodel->selectapproverow($id);
$name=$this->session->userdata('name');
$value['name']=$name;
//$status=$this->session->set_userdata('stat');
$value['result']=$this->lpmodel->ad_selectreimb($emp_id,$status,$frmdate,$todate);
$this->load->view('ad_reimbursement',$value);
}
else
{// echo "error";
?> <script>
alert('Try Again');
</script><?php
$value['new']=$this->lpmodel->fetchname();
$this->load->view('ad_reimbursement',$value);
}
}
Related
I have put a WordPress code to change the profile. The data is being updated, but after updating it is not redirected to the main page. Now I have to redirect it to another page if it gets redirected, then data not update. How could I do that?
<form method="post" id="adduser" action="<?php the_permalink(); ?>" class="profile-field">
<table class="table table-bordered">
<tbody>
<!--tr>
<td>Name</td>
<td><?php echo $user_details['first_name'][0]; ?></td>
</tr>
<tr>
<td>Email</td>
<td><?php echo wp_get_current_user()->user_email;?></td>
</tr-->
<p class="form-username">
<label for="first-name"><?php _e('First Name', 'profile'); ?></label>
<input class="text-input" name="first-name" type="text" id="first-name"
value="<?php the_author_meta( 'first_name', $current_user->ID ); ?>" />
</p>
<p class="form-username">
<label for="last-name"><?php _e('User mail', 'profile'); ?></label>
<input class="text-input" name="last-name" type="text" id="last-name"
value="<?php the_author_meta( 'user_email', $current_user->ID ); ?>" />
</p>
<!--tr>
<td>Company Code</td>
<td><?php echo $user_details['companycode'][0]; ?></td>
</tr>
<tr>
<td>Industry</td>
<td><?php echo $user_details['industury'][0]; ?></td>
</tr>
<tr>
<td>Job title</td>
<td><?php echo $user_details['jobtitle'][0]; ?></td>
</tr>
<tr>
<td>Experience</td>
<td><?php echo $user_details['experience'][0]; ?> Years</td>
</tr>
</tbody>
</table-->
<?php do_action('edit_user_profile',$current_user); ?>
<p class="form-submit">
<?php echo $referer; ?>
<div>
<button name="updateuser" type="submit" id="updateuser" class="submit button"
value="<?php _e('Update', 'profile'); ?>">update</button>
<?php //wp_nonce_field( 'update-user' ) ?>
<input name="action" type="hidden" id="action" value="update-user" />
</p>
<!--a class="profileinfo-edit" id ="edit" href="<?php echo site_url();?>/my-profile">Update Profile</a-->
</form>
<?php endif; ?>
See: https://codex.wordpress.org/Action_Reference/profile_update
add_action( 'profile_update', 'my_profile_update', 10, 2 );
function my_profile_update( $user_id, $old_user_data ) {
// Redirect
$redirect_url = '/your-redirect/permalink';
wp_redirect( $redirect_url );
exit();
}
I am using a while loop to display results from a query.
The while loop is working fine.
In the hidden field I would like to post the values of etj12idsinging to another page.
I am submitting the form from a link using javascript.
The problem is regardless of the row I click, it only posts the first value. What should I do?
while($row= mysql_fetch_array($result))
{
$SIidsinging = $row['etj12idsinging'];
?>
<tr>
<td><?php echo $SIidnumber; ?></td>
<td><?php echo $SIidtype; ?></td>
<TD>
<form method='post' name='form1' id="form1" onclick="submitform()">
<input type="hidden" name='name2' id='name2' value="<?php echo $row['etj12idsinging']; ?>"></a>
<input type="button" value="Edit" class="btn-warning"/>
</form>
</TD>
</tr>
The javascript that I used to submit the form:
function submitform()
{
var name2=$('#name2').val();
window.alert(name2);//it keeps having first result
$('#form1').submit();
}
You can use like below codes:
<?php
while($row= mysql_fetch_array($result)) {
$SIidsinging = $row['etj12idsinging'];
?>
<form method='post' name='form1' id="form1" onclick="submitform()">
<tr>
<td><?php echo $SIidnumber; ?></td>
<td><?php echo $SIidtype; ?></td>
<TD>
<input type="hidden" name='name' value="<?php echo $row['etj12idsinging']; ?>"></a>
<input type="submit" value="Edit" class="btn-warning"/>
</TD>
</tr>
</form>
<?php
}
?>
Now in your result of post, you can get this array, by:
<?php
$names = $_POST[ 'name' ];
?>
(1) Select To book(onchange value) Then open popup is ok.
(2)open popup in Checked NetAmount then i want to get Total in Text
Box.
(3)then Cheked NetAmount To Display This Record in index page.
i Want To point(2,3).
index.php
script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(function ()
{
$("#Debit_id").change(function ()
{
var Debit_id = document.getElementById('Debit_id').value;
if(Debit_id!="")
{
window.open("getpopup.php?Debit_id="+Debit_id,'popup','width=700,height=400,left=200,top=200,scrollbars=1');
}
});
});
</script>
Book : <select name="Debit_id" id="Debit_id">
<option value="" selected="selected">Select Book</option>
<?php
$result1 = mysql_query("SELECT AccountName,CID FROM account")or die(mysql_error());
while($row1 = mysql_fetch_array($result1))
if($row1)
{ ?>
<option value="<?php echo $row1['CID']; ?>"><?php echo $row1['AccountName']; ?></option><?php
} ?>
</select>
<br />
NetAmount Total : <input type="text" class="input" name="NetAmount" id="TotalCost">
popup.php
<?php
include("../config.php");
$Debit_id = intval($_GET['Debit_id']);
?>
<table>
<tr>
<th>SrNo</th>
<th>EntryDate</th>
<th>NetAmount</th>
</tr>
<?php
$sql="SELECT * FROM transaction WHERE Credit_id = '".$Debit_id."'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$SrNo =$row['SrNo'];
$EntryDate = $row['EntryDate'];
$NetAmount =$row['NetAmount'];
?>
<tr>
<td><?php echo $SrNo ?></td>
<td><?php echo $EntryDate ?></td>
<td><?php echo $NetAmount ?><input type="checkbox" name="<?php echo $SrNo ?>" value="<?php echo $NetAmount ?>"></td>
</tr>
<?php }?>
<tr>
<td colspan="3" align="center">
<input type="submit" value="ok" />
</td>
</tr>
</table>
I have a registration portal in which I change its view according to my template and now I want to add an input field to add date of birth with date picker how to use script in this registration page to add date picker.
<html>
<head>
<title></title>
<link href="catalog/view/theme/default/stylesheet/stylesheet1.css" rel=stylesheet type="text/css" />
<link href="catalog/view/theme/default/stylesheet/register.css" rel="stylesheet" type="text/css" />
<link href="catalog/view/theme/default/stylesheet/Menu.css" rel="stylesheet" type="text/css" />
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
</head>
<body>
<div id="Holder">
<div id="Navbar">
<nav>
<ul>
<li>Login</li>
<li>Register</li>
<li>Forgot Password</li>
</ul>
</nav>
</div>
<?php if ($error_warning) { ?>
<div class="warning"><?php echo $error_warning; ?></div>
<?php } ?>
<?php echo $column_left; ?>
<div id="content"><?php echo $content_top; ?>
<h1><?php echo $heading_title; ?></h1>
<p><?php echo $text_account_already; ?></p>
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
<div id="Details">
<div id="YourPersonalDetails">
<h2><?php echo $text_your_details; ?></h2>
<div class="content">
<table class="form">
<tr>
<td><span class="required">*</span> <?php echo $entry_emp_name; ?></td>
<td><input type="text" name="emp_name" value="<?php echo $emp_name; ?>" />
<?php if ($error_emp_name) { ?>
<span class="error"><?php echo $error_emp_name; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_emp_ID; ?></td>
<td><input type="text" name="emp_ID" value="<?php echo $emp_ID; ?>" />
<?php if ($error_emp_ID) { ?>
<span class="error"><?php echo $error_emp_ID; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> Date Of Birth</td>
<td><input type="text" id="datepicker" name="dob" value="<?php echo $dob; ?>" size="12" id="dob" />
<?php if ($error_dob) { ?>
<span class="error">We require your date of birth!</span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_email; ?></td>
<td><input type="text" name="email" value="<?php echo $email; ?>" />
<?php if ($error_email) { ?>
<span class="error"><?php echo $error_email; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_mobile_no; ?></td>
<td><input type="text" name="mobile_no" value="<?php echo $mobile_no; ?>" />
<?php if ($error_mobile_no) { ?>
<span class="error"><?php echo $error_mobile_no; ?></span>
<?php } ?></td>
</tr>
</table>
</div>
</div>
<div id="YourAddress" >
<h2><?php echo $text_your_address; ?></h2>
<div class="content">
<table class="form">
<tr>
<td><?php echo $entry_company; ?></td>
<td><input type="text" name="company" value="<?php echo $company; ?>" /></td>
</tr>
<tr style="display: <?php echo (count($customer_groups) > 1 ? 'table-row' : 'none'); ?>;">
<td><?php echo $entry_customer_group; ?></td>
<td><?php foreach ($customer_groups as $customer_group) { ?>
<?php if ($customer_group['customer_group_id'] == $customer_group_id) { ?>
<input type="radio" name="customer_group_id" value="<?php echo $customer_group['customer_group_id']; ?>" id="customer_group_id<?php echo $customer_group['customer_group_id']; ?>" checked="checked" />
<label for="customer_group_id<?php echo $customer_group['customer_group_id']; ?>"><?php echo $customer_group['name']; ?></label>
<br />
<?php } else { ?>
<input type="radio" name="customer_group_id" value="<?php echo $customer_group['customer_group_id']; ?>" id="customer_group_id<?php echo $customer_group['customer_group_id']; ?>" />
<label for="customer_group_id<?php echo $customer_group['customer_group_id']; ?>"><?php echo $customer_group['name']; ?></label>
<br />
<?php } ?>
<?php } ?></td>
</tr>
<tr id="company-id-display">
<td><span id="company-id-required" class="required">*</span> <?php echo $entry_company_id; ?></td>
<td><input type="text" name="company_id" value="<?php echo $company_id; ?>" />
<?php if ($error_company_id) { ?>
<span class="error"><?php echo $error_company_id; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_office_location; ?></td>
<td><input type="text" name="office_location" value="<?php echo $office_location; ?>" />
<?php if ($error_office_location) { ?>
<span class="error"><?php echo $error_office_location; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><?php echo $entry_address_2; ?></td>
<td><input type="text" name="address_2" value="<?php echo $address_2; ?>" /></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_city; ?></td>
<td><input type="text" name="city" value="<?php echo $city; ?>" />
<?php if ($error_city) { ?>
<span class="error"><?php echo $error_city; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span id="postcode-required" class="required">*</span> <?php echo $entry_postcode; ?></td>
<td><input type="text" name="postcode" value="<?php echo $postcode; ?>" />
<?php if ($error_postcode) { ?>
<span class="error"><?php echo $error_postcode; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_country; ?></td>
<td><select name="country_id">
<option value=""><?php echo $text_select; ?></option>
<?php foreach ($countries as $country) { ?>
<?php if ($country['country_id'] == $country_id) { ?>
<option value="<?php echo $country['country_id']; ?>" selected="selected"><?php echo $country['name']; ?></option>
<?php } else { ?>
<option value="<?php echo $country['country_id']; ?>"><?php echo $country['name']; ?></option>
<?php } ?>
<?php } ?>
</select>
<?php if ($error_country) { ?>
<span class="error"><?php echo $error_country; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_zone; ?></td>
<td><select name="zone_id">
<option value=""><?php echo $text_select; ?></option>
<option value="1483">Delhi</option>
<option value="1505">UP</option>
</select>
<?php if ($error_zone) { ?>
<span class="error"><?php echo $error_zone; ?></span>
<?php } ?></td>
</tr>
</table>
</div>
</div>
</div>
<div id="YourPassword">
<h2><?php echo $text_your_password; ?></h2>
<div class="content">
<table class="form">
<tr>
<td><span class="required">*</span> <?php echo $entry_password; ?></td>
<td><input type="password" name="password" value="<?php echo $password; ?>" />
<?php if ($error_password) { ?>
<span class="error"><?php echo $error_password; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_confirm; ?></td>
<td><input type="password" name="confirm" value="<?php echo $confirm; ?>" />
<?php if ($error_confirm) { ?>
<span class="error"><?php echo $error_confirm; ?></span>
<?php } ?></td>
</tr>
</table>
</div>
</div>
<div id="NewsLetter">
<h2><?php echo $text_newsletter; ?></h2>
<div class="content">
<table class="form">
<tr>
<td><?php echo $entry_newsletter; ?></td>
<td><?php if ($newsletter) { ?>
<input type="radio" name="newsletter" value="1" checked="checked" />
<?php echo $text_yes; ?>
<input type="radio" name="newsletter" value="0" />
<?php echo $text_no; ?>
<?php } else { ?>
<input type="radio" name="newsletter" value="1" />
<?php echo $text_yes; ?>
<input type="radio" name="newsletter" value="0" checked="checked" />
<?php echo $text_no; ?>
<?php } ?></td>
</tr>
</table>
</div>
</div>
<?php if ($text_agree) { ?>
<div class="buttons">
<div class="right"><?php echo $text_agree; ?>
<?php if ($agree) { ?>
<input type="checkbox" name="agree" value="1" checked="checked" />
<?php } else { ?>
<input type="checkbox" name="agree" value="1" />
<?php } ?>
<input type="submit" value="<?php echo $button_continue; ?>" class="button" />
</div>
</div>
<?php } else { ?>
<div class="buttons">
<div class="right">
<input type="submit" value="<?php echo $button_continue; ?>" class="button" />
</div>
</div>
<?php } ?>
</form>
<?php echo $content_bottom; ?></div>
<script type="text/javascript"><!--
$('input[name=\'customer_group_id\']:checked').live('change', function() {
var customer_group = [];
<?php foreach ($customer_groups as $customer_group) { ?>
customer_group[<?php echo $customer_group['customer_group_id']; ?>] = [];
customer_group[<?php echo $customer_group['customer_group_id']; ?>]['company_id_display'] = '<?php echo $customer_group['company_id_display']; ?>';
customer_group[<?php echo $customer_group['customer_group_id']; ?>]['company_id_required'] = '<?php echo $customer_group['company_id_required']; ?>';
customer_group[<?php echo $customer_group['customer_group_id']; ?>]['tax_id_display'] = '<?php echo $customer_group['tax_id_display']; ?>';
customer_group[<?php echo $customer_group['customer_group_id']; ?>]['tax_id_required'] = '<?php echo $customer_group['tax_id_required']; ?>';
<?php } ?>
if (customer_group[this.value]) {
if (customer_group[this.value]['company_id_display'] == '1') {
$('#company-id-display').show();
} else {
$('#company-id-display').hide();
}
if (customer_group[this.value]['company_id_required'] == '1') {
$('#company-id-required').show();
} else {
$('#company-id-required').hide();
}
if (customer_group[this.value]['tax_id_display'] == '1') {
$('#tax-id-display').show();
} else {
$('#tax-id-display').hide();
}
if (customer_group[this.value]['tax_id_required'] == '1') {
$('#tax-id-required').show();
} else {
$('#tax-id-required').hide();
}
}
});
$('input[name=\'customer_group_id\']:checked').trigger('change');
//--></script>
<script type="text/javascript"><!--
$('select[name=\'country_id\']').bind('change', function() {
$.ajax({
url: 'index.php?route=account/register/country&country_id=' + this.value,
dataType: 'json',
beforeSend: function() {
$('select[name=\'country_id\']').after('<span class="wait"> <img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
},
complete: function() {
$('.wait').remove();
},
success: function(json) {
if (json['postcode_required'] == '1') {
$('#postcode-required').show();
} else {
$('#postcode-required').hide();
}
html = '<option value=""><?php echo $text_select; ?></option>';
if (json['zone'] != '') {
for (i = 0; i < json['zone'].length; i++) {
html += '<option value="' + json['zone'][i]['zone_id'] + '"';
if (json['zone'][i]['zone_id'] == '<?php echo $zone_id; ?>') {
html += ' selected="selected"';
}
html += '>' + json['zone'][i]['name'] + '</option>';
}
} else {
html += '<option value="0" selected="selected"><?php echo $text_none; ?></option>';
}
$('select[name=\'zone_id\']').html(html);
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
});
$('select[name=\'country_id\']').trigger('change');
//--></script>
<script type="text/javascript"><!--
$(document).ready(function() {
$('.colorbox').colorbox({
width: 640,
height: 480
});
});
//--></script>
</div>
</body>
</html>
You can use Jquery date picker. Look at this https://jqueryui.com/datepicker/
You just need to use
("#inputField").Datepicker()
Place your html anywhere in the form.
The line above should go inside script> tag
Update You need to include jquery files like this in your page's header section
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
I have a problem, I have little understanding about jquery that's why I am having a hard time with my code. I have a pagination of products. And there are checkboxes on it. And my simple goal is to disable the products if the checkboxes are selected. But I can't do it in one form because I have already another process in my form which is delete products if selected. That's why I am planning to create a form action in my jquery and pass all the product id from my checkbox to a json array. But how can I do that?
Here's a bit of my code
<form action="<?php echo $delete; ?>" method="post" enctype="multipart/form-data" id="form">
<table class="list">
<thead>
<tr>
<td width="1" style="text-align: center;"><input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);" /></td>
<td class="left"><?php echo $column_name; ?></td>
<td class="right"><?php echo $column_sort_order; ?></td>
<td class="left"><?php echo $column_status; ?></td>
<td class="right"><?php echo $column_action; ?></td>
</tr>
</thead>
<tbody>
<?php if ($categories) { ?>
<?php foreach ($categories as $category) { ?>
<tr>
<td style="text-align: center;"><?php if ($category['selected']) { ?>
<input type="checkbox" name="selected[]" value="<?php echo $category['category_id']; ?>" checked="checked" />
<?php } else { ?>
<input type="checkbox" name="selected[]" value="<?php echo $category['category_id']; ?>" />
<?php } ?></td>
<td class="left"><?php echo $category['name']; ?></td>
<td class="right"><?php echo $category['sort_order']; ?></td>
<td class="right"><?php echo ($category['status'] == 1 ? 'Enable' : 'Disable'); ?></td>
<td class="right"><?php foreach ($category['action'] as $action) { ?>
[ <?php echo $action['text']; ?> ]
<?php } ?></td>
</tr>
<?php } ?>
<?php } else { ?>
<tr>
<td class="center" colspan="4"><?php echo $text_no_results; ?></td>
</tr>
<?php } ?>
</tbody>
</table>
</form>
<br />
<div align="right">
<select name="action_select">
<option value="enable">Enable Selected</option>
<option value="disable">Disable Selected</option>
</select>
<input type="button" class="button" id="update_status" value="Update Status" />
</div>
<br />
Here's my jquery sample
<script type="text/javascript">
$("#update_status").on('click', function(){
//how can I get the id of my checkboxes and assign it to a json array
//How can I create a form inside it?
});
</script>
That's all guys I hope you can understand my question. Thanks.
Otherwise you can use the below example code
<script>
$(document).ready(function()
{
$("input[type=checkbox]").click(function()
{
var categoryVals = [];
categoryVals.push('');
$('#Category_category :checked').each(function() {
categoryVals.push($(this).val());
});
$.ajax({
type:"POST",
url:"<?php echo $this->createUrl('ads/searchresult'); ?>", //url of the action page
data:{'category': categoryVals},
success : function(response){
//code to do somethng if its success
}
});
}
}
</script>
try
$('input[name="selected[]"]:checked').each(function() {
console.log(this.value);
});
for more info :- use jQuery to get values of selected checkboxes
Try
var values = $('.list input[name="selected[]"]:checked').map(function () {
return this.value;
}).get();