I can't get data using id - php

I can't get data with id it returns this: %7Bid%7D.
I want to get the id and edit the data.
Controller:
public function edit($id){
$slider = DB::table('header_sliders')->find($id);
return view('posts.edit',['header'=>$slider]);
}
View:
<div class="container">
<div class="row">
<div class="col-md-12">
<form action="{{url('admin/edit')}}" method="POST" >
{{csrf_field()}
<div class="form-group">
<label for="exampleInputEmail1">Mətn</label>
<input type="text" name="text" class="form-control" aria-describedby="emailHelp" value="{{$header->text}}">
<small id="emailHelp" class="form-text text-muted"></small>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Şəkil</label>
<input type="file" name="imgName" class="form-control" value="{{$header->imgName}}">
</div>
<div class="form-check">
</div>
<button type="submit" class="btn btn-primary">Dəyiş</button>
<a href="{{url('admin/edit/{id}')}}" class="edit" data-toggle="modal"><i
class="material-icons" data-toggle="tooltip" title="Edit"></i></a>

Create a Route like this
Route::get('/admin/edit/{id}','UserController#edit');
and pass the id with your URL like this
YourURL..../admin/edit/11
This will solve your problem

Related

Dynamic form inputs added using JavaScript validation in Laravel?

I have some input fields in a form. Which can be added dynamically using javascript. For example, if click 'Add another Post Graduation' button, again a div is added like below with all the inputs field.
<div class="shadow p-4 border mb-5 postgraduation-div">
<span class="bg-dark text-white py-1 px-3 my-board-name">Post Graduation</span>
<div class="form-check">
<input class="form-check-input" name="pg_checkbox[]" value="pg_checked" type="checkbox">
<label class="form-check-label"> Enable </label>
</div>
<div class="row">
<div class="col">
<div class="form-group">
<label for="employee-name">University: </label>
<input type="text" class="form-control" name="pg_university[]">
</div>
</div>
<div class="col">
<div class="form-group">
<label for="exampleInputEmail1">Passing Year: </label>
<input type="text" class="form-control" name="pg_passing_year[]">
</div>
</div>
<div class="col">
<div class="form-group">
<label for="exampleInputEmail1">Percentage: </label>
<input type="text" class="form-control" name="pg_percentage[]">
</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="form-group">
<label for="exampleInputEmail1">Degree: </label>
<input type="text" class="form-control" name="pg_degree[]">
</div>
</div>
<div class="col">
<div class="form-group">
<label for="exampleInputEmail1">Subject: </label>
<input type="text" class="form-control" name="pg_subject[]">
</div>
</div>
</div>
<div class="text-center">
<span class="btn btn-outline-dark btn-sm add-pg-btn"><i class="fas fa-plus"></i> Add another Post Graduation</span>
</div>
</div>
First I have to check if the checkbox is checked or not. If checked, the input fields should be validated. I am able to save the data using the below code in my controller:
if(request('pg_checkbox')){
$pg_checkbox_count = count(request('pg_checkbox'));
for($i=0; $i<$pg_checkbox_count; $i++){
if(request('pg_checkbox')[$i] == 'pg_checked'){
$postgraduation_data = new Postgraduation_data;
$postgraduation_data->user_id = $user_id;
$postgraduation_data->university = request('pg_university')[$i];
$postgraduation_data->passing_year = request('pg_passing_year')[$i];
$postgraduation_data->percentage = request('pg_percentage')[$i];
$postgraduation_data->subject = request('pg_subject')[$i];
$postgraduation_data->degree = request('pg_degree')[$i];
$postgraduation_data->save();
}
}
}
But I am not able to validate these inputs in my custom request class:
$rules = [];
if(request('pg_checkbox')){
$pg_checkbox_count = count(request('pg_checkbox'));
for($i=0; $i<$pg_checkbox_count; $i++){
if( request('pg_checkbox')[$i] == 'pg_checked'){
$rules['pg_university'.$i] = 'required';
$rules['pg_passing_year'.$i] = 'required | digits:4';
}
}
}
return $rules;
There are different ways to do this.
The simplest way to use class validator is to enter and use information inside the attribute of each class.
enter image description here
{{--Name--}}
<label for="name" class="required_field">{{ __( 'articles.ArticleName' ) }}</label>
<input type="text" id="name"
name="name"
maxlength="30"
class="validate[required,maxSize[30]] form-control"
title="{{ __( 'articles.CreateTitleName' ) }}">
add this script in javascript section:
<script type="text/javascript" charset="utf-8">
$(document).ready(function () {
$("#create_article_form").validationEngine();
});
</script>
Download the validator file from this link below and use it in your project.
https://github.com/posabsolute/jQuery-Validation-Engine/blob/master/README.md

One form is working while other form is not working in laravel 5.4

I've UserController in which I've two options -
1) For Updating Profile
2) For Updating Password
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use App\User;
use Auth;
use Hash;
class UserController extends Controller
{
public function profile(){
return view('profile', array('user' => Auth::user()));
}
public function update_avatar(Request $request){
if(isset($request->avatar) && $request->avatar->getClientOriginalName()){
$ext = $request->avatar->getClientOriginalExtension();
$file = date('YmdHis').rand(1,99999).'.'.$ext;
$request->avatar->storeAs('public/avatar',$file);
}
else
{
$user = Auth::user();
if(!$user->avatar)
$file = '';
else
$file = $user->avatar;
}
$user = Auth::user();
$user->avatar = $file;
$user->name = $request->name;
$user->email = $request->email;
$user->mb_number = $request->mb_number;
$user->home_town = $request->home_town;
$user->save();
return view('profile', array('user' => Auth::user()));
}
public function update_password(Request $request){
$user = Auth::user();
if(Hash::check(Input::get('old_password'), $user['password']) && Input::get('new_password') == Input::get('confirm_new_password')){
$user->password = bcrypt(Input::get('new_password'));
$user->save();
}
return view('profile', array('user' => Auth::user()));
}
}
In my view blade, I've two forms -
update_avatar for updating profile like name, phone number and avatar.
update_password for updating password.
</div>
<div class="widget-user-image">
<img class="img-circle" src="{{ asset('public/storage/avatar/'.$user->avatar) }}" alt="User Avatar">
</div>
<div class="box-footer">
<div class="row">
<div class="col-sm-4 border-right">
<div class="description-block">
<h5 class="description-header">{{ $user->email }}</h5>
<span class="description-text">Email</span>
</div>
<!-- /.description-block -->
</div>
<!-- /.col -->
<div class="col-sm-4 border-right">
<div class="description-block">
<h5 class="description-header">{{ $user->name }}</h5>
<span class="description-text">{{ $user->home_town }}</span>
</div>
<!-- /.description-block -->
</div>
<!-- /.col -->
<div class="col-sm-4">
<div class="description-block">
<h5 class="description-header">{{ $user->mb_number }}</h5>
<span class="description-text">Phone No.</span>
</div>
<!-- /.description-block -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</div>
<!--
<div class="box-footer no-padding">
<ul class="nav nav-stacked">
<li>Projects <span class="pull-right badge bg-blue">31</span></li>
<li>Tasks <span class="pull-right badge bg-aqua">5</span></li>
<li>Completed Projects <span class="pull-right badge bg-green">12</span></li>
<li>Followers <span class="pull-right badge bg-red">842</span></li>
</ul>
</div>
-->
</div>
</div>
<section class="content">
<div class="container-fluid">
<form action="/profile" enctype="multipart/form-data" method="POST">
<div class="form-group">
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" class="form-control" id="name" placeholder="Title" value="{{$user->name}}">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="text" name="email" class="form-control" id="email" placeholder="Description" value="{{$user->email}}" readonly>
</div>
<div class="form-group">
<label for="mb_number">Mobile No.</label>
<input type="text" name="mb_number" class="form-control" id="mb_number" placeholder="Schedule" value="{{$user->mb_number}}">
</div>
<div class="form-group">
<label for="home_town">Home Town</label>
<input type="text" name="home_town" class="form-control" id="home_town" placeholder="Deadline" value="{{$user->home_town}}">
</div>
<div class="form-group">
<label>Update Profile Image</label>
<input type="file" name="avatar">
#if($user->avatar)
<img src="{{ asset('public/storage/avatar/'.$user->avatar) }}" style="width:150px;">
#endif
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}"
<button type="submit" class="btn btn-primary">Update</button>
</div>
</div>
</section>
<section class="content">
<div class="container-fluid">
<form action="/profile" enctype="multipart/form-data" method="POST">
<div class="form-group">
<div class="form-group">
<label for="old_password">Old Password</label>
<input type="password" name="old_password" class="form-control" id="old_password" placeholder="Old Password">
</div>
<div class="form-group">
<label for="new_password">New Password</label>
<input type="password" name="new_password" class="form-control" id="new_password" placeholder="New Password">
</div>
<div class="form-group">
<label for="confirm_new_password">Confirm New Password </label>
<input type="password" name="confirm_new_password" class="form-control" id="confirm_new_password" placeholder="Confirm New Password">
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}"
<button type="submit" class="btn btn-primary">Update Password</button>
</div>
</div>
</section>
update_password function is working fine but update_avatar function is not working neither it's showing any error. I've tried dd($user) but still not giving output to dd.
Check this out i updated form a bit with indentation and proper closing, also please redirect profile avatar to different URL so that it can access different method :-
I would suggest you to use https://laravelcollective.com/docs/5.4/html , by using form collective it would be much more easier to implement more complex form structure.
In Route,
Route::post('/profile_avatar',"UserController#update_avatar");
Route::post('/profile_password',"UserController#update_password");
In Blade,
<section class="content">
<div class="container-fluid">
<form action="/profile_avatar" enctype="multipart/form-data" method="POST">
<div class="form-group">
<div class="form-group">
<label for="name">
Name
</label>
<input class="form-control" id="name" name="name" placeholder="Title" type="text" value="{{$user->name}}">
</input>
</div>
<div class="form-group">
<label for="email">
Email
</label>
<input class="form-control" id="email" name="email" placeholder="Description" readonly="" type="text" value="{{$user->email}}">
</input>
</div>
<div class="form-group">
<label for="mb_number">
Mobile No.
</label>
<input class="form-control" id="mb_number" name="mb_number" placeholder="Schedule" type="text" value="{{$user->mb_number}}">
</input>
</div>
<div class="form-group">
<label for="home_town">
Home Town
</label>
<input class="form-control" id="home_town" name="home_town" placeholder="Deadline" type="text" value="{{$user->home_town}}">
</input>
</div>
<div class="form-group">
<label>
Update Profile Image
</label>
<input name="avatar" type="file">
#if($user->avatar)
<img src="{{ asset('public/storage/avatar/'.$user->avatar) }}" style="width:150px;">
#endif
</img>
</input>
</div>
<input <a="" class="btn btn-info" href="" name="_token" type="submit" value="{{ csrf_token() }}"/>
</div>
<button class="btn btn-primary" type="submit">
Update
</button>
</form>
</div>
</section>
<section class="content">
<div class="container-fluid">
<form action="/profile_password" enctype="multipart/form-data" method="POST">
<div class="form-group">
<div class="form-group">
<label for="old_password">
Old Password
</label>
<input class="form-control" id="old_password" name="old_password" placeholder="Old Password" type="password">
</input>
</div>
<div class="form-group">
<label for="new_password">
New Password
</label>
<input class="form-control" id="new_password" name="new_password" placeholder="New Password" type="password">
</input>
</div>
<div class="form-group">
<label for="confirm_new_password">
Confirm New Password
</label>
<input class="form-control" id="confirm_new_password" name="confirm_new_password" placeholder="Confirm New Password" type="password">
</input>
</div>
<input <a="" class="btn btn-info" href="" name="_token" type="submit" value="{{ csrf_token() }}"/>
</div>
<button class="btn btn-primary" type="submit">
Update Password
</button>
</form>
</div>
</section>

How to use loop with array in laravel

I have a student registration form, when you enroll your'e child you fill up the form then inside the form has information about the father like name, occupation,email and etc.. then inside the form also you can put your'e child's name, age gender etc .. now if you have multiple child you can click the + button to add another row for the second child then once you submit the form the two child you key-in will have the same father's information.
Question: how do i construct it into my Controller? and how do i loop the parent's information. Currently with my code i can only save array of child information i can't loop the father's information in each child.
Controller:
public function store(Request $request)
{
//dd($request->all());
$this->validate($request, [
'student_name.*'=>'required|max:50',
'age.*'=>'required|integer',
//Roles Goes Here
]);
$input = $request->all();
if (count($input['student_name']) > 0) {
for ($i = 0 ; $i < count($input['student_name']) ; $i++) {
$leads = new Lead();
$leads->student_name = $input['student_name'][$i];
$leads->gender = $input['gender'][$i];
$leads->age = $input['age'][$i];
$leads->father_name=$request->father_name;
$leads->father_contact1=$request->father_contact1;
$leads->father_email=$request->father_email;
$leads->father_occupation=$request>father_occupation;
$leads->father_religion=$request->father_religion;
$leads->save();
}
VIEW:
<form action="{{route('leads.store')}}" method="POST">
{{csrf_field()}}
<div class="col-sm-12">
<h3 class="well">Parent's Information</h3>
<div class="row">
<div class="col-sm-4 form-group">
<label>FATHER'S NAME</label>
<input class="form-control" id="txtuppercase1" type="text" name="father_name" value="{{old('father_name')}}" placeholder="Enter FATHER NAME.." >
</div>
<div class="col-sm-4 form-group">
<label>CONTACT</label>
<input type="text" id="txtuppercase2" name="father_contact1" value="{{old('father_contact1')}}" placeholder="Enter CONTACT.." class="form-control" >
</div>
<div class="col-sm-4 form-group">
<label>EMAIL ADDRESS</label>
<input type="text" name="father_email" value="{{old('father_email')}}" placeholder="Enter EMAIL ADDRESS.." class="form-control" >
</div>
<div class="col-sm-4 form-group">
<label>OCCUPATION</label>
<input type="text" name="father_occupation" value="{{old('father_occupation')}}" placeholder="Enter OCCUPATION.." class="form-control" >
</div>
<div class="col-sm-4 form-group">
<label>RELIGION</label>
<input type="text" name="father_religion" value="{{old('father_religion')}}" placeholder="Enter RELIGION.." class="form-control" >
</div>
</div>
<br>
<div class="row">
<div class="col-md-12">
<div data-role="dynamic-fields">
<div class="form-inline">
<div class="form-group">
<label class="sr-only" for="student_name">NAME</label>
<input type="text" class="form-control" id="student_name" name="student_name[]" placeholder="STUDENT NAME">
</div>
<span>-</span>
<div class="form-group">
<label class="sr-only" for="age">AGE</label>
<input type="text" class="form-control" id="age" name="age[]" placeholder="AGE">
</div>
<span>-</span>
<div class="form-group">
<label class="sr-only" for="gender">GENDER</label>
<input type="text" class="form-control" id="gender" name="gender[]" placeholder="GENDER">
</div>
<span>-</span>
<div class="form-group">
<label class="sr-only" for="school">SCHOOL</label>
<input type="text" class="form-control" id="last_school_attended" name="last_school_attended[]" placeholder="SCHOOL">
</div>
<button class="btn btn-danger" data-role="remove">
<span class="glyphicon glyphicon-remove"></span>
</button>
<button class="btn btn-primary" data-role="add">
<span class="glyphicon glyphicon-plus"></span>
</button>
</div> <!-- /div.form-inline -->
</div> <!-- /div[data-role="dynamic-fields"] -->
</div> <!-- /div.col-md-12 -->
</div> <!-- /div.row -->
<br>
<div>
<button type="submit" class="btn btn-success">SUBMIT</button>
CANCEL
</div>
</form>
You don't need to loop the parent's information. You can directly access the parent's information through $input['father_name'];

Show duplicate entry warning in laravel

how to display duplicate entry warning error to my view in laravel blade. so when they key in same name the warning will appear when they saved it.
Note: i have already make my Schema $table->string('studentname')->unique();;
Controller
public function store(Request $request)
{
$this->validate($request, [
'studentname'=>'required|max:50',
]);
$students = new Student();
$students->studentname = $request->studentname;
$students->address = $request->address;
$students->religion = $request->religion;
$students->save();
return redirect()->route('students.index')
->with('flash_message', 'Success.');
}
View-Blade
<div class="container">
<h1 class="well">Registration Form</h1>
<div class="col-lg-12 well">
<div class="row">
<form action="{{route('students.store')}}" method="POST">
{{csrf_field()}}
<div class="col-sm-12">
<h3>CHILD'S INFORMATION</h3>
<hr>
<div class="row">
<div class="col-sm-4 form-group">
<label>FULLNAME</label>
<input type="text" name="studentname" value="" placeholder="Enter FULLNAME.." class="form-control" required>
</div>
<div class="col-sm-4 form-group">
<label>RELIGION</label>
<input type="text" name="religion" value="" placeholder="Enter RELIGION.." class="form-control">
</div>
<div class="col-sm-4 form-group">
<label>ADDRESS</label>
<input type="text" name="address" value="" placeholder="Enter ADDRESS.." class="form-control">
</div>
<div>
<button type="submit" class="btn btn-default">SUBMIT</button>
</div>
</div>
</div>
</div>
Add the unique validation which returns a message if it fails.
$this->validate($request, [
'studentname'=>'required|max:50|unique:table_name,studentname',
]);
And then, in your blade template, do this.
<div class="col-sm-4 form-group {{ $errors->get('studentname') ? 'has-error' : '' }}">
<label>FULLNAME</label>
<input type="text" name="studentname" value="" placeholder="Enter FULLNAME.." class="form-control" required>
#foreach($errors->get('studentname') as $error)
<span class="help-block">{{ $error }}</span>
#endforeach
</div>

Populate ng-model - Value not working AngularJS

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>

Categories