Dynamic form inputs added using JavaScript validation in Laravel? - php

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

Related

How to give a friendly error message inside a modal with Bootstrap form?

How do I give an error message inside modal after clicking update?
In my example here I gave a required attribute on the input field.
I want to change the error message based on Form Validation Best Practices.
(This code is part of CRUD PHP file for updating data in a table I had)
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Edit Data</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form id="form-update" action="proses_edit.php" name="modal_popup" enctype="multipart/form-data" method="POST">
<div class="form-group" style="padding-bottom: 20px;">
<label for="Name">Name</label>
<input type="hidden" name="modal_id" id="edit-id" class="form-control" value="<?php echo $r['modal_id']; ?>"/>
<input type="text" name="modal_name" id="edit-name" class="form-control" value="<?php echo $r['modal_name']; ?>" required />
</div>
<div class="form-group" style="padding-bottom: 20px;">
<label for="Description">Age</label>
<input type="text" id="edit-description" class="form-control" value="<?php echo $r['description']; ?>" required />
</div>
<div class="modal-footer">
<button class="btn btn-success" type="submit">
Update
</button>
<button type="reset" class="btn btn-danger" data-dismiss="modal" aria-hidden="true">
Cancel
</button>
</div>
</form>
</div>
</div>
</div>
Here’s how form validation works with Bootstrap, taken from the documentation:
HTML form validation is applied via CSS’s two pseudo-classes, :invalid and :valid. It applies to <input>, <select>, and <textarea> elements.
Bootstrap scopes the :invalid and :valid styles to parent .was-validated class, usually applied to the <form>. Otherwise, any required field without a value shows up as invalid on page load. This way, you may choose when to activate them (typically after form submission is attempted).
As a fallback, .is-invalid and .is-valid classes may be used instead of the pseudo-classes for server side validation. They do not require a .was-validated parent class.
To achieve somewhat of what you're trying to do, taken from the example here you can use custom styles and create tooltips for each input and display a response based on the validation result. You will need to add the novalidate property to your <form> in order to prevent the default browser validation for this to work.
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form class="needs-validation" novalidate>
<div class="form-row">
<div class="col-md-4 mb-3">
<label for="validationCustom01">First name</label>
<input type="text" class="form-control" id="validationCustom01" placeholder="First name" value="Mark" required>
<div class="valid-feedback">
Looks good!
</div>
</div>
<div class="col-md-4 mb-3">
<label for="validationCustom02">Last name</label>
<input type="text" class="form-control" id="validationCustom02" placeholder="Last name" value="Otto" required>
<div class="valid-feedback">
Looks good!
</div>
</div>
<div class="col-md-4 mb-3">
<label for="validationCustomUsername">Username</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text" id="inputGroupPrepend">#</span>
</div>
<input type="text" class="form-control" id="validationCustomUsername" placeholder="Username" aria-describedby="inputGroupPrepend" required>
<div class="invalid-feedback">
Please choose a username.
</div>
</div>
</div>
</div>
<div class="form-row">
<div class="col-md-6 mb-3">
<label for="validationCustom03">City</label>
<input type="text" class="form-control" id="validationCustom03" placeholder="City" required>
<div class="invalid-feedback">
Please provide a valid city.
</div>
</div>
<div class="col-md-3 mb-3">
<label for="validationCustom04">State</label>
<input type="text" class="form-control" id="validationCustom04" placeholder="State" required>
<div class="invalid-feedback">
Please provide a valid state.
</div>
</div>
<div class="col-md-3 mb-3">
<label for="validationCustom05">Zip</label>
<input type="text" class="form-control" id="validationCustom05" placeholder="Zip" required>
<div class="invalid-feedback">
Please provide a valid zip.
</div>
</div>
</div>
<div class="form-group">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="invalidCheck" required>
<label class="form-check-label" for="invalidCheck">
Agree to terms and conditions
</label>
<div class="invalid-feedback">
You must agree before submitting.
</div>
</div>
</div>
<button class="btn btn-primary" type="submit">Submit form</button>
</form>
<script>
// Example starter JavaScript for disabling form submissions if there are invalid fields
(function() {
'use strict';
window.addEventListener('load', function() {
// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.getElementsByClassName('needs-validation');
// Loop over them and prevent submission
var validation = Array.prototype.filter.call(forms, function(form) {
form.addEventListener('submit', function(event) {
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();
}
form.classList.add('was-validated');
}, false);
});
}, false);
})();
</script>
More information on Bootstrap Validation: https://getbootstrap.com/docs/4.0/components/forms/#validation

I can't get data using id

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

pass value with a link and use it in php

I am learning PHP and trying to make one admin panel. I have a link like below in my table.
<i class="icon-eye"></i>
when clicking on the above link icon, it's opening one modal form, in that form I want to show all details of user of that row id from the table. I have my modal code and PHP code like below
<div id="modal_form_vertical" class="modal fade" tabindex="-1">
<?php
$users1_qry="SELECT * FROM users WHERE id = 1";
$result1=mysqli_query($mysqli,$users1_qry);
$row1=mysqli_fetch_assoc($result1);
?>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header bg-primary">
<h5 class="modal-title">More Details</h5>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<form action="#">
<div class="modal-body">
<div class="form-group">
<div class="row">
<div class="col-sm-6">
<label>Username</label>
<input type="text" value = "<?php echo $row1['username'];?>" class="form-control" disabled>
</div>
<div class="col-sm-6">
<label>Email</label>
<input type="text" value = "<?php echo $row1['email'];?>" class="form-control" disabled>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-6">
<label>Full Name</label>
<input type="text" value = "<?php echo $row1['name'];?>" class="form-control" disabled>
</div>
<div class="col-sm-6">
<label>Address</label>
<input type="text" value = "<?php echo $row1['address'];?>" class="form-control" disabled>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-6">
<label>Phone</label>
<input type="text" value = "<?php echo $row1['phone'];?>" class="form-control" disabled>
</div>
<div class="col-sm-6">
<label>Pin</label>
<input type="text" value = "<?php echo $row1['pin'];?>" class="form-control" disabled>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-6">
<label>Gender</label>
<input type="text" value = "<?php if($row1['gender'] ==0){echo 'Male';} else{echo 'Female';};?>" class="form-control" disabled>
</div>
<div class="col-sm-6">
<label>Occupation</label>
<input type="text" value = "<?php if($row1['occupation'] ==0){echo 'Parent';} else{echo 'Teacher';};?>" class="form-control" disabled>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-6">
<label>Corporation Id</label>
<input type="text" value = "<?php echo $row1['corp'];?>" class="form-control" disabled>
</div>
<div class="col-sm-6">
<label>Password</label>
<input type="text" value = "<?php echo $row1['password'];?>" class="form-control" disabled>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-link" data-dismiss="modal">Close</button>
</div>
</form>
</div>
</div>
</div>
You can see currently I have used 1 as user id in my mysqli query because I don't know how I can I pass row id to this modal class and so I can retrieve and use it. Let me know if someone can help me for same.
Thanks
You can send the ID by using POST or GET method, save it in the variable in your script and then use in the sql query.
Example:
<?php
$id = $_POST['id'];
$users1_qry="SELECT * FROM users WHERE id =".$id;
$result1=mysqli_query($mysqli,$users1_qry);
$row1=mysqli_fetch_assoc($result1);
?>
Consider using prepare/execute method so that you prevent possible SQL injections.
https://www.php.net/manual/en/pdo.prepare.php

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'];

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