Get Id From AJAX Response And Use The Id For Select2 - php

I write HTML code in controller
public function edit($id)
{
$user = User::find($id);
$rolesForEdit = Role::pluck('name', 'name')->all();
$userRole = $user->roles->pluck('name', 'name')->all();
$html = '<div class="row">
<div class="col-md-6">
<label for="name">Name</label>
<input value="' . $user->name . '" class="form-control"
placeholder="Full Name" type="text" name="name" id="name" />
<br>
<label for="phone">Phone Number</label>
<input value="' . $user->phone . '" class="form-control"
placeholder="Phone Number" type="text" name="phone" id="phone" />
<br>
</div>
<div class="col-md-6">
<label for="roles">Role</label><br>
<select style="width:220px;" name="rolesForEdit[]" multiple id="rolesForEdit"
class="rolesForEdit form-control"></select>
<br>
</div> <!-- kanan -->
</div> <!-- row-->';
return response()->json(['html' => $html]);
}
And then in view, I am trying to get rolesForEdit id and use it for select2. It doesn't work with this way. Any solution?
$.ajax({
url: "user/" + id + "/edit",
method: 'GET',
success: function(data) {
//var roles = $($.parseHTML(data)).find("#rolesForEdit").html();
//var roles = $(data).find('#rolesForEdit').text();
//var roles = $(this).attr('rolesForEdit');
//var roles = $($.parseHTML(data)).filter("#rolesForEdit");
alert(roles);
$(roles).select2({
ajax: {
url: '{{ url('searchrole') }}',
processResults: function(data) {
return {
results: data.map(function(item) {
return {
id: item.id,
text: item.name
}
})
}
}
}
});
$('#dataUserElement').html(data.html);
$('#saveBtn').val("create-product");
$('#user_id').val('');
$('#productForm').trigger("reset");
$('#modelHeading').html("Update User");
$('#ajaxModel').modal('show');
}
});
});

Your server return json as response so add dataType: 'json' to your ajax call. Then , append data return to your dataUserElement i.e : data.html and finally intialize your select2 .
Demo Code :
//suppose data is this :)
var data = {
'html': '<div class="row"><div class="col-md-6"> <label for="name">Name</label><input value="abc" class="form-control" placeholder="Full Name" type="text" name="name" id="name" /><br><label for="phone">Phone Number</label><input value="12346" class="form-control" placeholder="Phone Number" type="text" name="phone" id="phone" /><br></div><div class="col-md-6"><label for="roles">Role</label><br><select style="width:220px;" name="rolesForEdit[]" multiple id="rolesForEdit" class="rolesForEdit form-control"></select><br></div></div>'
}
/*$.ajax({
url: "user/" + id + "/edit",
method: 'GET',
dataType:'json',//add this
success: function(data) {*/
$('#dataUserElement').html(data.html); //then append this
var roles = $('#dataUserElement').find(".rolesForEdit") //get select refernce
$(roles).select2({
ajax: {
url: "https://api.github.com/orgs/select2/repos", //this is for demo change it to your real url
processResults: function(data) {
return {
results: data.map(function(item) {
return {
id: item.id,
text: item.name
}
})
}
}
}
});
//all other codes modal ..etc etc
/*}
});*/
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" />
<script src="https://code.jquery.com/jquery-3.2.1.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.full.min.js"></script>
<div id="dataUserElement">
</div>

Related

Record not insert into the database using laravel 8 ajax

i am a begineer of laravel and ajax i can do the system well in core php. i just converted to laravel.
i creating simple crud using laravel with ajax but i don't know how call the path through ajax request. what i tried so fat i attached below.pls give me the solution for it.
Screen shot of folder structure
this is view part. i name it
list.blade.php
div class="row">
<div class="col-sm-4">
<form class="card" id="frmProject">
<div class="form-group" align="left">
<label class="form-label">First name</label>
<input type="text" class="form-control" placeholder="first_name" id="first_name" name="first_name" size="30px" required>
</div>
<div class="form-group" align="left">
<label class="form-label">Last name</label>
<input type="text" class="form-control" placeholder="last_name" id="last_name" name="last_name" size="30px" required>
</div>
<div class="form-group" align="left">
<label class="form-label">Address</label>
<input type="text" class="form-control" placeholder="Address" id="address" name="address" size="30px" required>
</div>
<div class="card" align="right">
<button type="button" id="save" class="btn btn-info" onclick="addProject()">Add</button>
</div>
</form>
</div>
Ajax Call
function addProject() {
if ($("#frmProject").valid())
{
var _url = '';
var _data = '';
var _method;
if (isNew == true) {
_url = '/student';
_data = $('#frmProject').serialize();
_method = 'POST';
}
else {
_url = '/student',
_data = $('#frmProject').serialize() + "&project_id=" + project_id;
_method = 'POST';
alert(project_id);
}
$.ajax({
type: _method,
url: _url,
dataType: 'JSON',
data: _data,
beforeSend: function () {
$('#save').prop('disabled', true);
$('#save').html('');
$('#save').append('<i class="fa fa-spinner fa-spin fa-1x fa-fw"></i>Saving</i>');
},
success: function (data) {
$('#frmProject')[0].reset();
$('#save').prop('disabled', false);
$('#save').html('');
$('#save').append('Add');
get_all();
var msg;
console.log(data);
if (isNew)
{
msg="Brand Created";
}
else{
msg="Brand Updated";
}
$.alert({
title: 'Success!',
content: msg,
type: 'green',
boxWidth: '400px',
theme: 'light',
useBootstrap: false,
autoClose: 'ok|2000'
});
isNew = true;
},
error: function (xhr, status, error) {
alert(xhr);
console.log(xhr.responseText);
$.alert({
title: 'Fail!',
content: xhr.responseJSON.errors.product_code + '<br>' + xhr.responseJSON.msg,
type: 'red',
autoClose: 'ok|2000'
});
$('#save').prop('disabled', false);
$('#save').html('');
$('#save').append('Save');
}
});
}
}
Student Controller
class StudentController extends Controller
{
public function index()
{
$data['students'] = Student::orderBy('id','desc')->paginate(5);
return view('student.list',$data);
}
public function create()
{
}
public function store(Request $request)
{
$student = new Student([
'first_name' => $request->post('first_name'),
'last_name'=> $request->post('lastname'),
'address'=> $request->post('address')
]);
]);
$student->save();
return Response::json($student);
}
routes
Route::get('/', [App\Http\Controllers\StudentController::class, 'index']);
Route::get('student', [App\Http\Controllers\StudentController::class, 'index']);
Route::post('student', [App\Http\Controllers\StudentController::class, 'store'])->name('student.store');
$(document).ready(function() {
$(".btn-submit").click(function(e){
e.preventDefault();
var _token = $("input[name='_token']").val();
var email = $("#email").val();
var pswd = $("#pwd").val();
var address = $("#address").val();
$.ajax({
url: "url",
type:'POST',
data: {_token:_token, email:email, pswd:pswd,address:address},
success: function(data) {
printMsg(data);
}
});
});
function printMsg (msg) {
if($.isEmptyObject(msg.error)){
console.log(msg.success);
$('.alert-block').css('display','block').append('<strong>'+msg.success+'</strong>');
}else{
$.each( msg.error, function( key, value ) {
$('.'+key+'_err').text(value);
});
}
}
});
Please use csrf token

Auto Search using Php ajax

while i am making the point of sale system i ran in to problem with the search.
when i enter the product code on the product code textbox it automatically Search and display product name and price in to the relevant textboxes using ajax and jquery and php. what i tried code i attached below. i didn't get any answer while i ran the code.please read the below code and get good solution for me as soon as possible.
Form Design
<div class="form-group">
<label for="" class="col-sm-2 control-label">Product Code</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="product_code" name="product_code" placeholder="Product Code" required>
</div>
</div>
<div class="form-group">
<label for="" class="col-sm-2 control-label">Product Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="product_name" name="product_name" placeholder="product_name " required>
</div>
</div>
<div class="form-group">
<label for="" class="col-sm-2 control-label">Price</label>
<div class="col-sm-10">
<input type="text" class="form-control price" id="price" name="price" placeholder="price" required>
</div>
</div>
AJAX
function getProductcode() {
$('#product_code').empty();
$("#product_code").keyup(function(e) {
var q = $("#product_code").val();
$.ajax({
type: 'POST',
url: '../php/project_module/get_purchase.php',
dataType: 'JSON',
async: false,
success: function(data) {
for (var i = 0; i < data.length; i++) {
$('#product_code').append($("<option/>", {
value: data[i].product_id,
text: data[i].product_name,
}));
}
data: {
product_code: $('#product_code').val()
},
}
},
error: function(xhr, status, error) {
alert(xhr.responseText);
//
}
});
}
**get_purchase.php**
$product_code = $_POST["product_code"];
$stmt = $conn->prepare("select product_id,product_name,barcode,category,description,warrenty,product_condition,price_retail,
price_cost,discount,reorderlevel,brand
from product where barcode = ?");
$stmt->bind_param("s", $product_code);
$stmt->bind_result($product_id,$product_name,$price);
if ($stmt->execute()) {
while ( $stmt->fetch() ) {
$output[] = array ("product_id"=>$product_id,"product_name"=>$product_name,"price_retail"=>$price);
}
echo json_encode( $output );
}
$stmt->close();
The data attribute is in the wrong place of the ajax configuration.
Here is a revised version
Add this to your HTML
<p id="output"></p>
And this as your getProductCode() definition
function getProductcode() {
$("#product_code").empty();
$("#product_code").keyup(function(e) {
var q = $("#product_code").val();
$.ajax({
type: "POST",
url: "../php/project_module/get_purchase.php",
dataType: "JSON",
data: { product_code: $("#product_code").val() },
success: function(data) {
if(typeof data === 'undefined'){
return
}
$("#output").val(data[0].product_id + " : " +data[0].product_name)
},
error: function(xhr, status, error) {
alert(xhr.responseText);
}
});
});
}
I pasted your code in my editor (VS Code) and it gave helpful syntax errors. Maybe it would be a good idea to look into editors with syntax highlighting and checking capabilities?

upload image with laravel using ajax

I have table user:
id (int)
firstname (string)
lastName (string)
email (string)
login (string)
password (string)
image (text)
I would like to insert image in my database using ajax jquery.
But at the given database level it does not insert the data with the image.
I try with this code but doesn't work.
Controller:
public function addUser(Request $request){
$user = new User();
$user->lastName = $request->lastName;
$user->firstName = $request->firstName;
$user->email = $request->email;
$user->login = $request->login;
$user->password = bcrypt($request->password);
if($request->has('image') ) {
$file_local = $request->file('image');
$extension = $request->file('image')->getClientOriginalExtension();
if($extension == 'jpg' || $extension == 'png' || $extension == 'jpeg'){
$name=$request->file('image')->getClientOriginalName();
$path = $file_local->storeAS('public/',$name);
$user->image = $name;
}
}
$user->save();
return response()->json($user);
}
View:
<form enctype="multipart/form-data">
<div class="form-group">
<input type="text" id="lastName" class="form-control" placeholder="last Name" required />
</div>
<div class="form-group">
<input type="text" id="firstName" class="form-control" placeholder="name" required />
</div>
<div class="form-group">
<input type="email" id="email" class="form-control" placeholder="Email" required/>
</div>
<div class="form-group">
<input type="text" id="login" class="form-control" placeholder="Login" required/>
</div>
<div class="form-group">
<input type="password" id="password" class="form-control" placeholder="password" required/>
</div>
<div class="form-group">
<input type="file" id="image" class="form-control" required />
</div>
</form>
ajax:
$(document).on('click', "#creer_utilisateur", function() {
var lastName= $('#lastName').val();
var firstName = $('#firstName').val();
var email = $('#email').val();
var login = $('#login').val();
var password = $('#password').val();
var image = $('#image').val();
success: function(data) {
$.ajax({
url: "{{action('UserController#addUser')}}",
method: 'POST',
data: {
lastName: lastName,
firstName: firstName,
email: email,
login: login,
password: password,
image: image
},
success: function(data) {
alert('success');
},
error: function(){
alert('failed');
}
});
}
});
});
You are actually saving the name of the image:
$name=$request->file('image')->getClientOriginalName();
...
$user->image = $name;
You said:
"But at the given database level it does not insert the data with the image."
And the type of the column is:
image (text)
So, I guess you don't want to store the name, right?
when you are using ajax to upload file you need to create form with File attribute. and Then append other values with that.
Something like this:
var formData = new FormData();
if ($('#images')[0].files.length > 0) {
for (var i = 0; i < $('#images')[0].files.length; i++)
formData.append('file[]', $('#images')[0].files[i]);
}
formData.append('lastName', $('#lastName').val());
second when you pass files with ajax make sure cache is false.
$.ajax({
type: 'POST',
dataType: "JSON",
url: jQuery('form').attr('action'),
xhr: function() {
myXhr = $.ajaxSettings.xhr();
return myXhr;
},
cache: false,
contentType: false,
processData: false
data: formData,
success: function(data) {
// Success
},
error: function(error) {
// error
},
});
Good luck
you can change an image text area like you can select an image: file then you can insert a file

Laravel 5.2 - ajax check if value exists in database

I am creating an employee hierarchy and while setting up the superior for new employee I would like to check if the employee already exists in database ... but :) I would like to do it with AJAX to know it realtime without sending the form ..
I have absolutely no idea how to do it, since I am a newbie to Laravel ..
***UPDATED BASED ON ADVICES:***
I have a form in add_emp.blade.php:
<form action="../create_employee" method="POST">
<button class="button" type="submit" style="float:right"><span>Save</span></button>
<div style="clear:both"></div>
<fieldset>
<legend>Personal data</legend>
<label for="first_name">First name:</label><input type="text" class="add_emp required" name="first_name" value="" /><br />
<label for="last_name">Last name:</label><input type="text" class="add_emp required" name="last_name" value="" /><br />
<label for="superior">Superior:</label><input type="text" class="add_emp" name="superior" value="" id="superior_list" /><br />
</fieldset>
</form>
Here is a script in add_employee.blade.php
<script type="text/javascript">
$('#superior_list').blur(function(){
var first_name = $('#superior_list');
$.ajax({
method: "POST",
url: '/check_superior',
data: { superior: superior }
})
.done(function( msg ) {
if(msg == 'exist') {
//employee exists, do something...
alert( "good." );
} else {
//employee does not exist, do something...
alert( "bad." );
}
});
})
</script>
route for handling the superior:
Route::post('check_superior', 'EmployeeController#check_superior');
This is the Controller function check_superior:
public function check_superior(Request\AjaxUserExistsRequest $request){
if(Employee::where('superior','=',$request->input('superior'))->exists()){
return "exist";
}else{
return "not exist";
}
}
But still not working ... can you advice where could be the issue?
*** FINAL SOLUTION ***
Form:
<form action="../create_employee" method="POST">
<button class="button" type="submit" style="float:right"><span>Save</span></button>
<div style="clear:both"></div>
<fieldset>
<legend>Personal data</legend>
<label for="first_name">First name:</label><input type="text" class="add_emp required" name="first_name" value="" /><br />
<label for="last_name">Last name:</label><input type="text" class="add_emp required" name="last_name" value="" /><br />
<label for="superior">Superior:</label><input type="text" class="add_emp" name="superior" value="" id="superior_list" /><span id="check-superior-status"></span><br />
</fieldset>
</form>
Add to app.blade.php
meta name="csrf-token" content="{{ csrf_token() }}"
Controller
public function check_superior(Request $request){
if(Employee::where('first_name','=',$request->input('superior_fname'))
->where('last_name','=',$request->input('superior_lname'))
->exists()){
return "exist";
}else{
return "not exist";
}
}
final emp.blade.php AJAX script
// place data after SEPERIOR selection
$( "#superior_list" ).blur(function() {
var sup_list = $(this).val();
var sup_arr = sup_list.split(' ');
var superior_fname = sup_arr[0];
var superior_lname = sup_arr[1];
var superior = superior_fname+" "+superior_lname;
// control print out
//$('#check-superior-status').text(superior);
// get real data
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
method: "POST",
url: '/check_superior',
data: { superior_fname: superior_fname, superior_lname: superior_lname },
/* // debug only
error: function(xhr, status, error){
$('#check-superior-status').text(xhr.responseText);
},
*/
success: function(data){
$('#check-superior-status').text(data);
}
})
});
This works like a charm :) thank you guys .. hope this will help someone ..
First make the request.
php artisan make:request AjaxUserExistsRequest
Then open the request file (App\Http\Requests) and find the following:
public function validate(){
return [
//rules
];
}
This is where you would stick your validation rules so you can check against the form elements being submit.
Then you should use dependency injection to force your request into the first argument of the user_exists() function:
public function user_exists(Requests\AjaxUserExistsRequest $request){
return User::where('first_name', $request->first_name)->first();
}
This will return nullif no user exists, otherwise we don't care about the response.
Finally, of course we need our route.
Route::post('employee_exists', 'EmployeeController#user_exists');
Lastly, we'll go ahead and capture the form submit and check if the user exists with our jQuery.
$('#employee_form').submit(function(e){
e.preventDefault();
var first_name = $('#first_name').val(),
$this = this; //aliased so we can use in ajax success function
$.ajax({
type: 'POST',
url: '/employee_exists',
data: {first_name: first_name},
success: function(data){
if(data == null){
//then submit the form for real
$this.submit; //doesn't fire our jQuery's submit() function
} else {
//show some type of message to the user
alert('That user already exists!');
}
}
});
});
The below will give alert message the user already exists! if the first_name exists in your db or it will give alret nothing.(if you want to check with superior change the code vice versa)
first make sure you have jquery.min.js in your public folder.
Now in blade.php add id for first_name, last_name, and superior as below:
<form action="../create_employee" method="POST">
<button class="button" type="submit" style="float:right"><span>Save</span></button>
<div style="clear:both"></div>
<fieldset>
<legend>Personal data</legend>
<label for="first_name">First name:</label><input type="text" id="first_name" class="add_emp required" name="first_name" value="" /><br />
<label for="last_name">Last name:</label><input type="text" id="last_name" class="add_emp required" name="last_name" value="" /><br />
<label for="superior">Superior:</label><input type="text" class="add_emp" name="superior" value="" id="superior_list" /><br />
</fieldset>
</form>
<script>
$(document).ready(function(){
$("#superior_list").blur(function(){
var first_name = $('#first_name').val();
var last_name = $('#last_name').val();
var superior = $('#superior_list').val();
$.ajax({
type: 'POST',
url: '/check_superior',
data: {first_name: first_name, last_name: last_name, superior: superior},
success: function(data){
if(data == 0){
alert('nothing');
} else {
alert('the user already exists!');
}
}
});
});
});
</script>
and in your route.php
Route::post('/check_superior', array('as' => '', 'uses' => 'EmployeeController#check_superior'));
in EmployeeController.php
public function check_superior(){
// can get last_name, superior like first_name below
$first_name = Input::get('first_name');
$data = YourModel::where('first_name',$first_name)->get();
return count($data);
}
It should work. if it doesn't please show us your error
Give your form an id:
<form action="../create_employee" method="POST" id="employee_form">
<button class="button" type="submit" style="float:right"><span>Save</span></button>
<div style="clear:both"></div>
<fieldset>
<legend>Personal data</legend>
<label for="first_name">First name:</label><input type="text" class="add_emp required" name="first_name" id="first_name" value="" /><br />
<label for="last_name">Last name:</label><input type="text" class="add_emp required" name="last_name" value="" /><br />
<label for="superior">Superior:</label><input type="text" class="add_emp" name="superior" value="" id="superior_list" /><br />
</fieldset>
</form>
your js will look like this
$('#employee_form').submit(function(e){
e.preventDefault();
var first_name = $('#first_name');
$.ajax({
method: "POST",
url: "checkUserExistence.php",
data: { first_name: first_name }
})
.done(function( msg ) {
if(msg == 'exist') {
//employee exists, do something...
} else {
//employee does not exist, do something...
}
});
})
also add csrf_field in your form to generate token, and use this token while sending request.
in your form:
{{ csrf_field() }}
in your ajax request:
$.ajax({
headers: {'X-CSRF-Token': $('input[name="_token"]').val()},
//other data....
})
you can also do it with meta teg. in your head teg
<meta name="csrf-token" content="{{ csrf_token() }}">
in your request
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content');
//other data...
}
});

hide div after inserting data in database

Hi would you like to help me. im a php newbie. I want to insert employment information in my database and hide da div where the form placed.
HTML:
<div class="toggler">
<div id="effect" class="ui-widget-content ui-corner-all">
<form name="empform" method="post" action="profile.php" autofocus>
<input name="employ" type="text" id="employ" pattern="[A-Za-z ]{3,20}"
placeholder="Who is your employer?">
<input name="position" type="text" id="position" pattern="[A-Za-z ]{3,20}"
placeholder="What is your job description?">
<input name="empadd" type="text" id="empadd" pattern="[A-Za-z0-9##$% ]{5,30}"
placeholder="Where is your work address?">
<input name="empcont" type="text" id="empcont" pattern="[0-9]{11}" title="11-digit number"
placeholder="Contact number">
<input name="btncancel" type="button" class="btncancel" value="Cancel"
style="width:60px; border-radius:3px; float:right">
<input name="btndone" type="submit" class="btndone" value="Done" style="width:60px; border-radius:3px; float:right">
</form>
</div>
</div>
PHP:
if (isset($_POST['btndone'])) {
$employ = $_POST['employ'];
$position = $_POST['position'];
$empadd = $_POST['empadd'];
$empcont = $_POST['empcont'];
$empdate = $_POST['empdate'];
$empID = $alumniID;
$obj - > addEmployment($employ, $position, $empadd, $empcont, $empdate, $empID);
}
JS:
<script>
$(function () {
function runEffect() {
var selectedEffect = "highlight";
$(".toggler").show(selectedEffect);
};
function runDisplay() {
var selectedDisplay = "highlight";
$("#empdisplay").show(selectedDisplay);
};
$(".btncancel").click(function () {
$(".toggler").hide();
return false;
});
$(".btndone").click(function () {
runDisplay();
$(".toggler").hide();
return false;
});
}
</script>
Hi this is what I'll do
var request = $.ajax({
url: "profile.php",
type: "POST",
data: $('#form').serialize()
});
request.done(function(msg) {
$('#form').hide();
});
request.fail(function(jqXHR, textStatus) {
alert( "Form failed" );
});
If you have some doubts with Jquery's Ajax visit this link
If you don't understand what jqXHR is, I suggest you visit this link http://www.jquery4u.com/javascript/jqxhr-object/
Execute on click
$('#form').submit(function(){
var request = $.ajax({
url: "profile.php",
type: "POST",
data: $('#form').serialize()
});
request.done(function(msg) {
$('#form').hide();
});
request.fail(function(jqXHR, textStatus) {
alert( "Form failed" );
});
});
Try This
HTML
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
</head>
<body>
<div class="toggler">
<div id="effect" class="ui-widget-content ui-corner-all">
<form id="empform" name="empform" method="post" action="profile.php" autofocus>
<input name="employ" type="text" id="employ" pattern="[A-Za-z ]{3,20}"
placeholder="Who is your employer?">
<input name="position" type="text" id="position" pattern="[A-Za-z ]{3,20}"
placeholder="What is your job description?">
<input name="empadd" type="text" id="empadd" pattern="[A-Za-z0-9##$% ]{5,30}"
placeholder="Where is your work address?">
<input name="empcont" type="text" id="empcont" pattern="[0-9]{11}" title="11-digit number"
placeholder="Contact number">
<input name="btncancel" type="button" class="btncancel" value="Cancel"
style="width:60px; border-radius:3px; float:right">
<input id="submit"name="btndone" type="submit" class="btndone" value="Done" style="width:60px; border-radius:3px; float:right">
</form>
</div>
</div>
<script>
$(document).ready(function() {
//$("#form").prev
$('#submit').click(function(event) {
//alert (dataString);return false;
event.preventDefault();
$.ajax({
type: "POST",
url: 'profile.php',
dataType:"html",
data: $("#empform").serialize(),
success: function(msg) {
alert("Form Submitted: " + msg);
//alert($('#form').serialize());
$('div.toggler').hide();
}
});
});
});
</script>
</html>
PHP
profile.php
<?php
if (isset($_POST)) {
$employ = $_POST['employ'];
$position = $_POST['position'];
$empadd = $_POST['empadd'];
$empcont = $_POST['empcont'];
$empdate = $_POST['empdate'];
$empID = $alumniID;
$obj - > addEmployment($employ, $position, $empadd, $empcont, $empdate, $empID);
}
?>
Iam not sure about your fields
echo $empdate = $_POST['empdate'];
$empID = $alumniID;
they are not in form but works!...
You should do an ajax call to save your data and then hide the div, someting like this :
$('form[name="empform"]').submit(function(e) {
e.preventDefault();
$.post($(this).attr('action'), $(this).serialize(), function(data) {
$('div.toggler').hide();
});
});

Categories