am trying to show google map in one section of my form, which i want to load locations based on IP Address, but when i tried locations are not loading based on ip address.What is the issue
#extends('user.layout.app')
#section('content')
<script src="{{ url('js/user/location.js') }}"></script>
<div class="container-fluid add-location">
<div class="row">
<div class="col-md-12">
<div class="card">
<form method="post" action="{{ route('locationstore') }}" name="locationadd" id="locationadd" enctype="multipart/form-data" novalidate>
{{ csrf_field() }}
<div class="card-header">
<h4 class="card-title"> Add My Location </h4>
</div>
#if(!empty($errors->all()))
<div class="row"> #foreach ($errors->all() as $error)
<div class="col-lg-12">
<div class="alert alert-danger"> <span>{{ $error }}</span> </div>
</div>
#endforeach </div>
<div class="row geolocationerror hide">
<div class="col-lg-12">
<div class="alert alert-danger"> <span>location not found</span> </div>
</div>
</div>
#endif
<div class="card-content">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-6">
<div class="form-group">
<label class="control-label">Location Name
<star>*</star>
</label>
<input id="location_name" name="location_name" class="controls form-control" type="text" placeholder="Location Name" value="{{ old('location_name') }}">
#if ($errors->has('location_name')) <span class="help-block"> {{ $errors->first('location_name') }} </span> #endif </div>
</div>
<div class="col-xs-12 col-sm-12 col-md-6">
<div class="form-group">
<label class="control-label">Clinics
<star>*</star>
</label>
<select class="selectpicker" data-style="btn-info btn-fill btn-block" id="clinic_id" name="clinic_id">
#foreach($clinics as$clinic)
<option value="{!! $clinic->clinicID !!}" id="{!! $clinic->clinicID !!}">{!! $clinic->clinicName !!}</option>
#endforeach
</select>
#if ($errors->has('category_id')) <span class="help-block"> {{ $errors->first('category_id') }} </span> #endif </div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-6">
<div class="form-group">
<label class="control-label">Address Line 1
<star>*</star>
</label>
<input type="text" placeholder="Address Line 1" class="form-control geoaddress" id="address_1" name="address_1" value="">
</div>
<div class="form-group">
<label class="control-label">Address Line 2 </label>
<input type="text" placeholder="Address Line 2" class="form-control geoaddress" id="address_2" name="address_2" value="">
</div>
<div class="form-group">
<label class="control-label">City
<star>*</star>
</label>
<input type="text" placeholder="City" class="form-control geoaddress" id="city" name="city" value="">
</div>
<div class="form-group">
<label class="control-label">State
<star>*</star>
</label>
<input type="text" placeholder="State" class="form-control geoaddress" id="state" name="state" value="">
<input type="hidden" id="state_code" name="state_code" value="" class="hidden-validation">
<input type="hidden" id="formatted_address" name="formatted_address" value="" class="hidden-validation">
<input type="hidden" id="latitude" name="latitude" value="" class="hidden-validation">
<input type="hidden" id="longitude" name="longitude" value="" class="hidden-validation">
</div>
<div class="form-group">
<label class="control-label">Country
<star>*</star>
</label>
<input type="text" placeholder="Country" class="form-control geoaddress" id="country" name="country" value="">
</div>
<div class="form-group">
<label class="control-label">Zip
<star>*</star>
</label>
<input type="text" placeholder="Zip" class="form-control geoaddress" id="zip" name="zip" value="">
</div>
<div class="form-group">
<label class="control-label">Phone Number
<star>*</star>
</label>
<input type="text" placeholder="Phone Number" class="form-control geoaddress" id="phone" name="phone" onkeypress="return isNumber(event)">
</div>
<div class="form-group">
<label class="control-label">Website
<star>*</star>
</label>
<input type="text" placeholder="Website" class="form-control" id="website" name="website" >
<span class="text-info"><strong>[ex. http://www.website.com]</strong></span> </div>
<div class="form-group">
<label class="control-label">Location Email
<star>*</star>
</label>
<input type="text" placeholder="Reports Email" class="form-control" id="reports_email" name="reports_email">
</div>
</div>
<div class="col-xs-12 col-sm-12 col-md-6">
<div class="form-group hide">
<label class="control-label">Location
<star>*</star>
</label>
<input id="pac-input" name="location" class="controls form-control" type="text" placeholder="Search Box">
<!-- <div id="map" height="1000" width="1000"></div> -->
</div>
<h4 >Preview</h4>
<div class="form-group">
<div id="regularMap" class="map"></div>
</div>
</div>
</div>
</div>
<div class="clear"></div>
<div class="clear"></div>
<div class="col-xs-12 col-sm-12 col-md-6">
</div>
<div class="clear"></div>
<div class="col-xs-12 col-sm-12 col-md-12 form-action">
<button type="submit" class="btn btn-fill btn-info">Submit</button>
Cancel </div>
<div class="clear"></div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="{{ asset('js/bootstrap-selectpicker.js')}}"></script>
<script>
$(document).ready(function(){
{{-- custom.initSmallGoogleMaps('41.31', '-72.92'); --}}
var map = new google.maps.Map(document.getElementById('regularMap'), {
zoom: 16,
center: new google.maps.LatLng(41.31,-72.92),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
myMarker = new google.maps.Marker({
position: new google.maps.LatLng(41.31, -72.92),
draggable: true
});
map.setCenter(myMarker.position);
myMarker.setMap(map);
google.maps.event.addListener(myMarker, 'dragend', function(evt) {
document.getElementById("latitude").value = evt.latLng.lat();
document.getElementById("longitude").value = evt.latLng.lng();
});
$('#locationadd').submit(function(event) {
var formatted_address = $('#formatted_address').val();
var latitude = $('#latitude').val();
var longitude = $('#longitude').val();
if(formatted_address == '' && !isFloat(latitude) && !isFloat(longitude))
{
getLocation();
}
});
$('.geoaddress').blur(function(){
getLocation();
})
function isFloat(n){
return Number(n) === n && n % 1 !== 0;
}
function getLocation(){
var address_1 = $('#address_1').val();
var address_2 = $('#address_2').val();
var city = $('#city').val();
var state = $('#state').val();
var country = $('#country').val();
var zip = $('#zip').val();
if(address_1 != '' && city != '' && state != '' && country != '' && zip != '' ){
var finalAdd = address_1+'+'+address_2+'+'+city+'+'+state+'+'+country+'+'+zip;
var formatted_address = address_1+' '+address_2+' '+city+' '+state+' '+country+' '+zip;
$.ajax({
url : 'https://maps.googleapis.com/maps/api/geocode/json?address='+finalAdd+'&key=MY_KEY',
type: 'GET',
success : function(data){
if(data.results.length >0){
var places = data.results;
document.getElementById("latitude").value = places[0].geometry.location.lat;
document.getElementById("longitude").value = places[0].geometry.location.lng;
document.getElementById("formatted_address").value = formatted_address;
document.getElementById("pac-input").value = places[0].formatted_address;
for (var i = 0, len = places[0].address_components.length; i < len; i++) {
var ac = places[0].address_components[i];
if (ac.types.indexOf("administrative_area_level_1") >= 0) {
document.getElementById("state_code").value = ac.short_name;
document.getElementById("state").value = ac.long_name;
}
}
var newLatLang = new google.maps.LatLng(places[0].geometry.location.lat, places[0].geometry.location.lng);
map.panTo(newLatLang);
myMarker.setPosition(newLatLang);
custom.getTimeZone(places[0].geometry.location.lat, places[0].geometry.location.lng);
}else{
document.getElementById("latitude").value = '';
document.getElementById("longitude").value = '';
document.getElementById("formatted_address").value = '';
$.scrollTo($('#geolocationerror'), 1000);
$('#geolocationerror').show();
event.preventDefault();
event.preventDefault();
}
}
});
}
}
});
</script>
{!! $validator !!}
#endsection
Please not that i have added correct API key, which i have added in .env file. Now the locations are only showing based on values provided in State,Zip,location name values etc.
I want maps get loaded based on the IP adddress
Related
I am using ajax for submitting data in the database but when I hit submit button in the return response "undefined " value I got, and the problem lies in the controller. I am not sure why I got this error. I am getting this error on fname variable and obv other variables too as they all are similar.
Here is the Controller
public function save(Request $request)
{
$validator = \Validator::make($request->all(), [
'cnic' => 'required|unique:patients',
]);
if ($validator->fails()) {
return response()->json(['success' => false, 'errors' => $validator->errors()->all()]);
}
$temppatientId = IdGenerator::generate(['table' => 'patients', 'length' => 5, 'prefix' => '22']);
$patientid = $temppatientId + 1;
$query = new patient;
$query->patientid = $patientid;
$query->fname =$fname;
$query->lname = $lname;
$query->cnic = $cnic;
$query->contactno = $contactno;
$query->gender = $gender;
$query->age = $age;
$query->dob = $dob;
$query->city = $city;
$query->address = $address;
$query->husbandname = $husbandname;
$query->fathername = $fathername;
$query->bloodgroup = $bloodgroup;
$query->maritalstatus = $maritalstatus;
$query->save();
return response()->json(['success' => true, 'patients' => $query]);
}
Here is the Ajax function
$(document).ready(function() {
$("#save1").on('click', function(e) {
var cnic = $("#cnic").val();
if (cnic == '') {
alert("Kindly Enter CNIC");
return false;
}
var gender = $("#gender").val();
if (gender == '') {
alert("Kindly Enter Gender");
return false;
}
var contactno = $("#contactno").val();
if (contactno == '') {
alert("Kindly Enter Contact No");
return false;
}
var fname = $("#fname").val();
if (fname == '') {
alert("Kindly Enter Name");
return false;
}
else{
$.ajax({
url: "/save",
type: "post",
data: $('#registrationform').serialize(),
dataType: 'json',
success: function(data) {
if (data.success === false) {
alert('CNIC already Exists !');
} else {
$("#patientid").val(data.patient.patientid);
// console.log(data.patient);
}
}
})
}
});
});
this is my blade file
<form class="form" data-parsley-validate id="registrationform" autocomplete="off">
#csrf
<div class="row">
<div class="col-md-4 col-4">
<div class="form-group mandatory">
<label for="first-name-column" class="form-label">First Name</label>
<input type="text" autofocus tabIndex="1" name="fname" id="fname" class="form-control" placeholder="First Name" name="fname" data-parsley-required="true">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group">
<label for="last-name-column" class="form-label">Last Name</label>
<input type="text" id="lname" tabIndex="2" class="form-control" placeholder="Last Name" name="lname">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group">
<label for="city-column" class="form-label">Age</label>
<input type="number" id="age" tabIndex="3" class="form-control" placeholder="Age" name="age" >
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group">
<label for="country-floating" class="form-label">DOB</label>
<input type="date" id="dob" tabIndex="4" class="form-control" name="dob" placeholder="Date of Birth">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group choices" mandatory>
<label for="company-column" class="form-label choices">Gender:</label>
<div class="form-group">
<select class="choices form-select" tabIndex="5" id="gender" name="gender">
<option value="">SELECT</option>
<option value="MALE">MALE</option>
<option value="FEMALE">FEMALE</option>
<option value="NEUTER">NEUTER</option>
</select>
</div>
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group mandatory">
<label for="email-id-column" class="form-label">Contact No</label>
<input type="number" id="contactno" tabIndex="6" class="form-control" name="contactno" placeholder="Contact No" data-parsley-required="true">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group ">
<label for="email-id-column" class="form-label">Father Name</label>
<input type="text" id="fathername" tabIndex="7" class="form-control" name="fathername" placeholder="Father Name" data-parsley-required="true">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group ">
<label for="email-id-column" class="form-label">Husband Name</label>
<input type="text" id="husbandname" tabIndex="8" class="form-control" name="husbandname" placeholder="Husband Name" data-parsley-required="true">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group mandatory">
<label for="email-id-column" class="form-label">CNIC</label>
<input type="number" id="cnic" class="form-control" tabIndex="9" name="cnic" placeholder="CNIC" data-parsley-required="true">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group ">
<label for="email-id-column" class="form-label">City</label>
<input type="text" id="city" tabIndex="10" class="form-control" name="city" placeholder="City" data-parsley-required="true">
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group choices">
<label for="company-column" class="form-label choices">Marital Status</label>
<div class="form-group">
<select class="choices form-select" tabIndex="11" id="maritalstatus" name="maritalstatus">
<option value="">SELECT</option>
<option value="NOT SPECIFIED">NOT SPECIFIED</option>
<option value="SINGLE">SINGLE</option>
<option value="MARRIED">MARRIED</option>
<option value="WIDOW">WIDOW</option>
<option value="WIDOWER">WIDOWER</option>
<option value="DIVORCED">DIVORCED</option>
<option value="SEPARATED">SEPARATED</option>
<option value="UNKNOWN">UNKNOWN</option>
</select>
</div>
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group choices">
<label for="company-column" class="form-label choices">Blood Group</label>
<div class="form-group">
<select class="choices form-select" tabIndex="12" id="bloodgroup" name="bloodgroup">
<option value="">SELECT</option>
<option value="NOT SPECIFIED">NOT SPECIFIED</option>
<option value="A POSITIVE">A POSITIVE</option>
<option value="A NEGATIVE">A NEGATIVE</option>
<option value="B POSITIVE">B POSITIVE</option>
<option value="B NEGATIVE">B NEGATIVE</option>
<option value="O POSITIVE">O POSITIVE</option>
<option value="O NEGATIVE">O NEGATIVE</option>
<option value="AB POSITIVE">AB POSITIVE</option>
<option value="AB NEGATIVE">AB NEGATIVE</option>
</select>
</div>
</div>
</div>
<div class="col-md-4 col-4">
<div class="form-group mandatory">
<label for="email-id-column" class="form-label">Address</label>
<input type="text" id="address" class="form-control" tabIndex="13" name="address" placeholder="Address" data-parsley-required="true">
</div>
</div>
<div class="col-6 col-lg-3 col-md-6">
<div class="card-body px-2 py-3-4">
<div class="row">
<div class="col-md-4 col-lg-4 col-xl-8 col-xxl-5 d-flex justify-content-start ">
<div class="stats-icon purple mb-2">
<i class="iconly-boldShow"></i>
</div>
</div>
<div class="col-md-8 col-lg-12 col-xl-12 col-xxl-7">
<h6 class="text-muted font-semibold">Patient ID</h6>
<input class="font-extrabold mb-0" style="align-content: center; color:red; " type="number" name="patientid" id="patientid" disabled>
</div>
</div>
</div>
</div>
{{-- <label>Search Patient:</label>
<div class="col-lg-2">
<label>Patient ID:</label>
<input placeholder="Enter Patient ID" type="number" name="patientid"
id="selectpatientid" class="form-control form-control-sm d2">
</div>
<div class="col-lg-2">
<label>Patient CNIC:</label>
<input placeholder="Enter Patient CNIC" type="number" name="cnic"
id="selectpatientcnic" class="form-control form-control-sm d2">
</div>
</div> --}}
<div class="row">
<div class="col-12 d-flex justify-content-end">
<a id="save1" tabIndex="14" class="btn btn-primary me-1 mb-1">Register</a>
{{-- <button type="submit" class="btn btn-light-secondary me-1 mb-1">Register</button> --}}
<button type="reset" class="btn btn-light-secondary me-1 mb-1">Reset</button>
</div>
</div>
</form>
Try opening the F12 tools and heading over to the networking tab, under the networking tab you can double check the CSR under is getting pass along to the app under the 'headers' or 'request' once you've clicked on your jQuery request
You should also be able to see that larval responded with if you click 'response'
It might also be worth checking out the laravel.log under storage provider any more insight to the problem, this normally contains some help hints
I'm having some troble with AJAX call to update a page after insert the info in the DB.
I update the form, but i need to update the form after the update.
Need some help, i'm not so good whit javascript.
Thks!
<script>
function chk()
{
var nome=document.getElementById('nome').value;
var dataString= 'nome='+ nome;
$.ajax({
type:"post",
url: default,
data:dataString,
cache:false
//success: function(html){
// $('#msg').html(html);
//}
});
return false;
}
</script>
All the code i use, it's not final and not uptimized, its a form, update the field, and i want to update with the changes, without make a page refresh
<div class="col-md-12 personal-info">
<form class="form-horizontal" role="form" method="post" action="">
<div class="form-group">
<label class="col-lg-4 control-label">Nome:</label>
<div class="col-lg-8">
<input class="form-control" type="text" id="nome" name="nome" value="<?php echo name($resultado); ?>">
<!--<input class="form-control" type="text" value="<?php $nome; ?>">-->
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label">Apelido:</label>
<div class="col-lg-8">
<input class="form-control" type="text" value="<?php echo apelido($chamada); ?>">
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label">Morada:</label>
<div class="col-lg-8">
<input class="form-control" type="text" value="<?php echo morada(); ?>">
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label">Código Postal:</label>
<div class="col-lg-8">
<input class="form-control" type="text" value="<?php echo codigopostal(); ?>">
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label">Localidade:</label>
<div class="col-lg-8">
<input class="form-control" type="text" value="<?php echo localidade(); ?>">
</div>
</div>
<div class="form-group">
<label class="col-lg-4 control-label">Email:</label>
<div class="col-lg-8">
<input class="form-control" type="text" value="<?php echo email(); ?>">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Username:</label>
<div class="col-md-8">
<input class="form-control" type="text" value="<?php echo $current_user->user_login ?>">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Password:</label>
<div class="col-md-8">
<input class="form-control" type="password" value="11111122333">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Confirm password:</label>
<div class="col-md-8">
<input class="form-control" type="password" value="11111122333">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label"></label>
<div class="col-md-8">
<input type="submit" name="submit" class="btn btn-primary" value="Save Changes" onclick="return chk()">
<!--<input type="submit" name="submit" class="btn btn-primary" value="Save Changes">-->
<span></span>
<input type="reset" name="reset" class="btn btn-default" value="Cancel">
</div>
</div>
</form>
</div>
</div>
</div>
<hr>
<!--teste final-->
<?php
global $wpdb;
global $seconddb;
global $current_user;
if ($_POST['submit']){
$new = $_POST['nome'];
$query = $seconddb->query("UPDATE {$wpdb->prefix}sgc_socios SET nome='$new' WHERE email = '{$current_user->user_email}' ");
}
?>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
function chk()
{
var nome=document.getElementById('nome').value;
var dataString= 'nome='+ nome;
$.ajax({
type:"post",
url: default,
data:dataString,
cache:false
//success: function(html){
// $('#msg').html(html);
//}
});
return false;
}
</script>
Thks for the help!
In my form i created multiselect drop down list. i need to store the data which i selected from my multi select drop down to database, table name devicelist along with some value that is taken from my form.
my view page is
#extends('app')
#section('content')
<br><br><br><br><br>
<div class="templatemo-content-wrapper">
<div class="container">
<ol class="breadcrumb">
<li><font color="green">Home</font></li>
<li class="active">View/Edit Vehicle</li>
</ol>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-success">
<div class="panel-heading">View/Edit Vehicle Information</div>
<div class="panel-body">
#if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form class="form-horizontal" role="form" method="POST" action="{{ url('vehicle/update/') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
#foreach($devices as $device)
<div class="form-group">
<label class="col-md-4 control-label">Vehicle ID</label>
<div class="col-md-6">
<input type="text" class="form-control" name="deviceID" value="{{ ($device->deviceID)}}">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Creation date</label>
<div class="col-md-6">
<input type="text" class="form-control" name="creationTime" value="{{ date('Y/m/d H:i:s',($device->creationTime))}}">
</div>
</div>
<!--<div class="form-group">
<label class="col-md-4 control-label">Server ID</label>
<div class="col-md-6">
<input type="text" class="form-control" name="userID" value="" placeholder="Enter User ID">
</div>
</div> -->
<div class="form-group">
<label class="col-md-4 control-label">Unique ID</label>
<div class="col-md-6">
<input type="text" class="form-control" name="uniqueID" value="{{ ($device->uniqueID)}}" placeholder="Enter Unique ID">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Active</label>
<div class="col-md-6">
<select class="form-control" value="{{ ($device->isActive) }}" name="isActive" >
<option value="1">Yes</option>
<option value="0">No</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Vehicle Description</label>
<div class="col-md-6">
<input type="text" class="form-control" name="description" value="{{ ($device->description) }}" placeholder="Enter the description">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Short Name</label>
<div class="col-md-6">
<input type="text" class="form-control" name="displayName" value="{{ ($device->displayName) }}" placeholder="Enter Display Name">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Vehicle ID</label>
<div class="col-md-6">
<input type="text" class="form-control" name="vehicleID" value="{{ ($device->vehicleID) }}" placeholder="Enter Vehicle ID">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">License Plate</label>
<div class="col-md-6">
<input type="text" class="form-control" name="licensePlate" value="{{ ($device->licensePlate) }}" placeholder="Enter license Plate">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">License Expiration</label>
<div class="col-md-6">
<input type="date" class="form-control" name="licenseExpire" value="{{ ($device->licenseExpire) }}" placeholder="Enter license Expire Date">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Equipment Type</label>
<div class="col-md-6">
<input type="email" class="form-control" name="equipmentType" value="{{ ($device->equipmentType) }}" placeholder="Enter E-Mail Address">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Equipment Status</label>
<div class="col-md-6">
<select class="form-control" value="{{ ($device->equipmentStatus) }}" name="equipmentStatus" >
<option>Unspecified</option>
<option value="inservice">In Service</option>
<option value="rented">Rented</option>
<option value="pending">Pending</option>
<option value="completed">Completed</option>
<option value="available">Available</option>
<option value="unavailable">Unavailable</option>
<option value="repair">Repair</option>
<option value="retired">Retired</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">IMEI/EDN Number</label>
<div class="col-md-6">
<input type="email" class="form-control" name="imeiNumber" value="{{ ($device->imeiNumber) }}" placeholder="Enter IMEI/EDN Number">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Serial Number</label>
<div class="col-md-6">
<input type="email" class="form-control" name="serialNumber" value="{{ ($device->serialNumber) }}" placeholder="Enter Serial Number">
</div>
</div>
<!-- <div class="form-group">
<label class="col-md-4 control-label">Data Key</label>
<div class="col-md-6">
<input type="email" class="form-control" name="notifyEmail" value="" placeholder="Enter E-Mail Address">
</div>
</div> -->
<div class="form-group">
<label class="col-md-4 control-label">SIM Phone</label>
<div class="col-md-6">
<input type="email" class="form-control" name="simPhoneNumber" value="{{ ($device->simPhoneNumber) }}" placeholder="Enter SIM Phone Number">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">SMS Email Address</label>
<div class="col-md-6">
<input type="email" class="form-control" name="smsEmail" value="{{ ($device->smsEmail) }}" placeholder="Enter SMS E-Mail Address">
</div>
</div>
<!-- <div class="form-group">
<label class="col-md-4 control-label">Group Pushpin ID</label>
<div class="col-md-6">
<input type="email" class="form-control" name="notifyEmail" value="" placeholder="Enter E-Mail Address">
</div>
</div> -->
<div class="form-group">
<label class="col-md-4 control-label">Map Route Color</label>
<div class="col-md-6">
<select class="form-control" value="{{ ($device->displayColor) }}" name="displayColor" >
<option>Default</option>
<option value="#000000">Black</option>
<option value="#a52a2a">Brown</option>
<option value="#dd0000">Red</option>
<option value="#b37400">Orange</option>
<option value="#008f00">Green</option>
<option value="#0000ee">Blue</option>
<option value="#9400d3">Purple</option>
<option value="#505050">Grey</option>
<option value="#00b3b3">Cyan</option>
<option value="#ff1493">Pink</option>
<option value="none">None</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Fuel Capacity</label>
<div class="col-md-6">
<input type="text" class="form-control" name="fuelCapacity" value="{{ ($device->fuelCapacity) }}" >
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Driver ID</label>
<div class="col-md-6">
<input type="email" class="form-control" name="driverID" value="{{ ($device->driverID) }}">
</div>
</div>
<!-- <div class="form-group">
<label class="col-md-4 control-label">Reported Odometer</label>
<div class="col-md-6">
<input type="email" class="form-control" name="notifyEmail" value="" placeholder="Enter E-Mail Address">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Reported Engine Hours</label>
<div class="col-md-6">
<input type="email" class="form-control" name="notifyEmail" value="" placeholder="Enter E-Mail Address">
</div>
</div> -->
<div class="form-group">
<label class="col-md-4 control-label">Group Membership</label>
<div class="col-md-6">
{{--<select class="form-control" value="{{ old('groupID') }}" name="groupID" multiple >--}}
{{--#foreach( $grouplist as $group)--}}
{{--#if ($group->groupID == old('description'))--}}
{{--<option value="{{ $group->groupID }}" >{{ $group->groupID." ".'['.$group->description.']' }}</option>--}}
{{--#else--}}
{{--<option value="{{ $group->groupID }}" >{{ $group->groupID." ".'['.$group->description.']' }}</option>--}}
{{--#endif--}}
{{--#endforeach--}}
{{--</select>--}}
<script type="text/javascript">
$(".js-example-basic-multiple").select2();
</script>
<select class="js-example-basic-multiple js-states form-control" id="id_label_multiple" value="{{ old('groupID[]') }}" name="groupID" multiple="multiple" >
#foreach( $grouplist as $group)
#if ($group->groupID == old('description'))
<option value="{{ $group->groupID }}" >{{ $group->groupID." ".'['.$group->description.']' }}</option>
#else
<option value="{{ $group->groupID }}" >{{ $group->groupID." ".'['.$group->description.']' }}</option>
#endif
#endforeach
</select>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-warning">
Update
</button>
</div>
</div>
#endforeach
</form>
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
and my controller page is
public function update(Request $request)
{
try {
$postUser = Input::all();
//insert data into mysql table
$account = Account::select('accountID')->where('accountID', '=', 'gts')->get();
foreach ($account as $acc) {
$abc = $acc->accountID;
}
$data=DB::table('device')
->where("deviceID",$request['deviceID'])
->update(array(
"uniqueID"=>$request['uniqueID'],
"isActive"=>$request['isActive'],
"description"=>$request['description'],
"displayName"=>$request['displayName'],
"vehicleID"=>$request['vehicleID'],
"licensePlate"=>$request['licensePlate'],
"licenseExpire"=>$request['licenseExpire'],
"equipmentType"=>$request['equipmentType'],
"equipmentStatus"=>$request['equipmentStatus'],
"imeiNumber"=>$request['imeiNumber'],
"serialNumber"=>$request['serialNumber'],
"simPhoneNumber"=>$request['simPhoneNumber'],
"smsEmail"=>$request['smsEmail'],
"displayColor"=>$request['displayColor'],
"fuelCapacity"=>$request['fuelCapacity'],
"driverID"=>$request['driverID'],
"lastUpdateTime"=>time()));
$data = array("accountID" => $abc,
"deviceID"=> $request['deviceID'],
"groupID"=>$request['groupID[]'],
"lastUpdateTime"=>time(),
"creationTime"=>time());
$ck = 0;
$ck = DB::table('devicelist')->Insert($data);
$devices = DB::table('device')->simplePaginate(10);
return view('vehicle.vehicleAdmin')->with('devices', $devices);
} catch (ModelNotFoundException $err) {
//Show error page
}
}
}
how can i write the function to store the data from multiselect drop down to my table each value in each row along with other value. Can anyone tell me what should i do? and how to write "string to array" conversion and "for loop" for the insertion
If you are getting array from multi select and want to insert it in one row. You should implode array into comma separated string then insert it in table
Implode function
$val = implode(",",$request['groupID[]']);
Then put $val into your $data array like
$data = array("accountID" => $abc,
"deviceID"=> $request['deviceID'],
"groupID"=>$val,
"lastUpdateTime"=>time(),
"creationTime"=>time());
If you are getting string then explode it
Explode function
$val = explode(",",$request['groupID[]']);
$count = count($val);
for($a=0; $a<$count; $a++){
$data = array("accountID" => $abc,
"deviceID"=> $request['deviceID'],
"groupID"=>$val[$a],
"lastUpdateTime"=>time(),
"creationTime"=>time());
}
I created one table in one page, to that table fetching data from database. Then give dynamic buttons for delete and Edit/View. When i click on Delete , it will delete corresponding row from database. Previously it was working properly. But now it showing error "NotFoundHttpException in RouteCollection.php line 161:". Can anyone tell what wrong i did in my code?
My vehicleController.php
<?php
namespace App\Http\Controllers;
use Mail;
use Illuminate\Support\Facades\DB;
use App\Device;
use App\Account;
use App\Http\Requests\createUserRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Input;
use Illuminate\Pagination\Paginator;
class VehicleController extends Controller
{
public $type = 'Device';
public function getIndex()
{
$devices = DB::table('device')->simplePaginate(15);
return view('vehicle.vehicleAdmin')->with('devices', $devices);
}
public function vehicleInsert()
{
$postUser = Input::all();
//insert data into mysql table
$account = Account::select('accountID')->get();
foreach ($account as $acc) {
$abc = $acc->accountID;
}
$data = array("accountID" => $abc,
"vehicleID"=> $postUser['vehicleID']
);
// echo print_r($data);
$ck = 0;
$ck = DB::table('device')->Insert($data);
//echo "Record Added Successfully!";
$devices = DB::table('device')->simplePaginate(50);
return view('vehicle.vehicleAdmin')->with('devices', $devices);
}
public function delete($id)
{
DB::table('device')->where('vehicleID', '=', $id)->delete();
return redirect('vehicleAdmin');
}
public function edit($id)
{
try {
//Find the user object from model if it exists
$devices = DB::table('device')->where('vehicleID', '=', $id)->get();
//$user = User::findOrFail($id);
//Redirect to edit user form with the user info found above.
return view('vehicle.add')->with('devices', $devices);
} catch (ModelNotFoundException $err) {
//redirect to your error page
}
}
}
my vehicleAdmin.blade,php
#extends('app')
#section('content')
<div class="templatemo-content-wrapper">
<div class="templatemo-content">
<ol class="breadcrumb">
<li><font color="green">Home</font></li>
<li class="active">Vehicle information</li>
</ol>
<h1>View/Edit Vehicle information</h1>
<p></p>
<div class="row">
<div class="col-md-12">
<div class="table-responsive" style="overflow-x:auto;">
<table id="example" class="table table-striped table-hover table-bordered" bgcolor="#fff8dc">
<h3>Select a Vehicle :</h3>
<thead>
<tr>
<th>Vehicle ID</th>
<th>Unique ID</th>
<th>Description</th>
<th>Equipment Type</th>
<th>SIM Phone</th>
<th>Server ID</th>
<th>Ignition State</th>
<th>Expecting ACK</th>
<th>Active</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
#foreach($devices as $device)
<tr>
<td>{{ $device->vehicleID }}</td>
<td>{{ $device->uniqueID }}</td>
<td>{{ $device->description }}</td>
<td>{{ $device->equipmentType }}</td>
<td>{{ $device->simPhoneNumber }}</td>
<td></td>
<td>
#if(#$device->ignitionIndex == '0')
OFF
#else
ON
#endif
</td>
<td>{{ $device->expectAck }}</td>
<td>
#if($device->isActive == '1')
Yes
#else
No
#endif
</td>
<td>
<div class="btn-group">
<button type="button" class="btn btn-info">Action</button>
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" role="menu">
<li>
View/ Edit
</li>
<li>Delete</li>
</ul>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
{{--{!! $results->appends(['sort' => $sort])->render() !!}--}}
{{$devices->links()}}
</div>
</div>
</div>
</div>
</div>
{{--{!! $device->links()!!}--}}
</br>
<h4>Create a new Vehicle</h4>
<form role="form" method="POST" action="{{ url('vehicleAdmin') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="row">
<div class="col-md-6 margin-bottom-15">
<input type="text" class="form-control" name="vehicleID" value="{{ old('vehicleID') }}" placeholder="Enter vehicle ID">
</div>
<div class="row templatemo-form-buttons">
<div class="submit-button">
<button type="submit" class="btn btn-primary">New</button>
</div>
</div>
</div>
</form>
<script type="text/javascript">
$(document).ready(function() {
$('#example').dataTable();
} );
</script>
#endsection
Edit page add.blade.php
#extends('app')
#section('content')
<div class="templatemo-content-wrapper">
<div class="container">
<ol class="breadcrumb">
<li><font color="green">Home</font></li>
<li class="active">View/Edit Vehicle</li>
</ol>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-success">
<div class="panel-heading">View/Edit Vehicle Information</div>
<div class="panel-body">
#if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form class="form-horizontal" role="form" method="POST" action="{{ url('vehicle/update/') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
#foreach($devices as $device)
<div class="form-group">
<label class="col-md-4 control-label">Vehicle ID</label>
<div class="col-md-6">
<input type="text" class="form-control" name="vehicleID" value="{{ ($device->vehicleID)}}" placeholder="Enter User ID">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Creation date</label>
<div class="col-md-6">
<input type="text" class="form-control" name="creationTime" value="{{ ($device->creationTime)}}">
</div>
</div>
<!--<div class="form-group">
<label class="col-md-4 control-label">Server ID</label>
<div class="col-md-6">
<input type="text" class="form-control" name="userID" value="{{ ($device->userID)}}" placeholder="Enter User ID">
</div>
</div> -->
<div class="form-group">
<label class="col-md-4 control-label">Unique ID</label>
<div class="col-md-6">
<input type="text" class="form-control" name="uniqueID" value="{{ ($device->uniqueID)}}" placeholder="Enter Unique ID">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Active</label>
<div class="col-md-6">
<select class="form-control" value="{{ ($device->isActive) }}" name="isActive" >
<option value="1">Yes</option>
<option value="0">No</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Vehicle Description</label>
<div class="col-md-6">
<input type="text" class="form-control" name="description" value="{{ ($device->description) }}" placeholder="Enter the description">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Short Name</label>
<div class="col-md-6">
<input type="text" class="form-control" name="displayName" value="{{ ($device->displayName) }}" placeholder="Enter Contact Name">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Vehicle ID</label>
<div class="col-md-6">
<input type="text" class="form-control" name="vehicleID" value="{{ ($device->vehicleID) }}" placeholder="Enter Vehicle ID">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">License Plate</label>
<div class="col-md-6">
<input type="text" class="form-control" name="licensePlate" value="{{ ($device->licensePlate) }}" placeholder="Enter license Plate">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">License Expiration</label>
<div class="col-md-6">
<input type="text" class="form-control" name="licenseExpire" value="{{ ($device->licenseExpire) }}" placeholder="Enter license Expire Date">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Equipment Type</label>
<div class="col-md-6">
<input type="email" class="form-control" name="equipmentType" value="{{ ($device->equipmentType) }}" placeholder="Enter E-Mail Address">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Equipment Status</label>
<div class="col-md-6">
<select class="form-control" value="{{ ($device->equipmentStatus) }}" name="equipmentStatus" >
<option value="0">In Service</option>
<option value="#">Rented</option>
<option value="#">Pending</option>
<option value="#">Completed</option>
<option value="#">Available</option>
<option value="#">Unavailable</option>
<option value="#">Repair</option>
<option value="#">Retired</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">IMEI/EDN Number</label>
<div class="col-md-6">
<input type="email" class="form-control" name="notifyEmail" value="{{ ($device->imeiNumber) }}" placeholder="Enter IMEI/EDN Number">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Serial Number</label>
<div class="col-md-6">
<input type="email" class="form-control" name="notifyEmail" value="{{ ($device->serialNumber) }}" placeholder="Enter Serial Number">
</div>
</div>
<!-- <div class="form-group">
<label class="col-md-4 control-label">Data Key</label>
<div class="col-md-6">
<input type="email" class="form-control" name="notifyEmail" value="{{ ($device->notifyEmail) }}" placeholder="Enter E-Mail Address">
</div>
</div> -->
<div class="form-group">
<label class="col-md-4 control-label">SIM Phone</label>
<div class="col-md-6">
<input type="email" class="form-control" name="notifyEmail" value="{{ ($device->simPhoneNumber) }}" placeholder="Enter SIM Phone Number">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">SMS Email Address</label>
<div class="col-md-6">
<input type="email" class="form-control" name="notifyEmail" value="{{ ($device->smsEmail) }}" placeholder="Enter SMS E-Mail Address">
</div>
</div>
<!-- <div class="form-group">
<label class="col-md-4 control-label">Group Pushpin ID</label>
<div class="col-md-6">
<input type="email" class="form-control" name="notifyEmail" value="{{ ($device->notifyEmail) }}" placeholder="Enter E-Mail Address">
</div>
</div> -->
<div class="form-group">
<label class="col-md-4 control-label">Map Route Color</label>
<div class="col-md-6">
<select class="form-control" value="{{ ($device->timeZone) }}" name="timeZone" >
<option value="0">Black</option>
<option value="#">Brown</option>
<option value="#">Red</option>
<option value="#">Orange</option>
<option value="#">Green</option>
<option value="#">Blue</option>
<option value="#">Purple</option>
<option value="#">Grey</option>
<option value="#">Cyan</option>
<option value="#">Pink</option>
<option value="#">None</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Fuel Capacity</label>
<div class="col-md-6">
<input type="email" class="form-control" name="fuelCapacity" value="{{ ($device->fuelCapacity) }}" >
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Driver ID</label>
<div class="col-md-6">
<input type="email" class="form-control" name="driverID" value="{{ ($device->driverID) }}">
</div>
</div>
<!-- <div class="form-group">
<label class="col-md-4 control-label">Reported Odometer</label>
<div class="col-md-6">
<input type="email" class="form-control" name="notifyEmail" value="{{ old('notifyEmail') }}" placeholder="Enter E-Mail Address">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Reported Engine Hours</label>
<div class="col-md-6">
<input type="email" class="form-control" name="notifyEmail" value="{{ old('notifyEmail') }}" placeholder="Enter E-Mail Address">
</div>
</div> -->
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-warning">
Save
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
#endsection
Routes.php
Route::any('vehicleAdmin', 'VehicleController#getIndex');
Route::post('vehicleAdmin', 'VehicleController#vehicleInsert');
Route::get('vehicle/edit/{id}', 'VehicleController#edit');
Route::delete('vehicle/delete/{id}', 'VehicleController#delete');
I think when you click the link, it is probably sending a GET request to that end point unless you set the method to delete in ajax call,. CRUD in Laravel works according to REST. This means it is expecting a DELETE request instead of GET.
So I would suggest you to make your route as follow
Route::get('/vehicle/delete/{id}', 'VehicleController#delete');
I have an AngularJS front end for a new internal web portal I am building. Using value={{data.Param}} I have successfully gotten my get and create requests to work via Slim PHP. Now however I am trying to create a PUT request and I am running into an issue.
This is the current code for my "Update /PUT" page.
request-edit.html
<div class="jumbotron text-center">
<form class="form-horizontal" role="form">
<div class="form-group">
<div class="text-center">
<h1>{{ header }}</h1>
<br/>
<h3>{{ request.Header }}</h3>
<br/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Id:</label>
<div class="col-sm-3">
<input name="id" class="form-control" type="text" value="{{request.ID}}" disabled />
</div>
<label class="col-sm-3 control-label">Date:</label>
<div class="col-sm-3">
<input type="text" class="form-control" value="{{ request.Date_Submitted }}" disabled/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Change Initiator:</label>
<div class="col-sm-3">
<input type="text" class="form-control" placeholder="{{request.Change_Initiator}}" ng-model="request.changeInitiator"/>
</div>
<label class="col-sm-3 control-label">Risk Level:</label>
<div class="col-sm-3">
<input type="text" class="form-control" placeholder="{{ request.Risk_Level }}" ng-model="request.riskLevel" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">CI Details:</label>
<div class="col-sm-3">
<input type="text" class="form-control" placeholder="{{ request.Change_Initiator_id }}" ng-model="request.changeInitiatorId" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Requestor:</label>
<div class="col-sm-3">
<input type="text" class="form-control" placeholder="{{ request.Requestor }}" ng-model="request.requestor" />
</div>
<label class="col-sm-3 control-label">Systems Affected:</label>
<div class="col-sm-3">
<input type="text" class="form-control" placeholder="{{ request.Systems_Affected }}" ng-model="request.systemsAffected" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Implemented By:</label>
<div class="col-sm-3">
<input type="text" class="form-control" placeholder="{{ request.Implemented_By }}" ng-model="request.implementationBy" />
</div>
<label class="col-sm-3 control-label">Implementation Date:</label>
<div class="col-sm-3">
<input type="text" class="form-control" placeholder="{{ request.Implementation_Date }}" ng-model="request.implementationDate" bs-datepicker/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Close Date:</label>
<div class="col-sm-3">
<input type="text" class="form-control" placeholder="{{ request.Close_Date }}" ng-model="request.closeDate" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Work to be Performed:</label>
<div class="col-sm-3">
<textarea name="request.description" ng-model="request.workToBePerformed" placeholder="{{ request.Work_to_be_performed }}" ></textarea>
</div>
<label class="col-sm-3 control-label">Backout Plan:</label>
<div class="col-sm-3">
<textarea name="request.description" ng-model="request.backoutPlan" placeholder="{{ request.Backout_Plan }}" ></textarea>
</div>
</div>
<div class="form-group">
<button class="update" ng:click="updateRequest()">Save Edits</button>
<button class="approve" ng:click="approveRequest()">Approve</button>
</div>
</form>
<div class="form-group">
<a href="#/requests" class="btn btn-default pull-right">
<span class="glyphicon glyphicon-arrow-left"></span> Back
</a>
</div>
</div>
My confusion in with ng-model, value and placeholders. Currently all my data populates in the form, but when the user goes to update the page they have to re-fill out every box or else blank data will be pushed. I understand the Placeholder does not actually fill in the data - however I have been un-able to use both ng-model and value on the same input field.
My top two fields populate using value just fine, but I do not want people to edit the date or ID. My other fields show the correct data in a temp form using placeholder but do not populate using ng-model. Additionally when my user goes to make the update the ng-model DOES function.
So in short my current issue is that ng-model does not display the original data- but does push it correctly. This causes my users to have to re-type all the data everytime or else the record will be updated with null values.
Below is the rest of my logic for review.
app.js
var app = angular.module('changeControlApp', [
'ngRoute',
'ngResource'
]);
//This configures the routes and associates each route with a view and a controller
app.config(function($routeProvider, $locationProvider) {
//$locationProvider.html5Mode(true);
$routeProvider
.when('/', {templateUrl: 'app/partials/request-list.html', controller: 'viewController' })
.when('/requests', {templateUrl: 'app/partials/request-list.html', controller: 'viewController' })
.when('/requests/create', {templateUrl: 'app/partials/request-create.html', controller: 'createRequestController' })
.when('/settings', {templateUrl: 'app/partials/settings.html', controller: 'settingsController'})
.when('/requests/:id', {templateUrl: 'app/partials/request-view.html', controller: 'viewRequestController' })
.when('/requests/edit/:id', {templateUrl: 'app/partials/request-edit.html', controller: 'editRequestController' })
.otherwise({ redirectTo: '/' });
});
app.controller('editRequestController', function($scope, $location, $route, $routeParams, $resource) {
$scope.header = 'Edit Change Request';
// Update User details
var request_Id = $routeParams.id;
if (request_Id) {
var Request = $resource(('http://pdgrosit02v/changeRequest/app/api/requests/'+ request_Id));
$scope.request = Request.get();
}
$scope.updateRequest = function() {
var RequestPut = $resource(('http://pdgrosit02v/changeRequest/app/api/requests/'+ request_Id), {}, { update: { method: 'PUT'}} );
RequestPut.update($scope.request, function() {
// success
$location.path('/requests');
}, function() {
// error
console.log(error);
});
}
});
And the Slim file
index.php
<?php
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();
use Slim\Slim;
$app = new Slim();
//$paramValue = $app->request->params('paramName');
$app->get('/requests', 'getRequests');
$app->get('/requests/:id', 'getRequest');
$app->post('/requests/create', 'addRequest');
$app->put('/requests/:id', 'updateRequest');
$app->run();
function updateRequest($id) {
$request = Slim::getInstance()->request()->getBody();
$data = json_decode($request, true);
$sql = "UPDATE change_request SET Change_Initiator=:changeInitiator, Change_Initiator_id=:changeInitiatorId, Risk_Level=:riskLevel, Requestor=:requestor, Work_to_be_performed=:workToBePerformed, Backout_Plan=:backoutPlan, Backout_Time=:backoutTime, Implementation_Date=:implementationDate, Header=:title, Systems_Affected=:systemsAffected, Implemented_By=:implementationBy WHERE ID=$id";
//$sql = "UPDATE change_request SET Change_Initiator=:changeInitiator WHERE ID=$id";
try {
$db = getConnection();
$stmt = $db->prepare($sql);
$stmt->bindValue(":changeInitiator", $data['changeInitiator']);
$stmt->bindParam(":changeInitiatorId", $data['changeInitiatorId']);
$stmt->bindParam(":riskLevel", $data['riskLevel']);
$stmt->bindParam(":requestor", $data['requestor']);
$stmt->bindParam(":workToBePerformed", $data['workToBePerformed']);
$stmt->bindParam(":backoutPlan", $data['backoutPlan']);
$stmt->bindParam(":backoutTime", $data['backoutTime']);
$stmt->bindParam(":implementationDate", $data['implementationDate']);
$stmt->bindParam(":title", $data['title']);
$stmt->bindParam(":systemsAffected", $data['systemsAffected']);
$stmt->bindParam(":implementationBy", $data['implementationBy']);
$stmt->execute();
$db = null;
echo json_encode($data);
} catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}
I figured out the issue, turns out Value and ng-model conflict and I had to modify my form to get the data correctly.
I removed all value commands and replaced them with ng-model="data.keyvalue". I was confused before as I thought you needed to use {{}} when referencing things off the scope.
I also added form validation for updating - new code below
request-edit.html
<div class="jumbotron text-center">
<form class="form-horizontal" role="form" name="requestEditForm" ng-submit="updateRequest()">
<div class="form-group">
<div class="text-center">
<h1>{{ header }}</h1>
<br/>
<h3>Title of request:</h3>
<input name="title" id="title" class="form-control" type="text" ng-model="request.Header" />
<br/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Id:</label>
<div class="col-sm-3">
<input name="id" class="form-control" type="text" value="{{request.ID}}" disabled />
</div>
<label class="col-sm-3 control-label">Date Submitted:</label>
<div class="col-sm-3">
<input type="text" class="form-control" value="{{ request.Date_Submitted }}" disabled/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Change Initiator:</label>
<div class="col-sm-3">
<input type="text" class="form-control" ng-model="request.Change_Initiator" name="changeInitiator" id="changeInitiator" />
<span class="error" ng-show="requestEditForm.changeInitiator.$error.required && requestEditForm.changeInitiator.$dirty">Title is required</span>
</div>
<label class="col-sm-3 control-label">Risk Level:</label>
<div class="col-sm-3">
<input type="text" class="form-control" ng-model="request.Risk_Level" name="riskLevel" id="riskLevel" required/>
<span class="error" ng-show="requestEditForm.riskLevel.$error.required && requestEditForm.riskLevel.$dirty">Risk Level is required</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">CI Details:</label>
<div class="col-sm-3">
<input type="text" class="form-control" ng-model="request.Change_Initiator_id" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Requestor:</label>
<div class="col-sm-3">
<input type="text" class="form-control" ng-model="request.Requestor" />
</div>
<label class="col-sm-3 control-label">Systems Affected:</label>
<div class="col-sm-3">
<input type="text" class="form-control" ng-model="request.Systems_Affected" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Implemented By:</label>
<div class="col-sm-3">
<input type="text" class="form-control" ng-model="request.Implemented_By" />
</div>
<label class="col-sm-3 control-label">Implementation Date:</label>
<div class="col-sm-3">
<input type="text" class="form-control" ng-model="request.Implementation_Date" bs-datepicker/>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Close Date:</label>
<div class="col-sm-3">
<input type="text" class="form-control" ng-model="request.Close_Date" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Work to be Performed:</label>
<div class="col-sm-3">
<textarea name="request.description" ng-model="request.Work_to_be_performed"></textarea>
</div>
<label class="col-sm-3 control-label">Backout Plan:</label>
<div class="col-sm-3">
<textarea name="request.description" ng-model="request.Backout_Plan"></textarea>
</div>
</div>
<div class="form-group">
<button class="submit">Save Edits</button>
<button class="approve" ng:click="approveRequest()">Approve</button>
</div>
</form>
<div class="form-group">
<a href="#/requests" class="btn btn-default pull-right">
<span class="glyphicon glyphicon-arrow-left"></span> Back
</a>
</div>
</div>