On Checkbox Changed event I am copying hidden values to my textbox,
now when I try to add value using jquery its gives me [Object object].
HTML Code
My hidden variables values
<div class="reserve-form">
<span>Name: </span><span><?php echo $user_data[0]->first_name.' '.$user_data[0]->last_name; ?>
<input type="hidden" id="name_account" value="<?php echo $user_data[0]->first_name.' '.$user_data[0]->last_name; ?>" />
</span>
<span>Email Address: </span><span><?php echo $user_data[0]->email_id; ?>
<input type="hidden" id="email_account" value="<?php echo $user_data[0]->email_id; ?>" />
</span>
<span>Phone Number: </span><span><?php echo $user_data[0]->phone_no; ?>
<input type="hidden" id="phoneno_account" value="<?php echo $user_data[0]->phone_no; ?>">
</span>
<div class="passenger-checkbox">
<input type="checkbox" name="duplicate_info" id="duplicate_info" class="css-checkbox" />
<label for="duplicate_info" class="css-label">Is passenger info same as account holder</label>
</div>
</div>
**Where I need to append it**
<div id="passanger_info">
<input type="text" class="form-control" id="name[]" name="name[]" placeholder="Name">
<input type="text" class="form-control" id="email_address[]" name="email_address[]" placeholder="Email Address">
<input type="text" class="form-control" id="phone_number[]" name="phone_number[]" placeholder="Phone Number">
<button type="button" class="removebtn"><i class="fa fa-times"></i></button>
</div>
$("#duplicate_info").change(function() {
if(this.checked)
{
isChecked();
}
else
{
alert("Unchecked")
}
});
function isChecked()
{
//hidden variables values
var name_account = $('#name_account').val();
var email_account = $('#email_account').val();
var phoneno_account = $('#phoneno_account').val();
alert(name_account);
var name = $('#name').val(name_account);
alert(name);
var email_address = $('#email_address').val(email_account);
var phone_number = $('#phone_number').val(phoneno_account);
}
It's like when I copy name_account to name and try to alert the name it gives me Object Object instead of values. What I am missing?
You have to set the value, before you take from it.
setting value = $('#name').val(name_account)
taking the value = var name = $('#name').val();
The problem in your code is [] in your id
$("#duplicate_info").change(function() {
if (this.checked) {
isChecked();
} else {
alert("Unchecked")
}
});
function isChecked() {
//hidden variables values
var name_account = $('#name_account').val();
console.log("input val of #name_account is : " + name_account);
$('#name').val(name_account)
var name = $('#name').val();
console.log("input val of #name is : " + name);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="reserve-form">
<span>Name: </span><span>Carsten
<input type="hidden" id="name_account" value="Carsten" />
</span>
<span>Email Address: </span><span><?php echo $user_data[0]->email_id; ?>
<input type="hidden" id="email_account" value="<?php echo $user_data[0]->email_id; ?>" />
</span>
<span>Phone Number: </span><span><?php echo $user_data[0]->phone_no; ?>
<input type="hidden" id="phoneno_account" value="<?php echo $user_data[0]->phone_no; ?>">
</span>
<div class="passenger-checkbox">
<input type="checkbox" name="duplicate_info" id="duplicate_info" class="css-checkbox" />
<label for="duplicate_info" class="css-label">Is passenger info same as account holder</label>
</div>
</div>
**Where I need to append it**
<div id="passanger_info">
<input type="text" class="form-control" id="name" name="name[]" placeholder="Name">
<input type="text" class="form-control" id="email_address[]" name="email_address[]" placeholder="Email Address">
<input type="text" class="form-control" id="phone_number[]" name="phone_number[]" placeholder="Phone Number">
<button type="button" class="removebtn"><i class="fa fa-times"></i></button>
</div>
Check below example:
Fill up the details and click on checkbox.
$("#duplicate_info").change(function() {
if(this.checked)
{
isChecked();
}
else
{
alert("Unchecked")
}
});
function isChecked()
{
//hidden variables values
var name_account = $('#name_account').val();
var email_account = $('#email_account').val();
var phoneno_account = $('#phoneno_account').val();
alert(name_account);
$('#name').val(name_account);
var name = $('#name').val();
alert(name);
var email_address = $('#email_address').val(email_account);
var phone_number = $('#phone_number').val(phoneno_account);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
My hidden variables values
<div class="reserve-form">
<span>Name: </span><span>
<input type="hidden" id="name" value="" />
</span>
<span>Email Address: </span><span>
<input type="hidden" id="email_account" value="" />
</span>
<span>Phone Number: </span><span>
<input type="hidden" id="phoneno_account" value="">
</span>
<div class="passenger-checkbox">
<input type="checkbox" name="duplicate_info" id="duplicate_info" class="css-checkbox" />
<label for="duplicate_info" class="css-label">Is passenger info same as account holder</label>
</div>
</div>
**Where I need to append it**
<div id="passanger_info">
<input type="text" class="form-control" id="name_account" name="name_account[]" placeholder="Name">
<input type="text" class="form-control" id="email_address" name="email_address[]" placeholder="Email Address">
<input type="text" class="form-control" id="phone_number" name="phone_number[]" placeholder="Phone Number">
<button type="button" class="removebtn"><i class="fa fa-times"></i></button>
</div>
Related
my code is not inserting any data on my php, im using a form that will display values but my code in update is not working. please help,
here is my code in php :
if (isset($_POST['update'])) {
$landowner_id = $_POST['landowner_id'];
$firstname = $_POST['firstname'];
$middlename = $_POST['middlename'];
$lastname = $_POST['lastname'];
$municipality = $_POST['municipality'];
$barangay = $_POST['barnagay'];
$areacovered = $_POST['areacovered'];
$sex = $_POST['sex'];
mysqli_query($db, "UPDATE info SET firstname='$firstname', middlename='$middlename', lastnamename='$lastname', municipality='$municipality', barangay='$barangay', areacovered='$areacovered', sex='$sex' WHERE landowner_id=$landowner_id");
$_SESSION['message'] = "Address updated!";
}
here is my html
<div class="form-wrapper">
<input type="number" id = "check" name="firstname" placeholder="First Name" class="input-field" value="<?php echo $landowner_id;?>" required>
</div>
<div class="form-wrapper">
<input type="text" id = "check" name="firstname" placeholder="First Name" class="input-field" value="<?php echo $firstname;?>" required>
</div>
<div class="form-wrapper">
<input type="text" name="middlename" placeholder="Middle Name" class="input-field" value="<?php echo $middlename;?>">
</div>
<div class="form-wrapper">
<input type="text" name="lastname" placeholder="Last Name" class="input-field" value="<?php echo $lastname;?>" required>
</div>
<div class="form-wrapper">
<input type="text" name="municipality" placeholder="Municipality" class="input-field" value="<?php echo $municipality;?>" required>
</div>
<div class="form-wrapper">
<input type="text" name="barangay" placeholder="Barangay" class="input-field" value="<?php echo $barangay;?>" >
</div>
<div class="form-wrapper">
<input type="text" id = "check" name="areacovered" placeholder="Area Covered" class="input-field" value="<?php echo $areacovered;?>" required>
</div>
<div class="form-wrapper">
<input type="text" id = "check" name="sex" placeholder="Sex" class="input-field" value="<?php echo $sex;?>" required>
<br>
<button class="btn" type="submit" name="update" >Update</button>
</div>
I don't see any "form" tag. Are you missing to wrap your "form-wrapper" into a tag? Something like this:
<form action="" method="post">
<div class="form-wrapper">
<input type="number" id="check" name="firstname" placeholder="First Name" class="input-field" value="<?php echo $landowner_id; ?>" required>
</div>
<!-- Other inputs -->
<div class="form-wrapper">
<input type="text" id="check" name="sex" placeholder="Sex" class="input-field" value="<?php echo $sex; ?>" required>
<br>
<button class="btn" type="submit" name="update">Update</button>
</div>
</form>
Other important things to consider:
Never EVER send to the DB plain inputs coming from the outside without cleaning them! Otherwise, you will be open to SQL injection. Use prepare-statements to solve this issue.
Instead of mysqli_query I recommend you to use PDO. You can prepare statement super easy. Here you can see an example of usage: https://stackoverflow.com/a/60988740/3454593
In form, I want to insert the value of amount(text input) when value of rate(another text input) . The value which will be inserted in amount is the multiplication of rate and quantity. The value of quantity is taken from database. Here, the value of rate will be inserted by user.
After insertion of amount, the value can not be changed. How can i do this?
I have tried below code but result is showing zero every time:
View
<div class="form-group">
<label for="exampleInputPassword1">Rate</label>
<input type="text" class="form-control" name="rate" placeholder="Rate" required>
</div>
<div class="form-group">
<label>Quantity</label>
<input type="text" class="form-control" name="quantity" placeholder="quantity" value="<?php echo $object['sheet']; ?> " required readonly>
</div>
<div class="form-group">
<label for="exampleInputPassword2">Amount</label>
<?php
$sheet = $object['sheet'];
$rate = $this->input->post('rate');
$amount = $sheet*$rate;
echo $amount;
}
?>
<input type="text" class="form-control" name="amount" value="<?php echo $amount;?>" placeholder="Amount" required>
</div>
You can use jQuery to do that:
$(document).ready(function() {
$('input[name="rate"]').on('change',function() {
var amount = $(this).val()*$('input[name="quantity"]').val();
$('input[name="amount"]').val(amount);
})
});
Don't forget to include the jQuery api.
Also, don't forget to validate the amount after the form is submitted, as users can easily manipulate the value of the input.
Use Javascript for calculation.
I modified your code for your requirement. Your just need to set rate value dynamically from database. Here is your code :
<div class="form-group">
<label for="exampleInputPassword1">Rate</label>
<input type="text" class="form-control" name="rate" placeholder="Enter Rate" id="rate" required>
</div>
<div class="form-group">
<label>Quantity</label>
<input type="text" class="form-control" name="quantity" placeholder="quantity" value="2" id="qnty" required readonly>
</div>
<div class="form-group">
<label for="exampleInputPassword2">Amount</label>
<input type="text" class="form-control" name="amount" value="" id="amt" placeholder="Amount" required>
</div>
<script src="https://code.jquery.com/jquery-3.1.0.js" integrity="sha256-slogkvB1K3VOkzAI8QITxV3VzpOnkeNVsKvtkYLMjfk=" crossorigin="anonymous"></script>
<script>
$('#rate').keyup(function(){
var rate = parseInt($('#rate').val());
var qnty = parseInt($('#qnty').val());
var amt = parseInt(rate*qnty);
if(isNaN(amt)){
$('#amt').val('Enter valid rate');
} else {
$('#amt').val(amt);
}
});
</script>
I wasn't sure how to phrase the title, but here's what I'm trying to do.
I have a form to login to webmail, I don't have access to the webmail - it just posts the form input to the website and the webmail server takes it from there.
Everyone logging in to this page will be using the same email extension (e.g. "#myemail.com"), so I want to save the hassle of typing that every time, instead they can just write "mike" and the form will add "#myemail.com" on it's own.
I could post this form to a middle ground php page that sticks "mike" + "#mymail.com" together and posts this info to the webmail?
Or is there a simpler way to do this without having to create another page?
<form name="loginForm" action="http://webmail.emailsrvr.com/login.php" method="POST" target="_blank">
<input type="hidden" name="js_autodetect_results" value="SMPREF_JS_OFF">
<input type="hidden" name="just_logged_in" value="1">
<input type="hidden" name="type" value="v3">
<input type="hidden" name="useSSL" id="useSSL" value="">
<input type="email" name="user_name" placeholder="Username" required autofocus>
<input type="password" name="password" placeholder="Password" required>
<label for="remember"><input type="checkbox" name="remember">Remember my info</label>
<button type="submit">Sign In</button>
</form>
I want to take the value entered here...
<input type="email" name="user_name" placeholder="Username" required autofocus>
...and add an extension like "#myemail.com" to it, then post it.
Any idea? Thanks in advance for your help.
I could do something like this?
PAGE 1 - Enter username and password...
<input type="text" name="send_email" placeholder="Username" required autofocus>
<input type="password" name="send_password" placeholder="Password" required>
<label for="remember"><input type="checkbox" name="remember">Remember my info</label>
<button type="submit">Sign In</button>
</form>
PAGE 2 - PHP takes username and adds "#myemail.com" and sends form...
<?php
$form_email = $form_password = "";
if (!empty($_POST['send_email']) && !empty($_POST['send_password'])) {
$form_email = $test($_POST['send_email']) . '#fountaincreations.ca';
$form_password = $test($_POST['send_password']);
echo '<form name="loginForm" action="http://webmail.emailsrvr.com/login.php" method="POST" target="_blank">';
echo '<input type="hidden" name="js_autodetect_results" value="SMPREF_JS_OFF">';
echo '<input type="hidden" name="just_logged_in" value="1">';
echo '<input type="hidden" name="type" value="v3">';
echo '<input type="hidden" name="useSSL" id="useSSL" value="">';
echo '<input type="hidden" name="user_name" value="' . $form_email . '">';
echo '<input type="hidden" name="form_password" value="' . $form_password . '">';
echo '</form>';
} else {
echo '<p style="text-align:center;padding:40px 20px;">Please go back and try again.</p>';
}
function test($data) {
$data = strtolower(data);
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
How do I tell PHP to automatically submit the form though?
Here's what I have if I were to use jQuery:
It doesn't currently work though.
HTML:
<div class="box top">
<form name="loginForm" action="http://webmail.emailsrvr.com/login.php" method="POST" target="_blank">
<input type="hidden" name="js_autodetect_results" value="SMPREF_JS_OFF">
<input type="hidden" name="just_logged_in" value="1">
<input type="hidden" name="type" value="v3">
<input type="hidden" name="useSSL" id="useSSL" value="">
<div class="inner">
<div class="inner-row"><input type="text" name="user_name" placeholder="First Name" required autofocus></div>
<div class="inner-row"><input type="password" name="password" placeholder="Password" required></div>
<div class="inner-row">
<div class="inner-col col-2-4"><label for="remember"><input type="checkbox" name="remember">Remember my info</label></div>
<div class="inner-col col-2-4"><button type="submit">Sign In</button></div>
</div>
</div>
</form>
</div>
<div class="box bottom">
<div class="inner">
<div class="inner-row"><p>Already signed in? <b>Go to your inbox.</b></p>
</div>
</div>
JS:
<script type="text/javascript">
$(document).ready(function(){
$("button[type='submit']").on('click', function(e){
e.preventDefault();
var userEmail = $.trim($("input[name='user_name']").val());
$("input[name='user_name']").val(userEmail+"#fountaincreations.ca");
$("form[name='loginForm']").submit();
});
});
</script>
I think if you want to attach username + "#mymail.com" to useremail field, here is my suggestion:
1# create input user_email (just hide this field)
<input type="hidden" name="user_email" id="user_email" placeholder="User Email">
2# add js below
$('#user_name').on('input', function() {
username = this.value+'#myemail.com';
$('#user_email').val(username);
});
here example
I think this will go like this, hope this will help you. What i am doing in this code is, first I stop the form from being submitted through e.preventDefault(); and then i am taking the value of the required input and assigning it back value by attaching "#mymail.com".
$(document).ready(function(){
$("button[type='submit']").on('click', function(e){
e.preventDefault();
var userEmail = $.trim($("input[type='email']").val());
$("input[type='email']").val(userEmail+"#mymail.com");
$("form[name='loginForm']").submit();
});
});
I am trying to use Angular.
I am trying to Post Form of Angular, which have been done successfully, it is posting in JSON, But Problem is it only Post the input fields which have values, if i have NOT filled a textbox then it will NOT post that textbox value and fieldname, so how to know in controller which input fields have been posted.
Also how to send it to the model??
Here what i have done so far.
View.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
<link href="<?php echo base_url(); ?>/styles/formcss.css" rel="stylesheet" type="text/css"/>
<script src="<?php echo base_url(); ?>/scripts/angular.min.js"></script>
</head>
<body ng-app>
<div ng-controller="controller">
<form>
<label for="name">UserID:</label> <input type="text" name="UserID" ng-model="user.UserID" value=""><br>
<label for="UserName">Name:</label> <input type="text" name="UserName" ng-model="user.UserName" value=""><br>
<label for="rollno">In Game Name:</label> <input type="text" name="GameName" ng-model="user.InGameName" value="" ><br>
<label for="father">CNIC Number:</label> <input type="number" name="Cnic" ng-model="user.Cnic" value="" ><br>
<label for="age">Age:</label> <input name="Age" ng-model="user.Age" type="number" value="" ><br>
<label for="email1">Email:</label> <input name="Email" ng-model="user.Email" type="email" value="" ><br>
<label for="email2">Res enter Email:</label> <input id="email2" type="email" name="email2" value="" ><br>
<label for="pass1">Password:</label> <input id="pass1" type="password" name="Pass" ng-model="user.Password" value=""><br>
<label for="pass2">Re enter Password:</label> <input id="pass2" type="password" name="pass2" value="" ><br>
<label style="margin-bottom:-10px; " for="male">Male</label><input class="gen" ng-model="user.Gender" id="male" type="radio" name="g" value="Male"><br>
<label style="margin-bottom:15px;" for="female">Female</label><input class="gen" ng-model="user.Gender" id="female" type="radio" name="g" value="Female"><br>
<label class="dis" for="about" >About:</label> <textarea rows="5" cols="40" id="about" type="text" value=""></textarea><br>
<button style="margin-left: 225px;" ng-click="save()" >Save</button>
</form>
</div>
<script>
function controller ($scope,$http)
{
var angularform="<?php echo base_url(); ?>index.php/datacon/angform"
$scope.save=function()
{
$http.post(angularform, $scope.user);
}
}
</script>
</body>
</html>
Controller:
public function angform()
{
$get=file_get_contents('php://input');
$json_get=json_decode($get);
foreach($json_get as $key=>$value){
// i think something it has to do here.
}
$this->load->model('datamodel');
$this->datamodel->insert($data);
}
here is the screenshot, i have filled three fields so it posted the values of three fields only.
public function angform()
{
$get=file_get_contents('php://input');
$json_get=json_decode($get);
foreach($json_get as $key=>$value){
$data[$key]=$value; //Worked For Me.
}
$this->load->model('datamodel');
$this->datamodel->insert($data);
}
i check like this :-
if($this->input->get_post('male'))
{
// rest code goes here
}
Change your input name to match exactly like the database attribute(column) name. In that way you will not have to check anything:
$data = $this->input->post(null); #get the post array
$this->db->insert('table', $ata);
hello guys? can you help me with this? i want to get the id of the first input and the text value of the second input in a specific p tag
<p class="receiveitem">
<label for="mat_id">Material</label>
<input type="text" id="4"value="GI Coulping" disabled/>
<label for="rec_qty">Quantity</label>
<input type="text" class="rec_qty" />
<input type="button" class="receive" value=Receive />
</p>
<p class="receiveitem">
<label for="mat_id">Material</label>
<input type="text" id="5"value="Vulca Seal" disabled/>
<label for="rec_qty">Quantity</label>
<input type="text" class="rec_qty" />
<input type="button" class="receive" value=Receive />
</p>
<p class="receiveitem">
<label for="mat_id">Material</label>
<input type="text" id="6"value="teflon tape" disabled/>
<label for="rec_qty">Quantity</label>
<input type="text" class="rec_qty" />
<input type="button" class="receive" value=Receive />
</p>
so when i click the receive button that's in the p tag.
it will output someting like
ID: 4 and Value: 10
already have a js.but i can't get it done.
$(document).ready(function(){
$('input#receive').click(function(){
var mat = $('input[type=text]:first').attr('id');
var qty = $('input[type=text]:last').val;
alert(mat + qty);
});
});
and i dont know where to put the this in my variables mat and qty.please help?
Here is a modified approach using the more semantically correct data attributes (which are broadly supported) (building on #Chase's answer) (and a demo)
<p class="receiveitem">
<label for="mat_id">Material</label>
<input name="mat_id" type="text" data-id="4" value="GI Coulping" disabled="disabled"/>
<label for="rec_qty">Quantity</label>
<input type="text" name="rec_qty" />
<input name="rec_qty" type="button" class="receive" value="Receive" />
</p>
<p class="receiveitem">
<label for="mat_id">Material</label>
<input name="mat_id" type="text" data-id="5" value="Vulca Seal" disabled="disabled"/>
<label for="rec_qty">Quantity</label>
<input type="text" name="rec_qty" />
<input type="button" class="receive" value="Receive" />
</p>
<p class="receiveitem">
<label for="mat_id">Material</label>
<input name="mat_id" type="text" data-id="6" value="teflon tape" disabled="disabled"/>
<label for="rec_qty">Quantity</label>
<input type="text" name="rec_qty" />
<input type="button" class="receive" value="Receive" />
</p>
With this JavaScript
$(document).on("click", "input.receive", function () {
var mat = $(this).siblings("[name='mat_id']").data("id");
var qty = $(this).siblings("[name='rec_qty']").val();
alert("mat id: " + mat + " qty val: " + qty);
});
This approach won't abuse the id attribute which is designed for node identification and not data storage.
$(document).on('click', 'input#receive', function(e){
e.preventDefault();
var qty = $(this).prev().prev('input');
alert(qty);
});
You really need to change your markup to use data or unique IDs though.