I have nine text boxes wrapped in a form but when post to codeigniter controller, there are two specific text boxes have no value but they actually have.
Anyone encountered this issue before ? what is actually wrong ?
Form
<form name="frm_RRequest" id="frm_RRequest" action="<?php echo site_url('user/add_recommendation_request/'); ?>" method="post">
<tbody>
<tr>
<td class="col-left">Date</td>
<td class="col-middle"><input class="datepicker" type="text" name="txtStartDate" id="txtStartDate" class="datepicker" placeholder="Click to select a start date.."></td>
<td class="col-middle"><input class="datepicker" type="text" name="txtEndDate" id="txtEndDate" class="datepicker" placeholder="Click to select a end date.."></td>
<td class="col-right"><div class="error" id="error_date"> </div></td>
</tr>
<tr>
<td class="col-left">Travel time</td>
<td class="col-middle"><input type="text" class="ptTimeSelect input" name="txtStartTime" id="txtStartTime" placeholder="Click to select start time.." data-default-time="false"></td>
<td class="col-middle"><input type="text" class="ptTimeSelect input" name="txtEndTime" id="txtEndTime" placeholder="Click to select end time.." data-default-time="false"></td>
<td class="col-right"><div class="error" id="error_time"> </div></td>
</tr>
<tr>
<td class="col-left">Location</td>
<td class="col-middle-2"><input type="text" class="inputWithImge" name="txtStartLocation" id="txtStartLocation" onmouseover="display_text(this)" placeholder="Click the icon to select a start point"/><img src="<?php echo base_url('assets/images/search_icon.png'); ?>" class="location-icon" title="Click to show map" name="location-icon_start" value="StartLocation"/></td>
<td class="col-middle-2"><input type="text" class="inputWithImge" name="txtEndLocation" id="txtEndLocation" onmouseover="display_text(this)" placeholder="Click the icon to select a end point"/><img src="<?php echo base_url('assets/images/search_icon.png'); ?>" class="location-icon" title="Click to show map" name="location-icon_end" value="EndLocation" /></td>
<td class="col-right"><div class="error" id="error_location"> </div></td>
</tr>
<input type="hidden" name="txtStartLocation_Coordinates" id="txtStartLocation_Coordinates">
<input type="hidden" name="txtEndLocation_Coordinates" id="txtEndLocation_Coordinates">
</tbody>
</table>
</div>
<div><input type="button" class="button" id="btnGo" name="btnGo" value="Input detail" /> <span> << click this button if the travel time and location(s) are different for each day</span></div>
<div id="detail">
</div>
<input type="hidden" name="txtTotalDetail" id="txtTotalDetail">
<input type="hidden" name="txtNoOfDays" id="txtNoOfDays">
<div> </div>
<div><input type="button" id="btn_SaveDetail" name="btn_SaveDetail" class="button" value="Save" /></div>
</form>
<script>
function display_text(obj){
var value = obj.value;
obj.title = value;
}
</script>
Controller :
$total_detail = $this->input->post("txtTotalDetail");
$noOfDays = $this->input->post("txtNoOfDays");
$userid = $this->session->userdata('id');
$start_date = $this->input->post("txtStartDate");
$end_date = $this->input->post("txtEndDate");
$start_time = $this->input->post("txtStartTime");
$end_time = $this->input->post("txtEndTime");
$start_location = $this->input->post("txtStartLocation");
$end_location = $this->input->post("txtEndLocation");
$start_location_coor = $this->input->post("txtStartLocation_Coordinates");
$end_location_coor = $this->input->post("txtEndLocation_Coordinates");
These two text boxes have no value :
$start_location = $this->input->post("txtStartLocation");
$end_location = $this->input->post("txtEndLocation");
It is possible you forgot to use $this->form_validation->set_rules() on those particular fields.
Put value in your input tag like
<input type="hidden" name="txtStartLocation_Coordinates" value ="<?php echo $this->input->post('txtStartLocation_Coordinates');?>" id="txtStartLocation_Coordinates">
<input type="hidden" name="txtEndLocation_Coordinates" value ="<?php echo $this->input->post('txtEndLocation_Coordinates');?>" id="txtEndLocation_Coordinates">
<script>
$(function(){
$('#txtStartLocation_Coordinates').val("your value");
$('#txtEndLocation_Coordinates').val("your value");
});
</script>
Related
i'm setting up donate option on a website using przelewy24.pl. They have this startup template to send values by $_GET method to their website.
Everything works fine exept the amount field. Przelewy24 needs a gr amount (like cents) and i would like for the donor to type in integer in full zł (like $).
If the upper is not clear - when i type 100 in the field, it sends it to przelewy24 as 100 gr, whitch will be 1 zł.
I need to know how could i format the amount sent to them as in simple calculation - when 100 is typed, get sends 10000. (x*100)
The form used is shown below. The quick-start guide is avaliable here, but only in polish
<form method="get" action="https://sklep.przelewy24.pl/zakup.php">
<input type="hidden" name="z24_id_sprzedawcy" value="TWOJ_ID">
<input type="hidden" name="z24_crc" value="KLUCZ_ZAKUPU">
<input type="hidden" name="z24_return_url" value="TWOJASTRONA.PL">
<input type="hidden" name="z24_language" value="pl">
<table>
<tr>
<td align="right">Nazwa produktu:</td>
<td>
<input type="text" name="z24_nazwa" value="Opłata za rezerwację NR: 04/234/A3953">
</td>
</tr>
<tr>
<td align="right">Dodatkowy opis:</td>
<td>
<textarea name="z24_opis" style="width:250px">Dodatkowe informacje...
</textarea>
</td>
</tr>
<tr>
<td align="right">Do zapłaty:</td>
<td><input type="text" name="z24_kwota"></td><!--KWOTA W GROSZACH-->
</tr>
</table>
<input type="submit" value="zapłać z przelewy24.pl">
</form>
You can do it with a simple Javascript code.
You need to capture the value from input, transform it, and put the value on input hidden:
function formatMoney(e) {
document.getElementById('z24_kwota').value = (!isNaN(e.target.value) ? e.target.value : 0) * 100
// just to debug.. you can remove this line:
document.getElementById('final_value').innerHTML = document.getElementById('z24_kwota').value
}
<form method="get" action="https://sklep.przelewy24.pl/zakup.php">
<input type="hidden" name="z24_id_sprzedawcy" value="TWOJ_ID">
<input type="hidden" name="z24_crc" value="KLUCZ_ZAKUPU">
<input type="hidden" name="z24_return_url" value="TWOJASTRONA.PL">
<input type="hidden" name="z24_language" value="pl">
<table>
<tr>
<td align="right">Nazwa produktu:</td>
<td>
<input type="text" name="z24_nazwa" value="Opłata za rezerwację NR: 04/234/A3953">
</td>
</tr>
<tr>
<td align="right">Dodatkowy opis:</td>
<td>
<textarea name="z24_opis" style="width:250px">Dodatkowe informacje...
</textarea>
</td>
</tr>
<tr>
<td align="right">Do zapłaty:</td>
<td>
<input type="hidden" name="z24_kwota" id="z24_kwota">
<input type="text" onkeyup="formatMoney(event)"></td><!--KWOTA W GROSZACH-->
</tr>
</table>
<input type="submit" value="zapłać z przelewy24.pl">
</form>
<!-- you can remove this line: -->
Final Value: <span id="final_value"></span>
Try changing the value before submitting the form like below,
<form method="get" id="myform" action="https://sklep.przelewy24.pl/zakup.php">
<input type="hidden" name="z24_id_sprzedawcy" value="TWOJ_ID">
<input type="hidden" name="z24_crc" value="KLUCZ_ZAKUPU">
<input type="hidden" name="z24_return_url" value="TWOJASTRONA.PL">
<input type="hidden" name="z24_language" value="pl">
<table>
<tr>
<td align="right">Nazwa produktu:</td>
<td>
<input type="text" name="z24_nazwa" value="Opłata za rezerwację NR: 04/234/A3953">
</td>
</tr>
<tr>
<td align="right">Dodatkowy opis:</td>
<td>
<textarea name="z24_opis" style="width:250px">Dodatkowe informacje...
</textarea>
</td>
</tr>
<tr>
<td align="right">Do zapłaty:</td>
<td><input type="text" name="z24_kwota"></td><!--KWOTA W GROSZACH-->
</tr>
</table>
<input type="submit" value="zapłać z przelewy24.pl">
</form>
<script
src="http://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script type="text/javascript">
var firstSubmit = false;
$('#myform').on('submit',function(e){
if(!firstSubmit){
e.preventDefault();
firstSubmit = true;
var amount = parseInt($('input[name=z24_kwota]').val());
$('input[name=z24_kwota]').val(amount*100);
$('#myform').trigger('submit');
}
})
</script>
Note: I have given an id to the form as myform
i update php form and change the value but it cant change it saves the same previous value
<tr>
<td width="22%">Course Fees</td>
<td width="38%">
<div id="total_fees">
<input type="text" class="input_text" name="total_fees" id="toal_fees" onblur="show_record(this.value,1)" value="<?php if($_POST['total_fees']) echo $_POST['total_fees']; else echo $row['total_fees'];?>" />
</div>
</td>
</tr>
Please see the screenshot of source code and input filed . i changed the value in input field but it remain same in source code and save source code value db
The input values not immediately affect on your input but You will get your new value while you submitting your form.
So submit your form and then print the values of the Request. You will find the new value of total_fees into the request parameters.
HTML CODE
<form name="jqueryForm" method="post" id="jqueryForm" enctype="multipart/form-data" onSubmit="return validme();">
<table border="0" cellspacing="15" cellpadding="0" width="100%" >
<tr>
<td width="22%">Course Fees</td>
<td width="38%">
<div id=total_fees>
<input type="text" class="input_text" name="total_fees" id="toal_fees" onblur="show_record(this.value,1)" value="<?php if($_POST['total_fees']) echo $_POST['total_fees']; else echo $row['total_fees'];?>" />
</div>
</td>
<td width="40%"></td>
</tr>
<tr>
<td width="22%">Discount in <input type="radio" name='discount_type' value="<?php if($_POST['discount_type']) echo $_POST['discount_type']; else echo percent; ?>" checked="checked" onChange="show_record()" />% or <input type="radio" name='discount_type' value="<?php if($_POST['discount_type']) echo $_POST['discount_type']; else echo cash; ?>" onChange="show_record()" />Cash</td>
<td width="38%"><input type="text" class="input_text" name="concession" id="concession" value="<?php if($_POST['concession']) echo $_POST['concession']; else if($row_record['discount'] !=0) echo $row_record['discount']; else echo 0; ?>" onBlur="show_record()"/>
</td>
<td width="40%"></td>
</tr>
</table>
<input type="submit" value="Save Record" name="save_changes" />
</form>
PHP CODE FOR SAVE IN DB
if(isset($_POST['save_changes']))
{
$total_fees=($_POST['total_fees']) ? $_POST['total_fees'] : "0";
$data_record['total_fees']=$total_fees;
$courses_id=$db->query_insert("enroll", $data_record);
}
I have some content and a table inside my <form> tags. On submitting, when I echo the post value coming from the form, it shows the value 1 against each entered value.
This surprises me and I would like to know why this is happening?
Even when I have commented out all of my CSS and JavaScript linked libraries/files, a 1 is still returned.
HTML:
<div id="page-wrap">
<form method="post" action="save_view.php"> <textarea id="header">INVOICE</textarea>
<div id="identity">
<div> <img id="image" src="images/logo_1.png" alt="logo" /> </div>
</div>
<div style="clear:both"></div>
<div id="customer">
<table id="meta">
<tr>
<td class="meta-head">Invoice #</td>
<td> <input name="Invoice" type="text" /> </td>
</tr>
<tr>
<td class="meta-head">Customer Name</td>
<td> <input name="cname" type="text" /> </td>
</tr>
<tr>
<td class="meta-head">Paid Date</td>
<td> <input name="pdate" type="text" /> </td>
</tr>
<tr>
<td class="meta-head">Sales Person</td>
<td> <input name="sperson" type="text" /> </td>
</tr>
</table>
</div> <input name="submit" type="submit" value="Submit" /> </form>
</div>
save_view.php:
if(isset($_POST['submit']))
{
echo $invoice = isset($_POST['Invoice']);
die();
}
isset returns a boolean.
if(isset($_POST['submit']))
{
$invoice = isset($_POST['Invoice']) ? $_POST['Invoice'] : '';
echo ($invoice);
die();
}
isset method is for determinate if a variable exist.
So when you do $invoice = isset($_POST['Invoice']);
$invoice = 1 //variable exist
$invoice =0 //variable not exist
Try
if(isset($_POST['Invoice']))
echo $invoice = $_POST['Invoice'];
isset()
Determine if a variable is set and is not NULL
To get value you have to use like this
if(isset($_POST['Invoice']){
echo $invoice = $_POST['Invoice'];
}
die();
You got TRUE every time and that's the reason you got only 1 everytime
isset() always returns either true or false, echo your data like this
echo"<pre>";print_r($_POST['Invoice']);die;
I have a form like the code below, when the submit button is clicked, not all elements of the form being sent to Codeigniter's controller, especially txtStartLocation and txtEndLocation. I clearly defined the names for both elements.
Here what I got when var_dump the post element
array(8) {
["txtStartDate"]=> string(10) "2015-09-29"
["txtEndDate"]=> string(10) "2015-09-30"
["txtStartTime"]=> string(4) "8:45"
["txtEndTime"]=> string(5) "14:45"
["txtStartLocation_Coordinates"]=> string(32) "(36.106965, -112.11299700000001)"
["txtEndLocation_Coordinates"]=> string(23) "(37.559152, 126.983967)"
["txtTotalDetail"]=> string(1) "0"
["txtNoOfDays"]=> string(1) "2" }`
Form View
<form name="frm_RRequest" id="frm_RRequest" action="<?php echo site_url('user/add_recommendation_request/'); ?>" method="post">
<tbody>
<tr>
<td class="col-left">Date</td>
<td class="col-middle"><input class="datepicker" type="text" name="txtStartDate" id="txtStartDate" class="datepicker" placeholder="Click to select a start date.."></td>
<td class="col-middle"><input class="datepicker" type="text" name="txtEndDate" id="txtEndDate" class="datepicker" placeholder="Click to select a end date.."></td>
<td class="col-right"><div class="error" id="error_date"> </div></td>
</tr>
<tr>
<td class="col-left">Travel time</td>
<td class="col-middle"><input type="text" class="ptTimeSelect input" name="txtStartTime" id="txtStartTime" placeholder="Click to select start time.." data-default-time="false"></td>
<td class="col-middle"><input type="text" class="ptTimeSelect input" name="txtEndTime" id="txtEndTime" placeholder="Click to select end time.." data-default-time="false"></td>
<td class="col-right"><div class="error" id="error_time"> </div></td>
</tr>
<tr>
<td class="col-left">Location</td>
<td class="col-middle-2"><input type="text" class="inputWithImge" name="txtStartLocation" id="txtStartLocation" onmouseover="display_text(this)" placeholder="Click the icon to select a start point"/><img src="<?php echo base_url('assets/images/search_icon.png'); ?>" class="location-icon" title="Click to show map" name="location-icon_start" value="StartLocation"/></td>
<td class="col-middle-2"><input type="text" class="inputWithImge" name="txtEndLocation" id="txtEndLocation" onmouseover="display_text(this)" placeholder="Click the icon to select a end point"/><img src="<?php echo base_url('assets/images/search_icon.png'); ?>" class="location-icon" title="Click to show map" name="location-icon_end" value="EndLocation" /></td>
<td class="col-right"><div class="error" id="error_location"> </div></td>
</tr>
</tbody>
</table>
</div>
<input type="hidden" name="txtStartLocation_Coordinates" id="txtStartLocation_Coordinates">
<input type="hidden" name="txtEndLocation_Coordinates" id="txtEndLocation_Coordinates">
<div><input type="button" class="button" id="btnGo" name="btnGo" value="Input detail" /> <span> << click this button if the travel time and location(s) are different for each day</span></div>
<div id="detail">
</div>
<input type="hidden" name="txtTotalDetail" id="txtTotalDetail">
<input type="hidden" name="txtNoOfDays" id="txtNoOfDays">
<div> </div>
<div><input type="button" id="btn_SaveDetail" name="btn_SaveDetail" class="button" value="Save" /></div>
</form>
Try to use open/close form like this:
<?php echo form_open("controller/function"); ?>
<?php echo form_close(); ?>
then change
<input type="button" id="btn_SaveDetail" name="btn_SaveDetail" class="button" value="Save" />
into
<input type="submit" id="btn_SaveDetail" name="btn_SaveDetail" class="button" value="Save" />
I'm trying to build an application using php. in "stock_out.php", i wanna create a form that include two barcodes. I have 8 fields. (1)Effectivedate,(2)Partnumber,(3)Description1,(4)Description2,(5)NPK,(6)Nama,(7)QtyOut,(8)Reason. I wanna using barcode-reader in "Partnumber" and "NPK".
I have some problems:
1. When i press enter, it's respon for button submit.
2. Actually, when i press enter in Partnumber, i want show details data in "description1" and "description2". As well as in NPK, i want show details data in "nama"
3. In the end of form, i still want to submit this form into database.
I'm newbie in AJAX, so i still don't know how to implementation AJAX in PHP. This is my code, I am grateful for the help
<html><body>
<div id="outerContainer">
<?php include("headerFile.html"); ?>
<?php include("navigationFile.html"); ?>
<div id="bodyContainer">
<div id="pageBodyTitle"> Stock Out </div> <br>
<form id="formSearch" name="formSearch" method="post" action="proses_out.php" onSubmit="return cek_data();">
<table id="messageTable">
<tr>
<td class="heading"> Effective Date </td>
<td>
<input class="inputField" name="tgl" type="text" readonly value="<?php echo $_POST['tgl']?>" tabindex="1"/>
<script language='JavaScript'>new tcal ({'formname': 'formSearch','controlname': 'tgl'});</script>
</td>
</tr>
<tr>
<td class="heading"> Part Number </td>
<td><input type='text' name='txtItem' id='txtItem' size="20" class="inputField" value='<?php echo $item;?>' tabindex="2" />
<img src='search.ico' onClick='open_win_item()'> </td>
</tr>
<tr>
<td class="heading">Description1</td>
<td><input type='text' name='txtDesc1' id='txtDesc1' size="50" value='<?php echo $desc1;?>' readonly /></td>
</tr>
<tr>
<td class="heading">Description2</td>
<td><input type='text' name='txtDesc2' id='txtDesc2' size="50" value='<?php echo $desc2;?>' readonly /></td>
</tr>
<tr>
<td class="heading"> NPK </td>
<td><input type='text' name='txtNpk' id='txtNpk' size="20" maxlength="5" class="inputField" value='<?php echo $tr_no;?>' tabindex="3" />
<img src='search.ico' onClick='open_win_npk()'></td>
</tr>
<tr>
<td class="heading">Nama</td>
<td><input type='text' name='txtName' id='txtName' size="30" value='<?php echo $nama;?>' readonly /></td>
</tr>
<tr>
<td class="heading"> Qty Out </td>
<td><input type='text' name='txtQty' id='txtQty' size="5" class="inputField" tabindex="4"/></td>
</tr>
<tr>
<td class="heading"> Reason </td>
<td><select class="inputField" name="choose" id="choose" value="" tabindex="5">
<?php
include "/class/connect_SQL.class.php";
$sql = "select reason_code from Inv_reason_master";
$query = mssql_query($sql);
while ($row = mssql_fetch_array($query))
{
$coba = $row['reason_code'];
?>
<option value="<?php echo $coba; ?>"><?php echo $coba;?></option>
<?php
}
?>
</select></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="Submit" value="Save" class="formButton2" tabindex="6"/>
<input type="reset" name="reset" value="Cancel" class="formButton2" tabindex="7"/>
</td>
</tr>
</table>
</form>
</div>
<?php
if(isset($_GET["message"]) and $_GET["message"]='save')
{
echo "<script language=\"javascript\"> alert('Data Tersimpan!') </script>";
}
?>
<?php include("footerFile.html"); ?>
</div>
You will have to prevent the response of the "Enter"-key. If you are using jquery in your project you can prevent it with this code:
$(function() {
$("form").bind("keypress", function(e) {
if (e.keyCode == 13) return false;
});
});
To bind Enter key to "Part number" field instead you could try this:
$('#txtItem').keypress(function(e) {
if (e.keyCode == 13) {
alert('Enter is pressed in part number');
}
});