jquery dialog post values to php page - php

i am completely new to JQuery.
I would like to get a solution on how to pass values from a jquery dialog form to a php file for proccessing.
Please refer to this link as an example of the jquery dialog form
Please note: The example of the dialog form passes values to a table and displays. In my case I would like to pass them to another page(.php file).
Your assistance is much appreciated :)
Code:
-Script
if(bValid)
{
$.post("scripts/appointment.php",{ name: name.val(),
email: email.val(),
contact: contact.val(),
file: filenumber.val(),
reason: reason.val(),
app_date: appdate.val(),
time: apptime().val,
visit: getRadioValue()},
function(data){
$("#dialog-form").slideUp("normal", function() {
$("#dialog-form").before('<h1>Success</h1><p>Your Appointment was sent.</p>');
}); }
);
$( this ).dialog( "close" );
}
-form
<div id="dialog-form" title="Make an appointment">
<p class="validateTips">Please fill in the form to book an appointment.<br>If the
booking is not available we will notify you!</p>
<form>
<fieldset>
<label for="patient"><b>First Time Visit?</b></label>
<input type="radio" name="patient" id="patient_state" value="Yes">Yes<br>
<input type="radio" name="patient" id="patient_state" value="No">No<br><hr>
<label for="filenumber">File No.</label>
<input type="text" name="filenumber" id="filenumber" value="" class="text ui-widget-content ui-corner-all" />
<label for="reason">What's your reason for visit?</label>
<input type="text" name="reason" id="reason" value="type reason here..." class="text ui-widget-content ui-corner-all" />
<label for="name">Name</label>
<input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" />
<label for="email">Email</label>
<input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" />
<label for="contact">Contact No.</label>
<input type="text" name="contact" id="contact" value="" class="text ui-widget-content ui-corner-all" />
<label for="appdate">Date</label>
<input type="text" name="appdate" id="datepicker" value="" class="text ui-widget-content ui-corner-all" />
<label for="apptime">Time</label>
<input type="text" name="apptime" id="apptime" value="HH:MM" class="text ui-widget-
content ui-corner-all" />
</fieldset>
</form>
</div>

this means you have to bind click event on your book button:
$('#bookButton').click(function() {
// perfom check
if (bValid) {
// other code
}
});

Related

html form-- need help having new input area populate if radio button is clicked

I am making a basic new customer database with mysql and php. I would like when people click on the radio button"different mailing address" for another couple of input fields to appear for the mailing address. Im not quite sure how to handle this with inputs and not variables. Is there a way to do an if statement here is my html form code below
<form method="POST" action="insert.php">
<fieldset>
<legend>New Customer data</legend>
<label>Complete Below</label>
<div class="controls controls-row">
<input class="span4" name="firstname" type="text" placeholder="First name">
<input class="span3" name="lastname" type="text" placeholder="Last Name">
<input class="span3" name="phone" type="text" placeholder="Phone">
</div>
<div class="controls controls-row">
<input class="span4" name="address" type="text" placeholder="Address">
<input class="span2" name="city" type="text" placeholder="City">
<input class="span1" name="state" type="text" placeholder="State">
</div>
<div class="controls controls-row">
<input class="span4" name="zip" type="text" placeholder="Zip Code">
<input class="span2" name="email" type="text" placeholder="Email">
<input class="span2" name="ccemail" type="text" placeholder="cc email">
</div>
<span class="help-block">When is the customers due date monthly</span>
<label class="radio">
<input type="radio" name="duedate" id="optionsRadios1" value="1" checked>
1st of the month</label>
<label class="radio">
<input type="radio" name="duedate" id="optionsRadios2" value="15">
15th of the month
</label>
<span class="help-block">Mailing address</span>
<label class="radio">
<input type="radio" name="mailingaddress" id="optionsRadios3" value="1" checked>
Check if mailing address is the same as the service address
</label>
<label class="radio">
<input type="radio" name="mailingaddress" id="optionsRadios4" value="0">
Check if mailing address is different
</label>
<button type="submit" class="btn btn-primary">Submit</button>
</fieldset>
</form>
Using jQuery, have two inputs that are initially hidden. Once the user checks the box, '$.show()' on those two inputs. Id have a div containing two inputs, and just show or hide the div depending on whether the box is checked or not
you can try this.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" >
</script>
<script>
$(document).ready(function(){
$("#checkme").on('change',function(){
if($("#checkme").is(":checked")){
$("input#myemail").fadeIn();
}else{
$("input#myemail").fadeOut();
}
});
});
</script>
</head>
<body>
show: <input type="checkbox" id="checkme" /><br />
<input type="text" id="myemail" hidden />
</body>
</html>

AngularJS | How to Send the Data of Json to database in Codeigniter

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);

AngularJS, Databind Multiple Form Fields

Ok i have a Edit Form in AngularJS and i want show data in textboxes through angular databindings.
Here is the Form which i have done so far.
<!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>
Here is the Json Array I am Getting From the Controller
JSON:
{"datas":[{"UserID":"168","UserName":"fdaa","Cnic":"23424","Email":"pak#gmail.com","Password":"asdad","Age":"12","Gender":"Male","Picture":null,"InGameName":"fds","ContactID":null,"GroupID":null,"ClanID":null}]}
But How to show these values in TextBoxes through Angular Data bindings?
Or if i am Doing Something Wrong Please Redirect me to my mistakes so i could solve my mistakes.
I am not sure whether I am getting you right or not. But I think If you are using $scope and ng-model, they are doing their job perfectly. You are using absolutely correct.
With the $http.post() you can save the data. At the same time data will be present in the text boxes.
What exactly you want to do. Please explain a bit more so that folks can try to explain you more.

formname.submit not working on IE8

I am currently developing an app and i am getting difficulties on IE8.
I have the following code:
<form class="fillClaimForm" name="fillClaimForm" method="POST" enctype="multipart/form-data" action="<?php print BASE_URL; ?>?action=insertBlogger" >
<label for="fblogName">Blog's name: </label>
<input type="text" name="fblogName" id="fblogName" class="cfInput" placeholder ="Complex" required />
<label for="fblogUrl">URL: </label>
<input type="text" name="fblogUrl" id="fblogUrl" class="cfInput" placeholder ="www.complex.com" required />
<label>Blog's logo: </label>
<div class="upload-file-container"><span>UPLOAD</span>
<input type="file" name="fblogLogo" id="fblogLogo"/>
<p class="ErrLoad error" style="display:none;">Please load your logo</p>
</div>
<label for="fEmail">Email adresse: </label>
<input type="email" name="fEmail" id="fEmail" class="cfInput" required />
<label for="frNum">Phone number: </label>
<input type="tel" name="frNum" id="frNum" class="cfInput" required />
<input type="hidden" name="idVid" id ="idVid" value=""/>
<input type="hidden" name="idRubrique" id ="idRubrique" value=""/>
<button id="sendClaim" class="sendClaim">SEND</button>
Consequently, I am doing a form submission using jquery:
......submit(function(){
validate=false;
formInfo = validateForm(validate,$thisLi);
if(formInfo.validate){
**fillClaimForm.submit();**
}
return false;
});
It is working on all browsers except IE8
Can someone kindly help me.
Thanks
Close your form.
Also give the same name as the id for your form and use
$("#formId").submit();
Code
<form class="fillClaimForm" name="fillClaimForm" method="POST" enctype="multipart/form-data" action="<?php print BASE_URL; ?>?action=insertBlogger" >
<label for="fblogName">Blog's name: </label>
<input type="text" name="fblogName" id="fblogName" class="cfInput" placeholder ="Complex" required />
<label for="fblogUrl">URL: </label>
<input type="text" name="fblogUrl" id="fblogUrl" class="cfInput" placeholder ="www.complex.com" required />
<label>Blog's logo: </label>
<div class="upload-file-container"><span>UPLOAD</span>
<input type="file" name="fblogLogo" id="fblogLogo"/>
<p class="ErrLoad error" style="display:none;">Please load your logo</p>
</div>
<label for="fEmail">Email adresse: </label>
<input type="email" name="fEmail" id="fEmail" class="cfInput" required />
<label for="frNum">Phone number: </label>
<input type="tel" name="frNum" id="frNum" class="cfInput" required />
<input type="hidden" name="idVid" id ="idVid" value=""/>
<input type="hidden" name="idRubrique" id ="idRubrique" value=""/>
<button id="sendClaim" class="sendClaim">SEND</button>
</form>
$("#sendClaim").click(function(){
validate=false;
formInfo = validateForm(validate,$thisLi);
if(formInfo.validate){
$("#fillClaimForm").submit();
}
return false;
});
Try this:
document.forms.fillClaimForm.submit();
Or if the ...... in your code represents creating of a submit handler on that same form you can probably just say this.submit().

Passing form data from one web page to another with PHP

i found few similar questions here but from answers i didn't get the whole picture of how should work.
I have a subscription form in a page:
<form method="post" action="index.php/register">
<fieldset>
<input type="text" id="first_name" name="first_name" />
<input type="text" id="last_name" name="last_name" />
<input type="text" id="email" name="email" />
<input type="text" id="address" name="address" />
<input id="submit" type="submit" value=">>" />
</fieldset>
</form>
when a user a user click the submit button is lead to a page with the full registering form, where i need to have few fields populated with the data sent from previous page form. this is a preview of few fields from the form of the second page:
<form id="register" name="form1" method="post" action="send_contact.php">
<fieldset>
<li><label>*First Name</label>
<input type="text" id="first_name" name="first_name" />
</li>
<li>
<label>*Last Name</label>
<input type="text" id="last_name" name="last_name" />
</li>
<li>
<label>*Email</label>
<input type="text" id="email" name="email" />
</li>
<li>
<label>*Confirm Email</label>
<input type="text" id="confirm-email" name="confirm_email" />
</li>
<li>
<label>Street Address</label>
<input type="text" id="address" name="address" />
<li class="full-width">
<input id="submit" type="submit" value="Register" />
</li>
</fieldset>
</form>
the php is not my strong point, so if you can be more detailed in answer is great for me.
thanks!
I would say for security reasons, do not use Get method "$_GET[]" as people described, keep POST as you have it.
All you need to do on register/ page is get all the values passed on using the POST method and populate them into your HTML. So the second form should look like:
<form id="register" name="form1" method="post" action="send_contact.php">
<fieldset>
<li><label>First Name</label>
<input type="text" id="first_name" name="first_name" value="<?=$_POST[first_name]?>" />
</li>
<li>
<label>*Last Name</label>
<input type="text" id="last_name" name="last_name" value="<?=$_POST[last_name]?>" />
</li>
<li>
<label>*Email</label>
<input type="text" id="email" name="email" value="<?=$_POST[email]?>" />
</li>
<li>
<label>*Confirm Email</label>
<input type="text" id="confirm-email" name="confirm_email" />
</li>
<li>
<label>Street Address</label>
<input type="text" id="address" name="address" value="<?=$_POST[address]?>" />
<li class="full-width">
<input id="submit" type="submit" value="Register" />
</li>
</fieldset>
</form>
Above, I am using shorthand version of "echo" and php tags, if you do not have that enabled under php.ini, please change "" to "; ?>. Also, script will not populate "confirm" email as I assume you would like the user to retype that.
That should do it.
There are basically two methods
Store the values of the first form in a cookie, and the process code can retrieve the values from the cookie
make the form action 'Get' so that the data is passed on to the next page.
You can use the $_POST values from the first form in the page handling the submit of the first form and print them in the new form as:
<?php
echo '<input type="text" id="email" name="email" value="' . htmlentities($_POST['email']) . '"/>
?>
<form method="post" action="register.php">
<fieldset>
<input type="text" id="first_name" name="first_name" />
<input type="text" id="last_name" name="last_name" />
<input type="text" id="email" name="email" />
<input type="text" id="address" name="address" />
<input id="submit" type="submit" value=">>" />
</fieldset>
</form>
register.php
<form id="register" name="form1" method="post" action="send_contact.php">
<fieldset>
<li><label>*First Name</label>
<input type="text" value="<?php echo $_POST['first_name'];?>" id="first_name" name="first_name" />
</li>
<li>
<label>*Last Name</label>
<input type="text" value="<?php echo $_POST['last_name'];?>" id="last_name" name="last_name" />
</li>
<li>
<label>*Email</label>
<input type="text" value="<?php echo $_POST['email'];?>" id="email" name="email" />
</li>
<li>
<label>*Confirm Email</label>
<input type="text" id="confirm-email" name="confirm_email" />
</li>
<li>
<label>Street Address</label>
<input type="text" value="<?php echo $_POST['address'];?>" id="address" name="address" />
<li class="full-width">
<input id="submit" type="submit" value="Register" />
</li>
</fieldset>
</form>
Finally service the post in send_contact.php as you wish

Categories