I want to generate a password for users when creating an account using vue components. However when I check the box it doesn't disabled the password input field.
Here is my code:
create.blade.php
#extends('layouts.manage')
#section('content')
<div class="flex-container">
<div class="columns m-t-10">
<div class="column">
<h1 class="title">Create New Users User</h1>
</div>
</div>
<hr class="m-t-0">
<div class="columns">
<div class="column">
<form action="{{ route('users.store') }}" method="POST">
<div class="field">
<label for="name" class="label">Name</label>
<p class="control">
<input type="text" class="input" name="name" id="name">
</p>
</div>
<div class="field">
<label for="email" class="label">Email</label>
<p class="control">
<input type="email" class="input" name="email" id="email">
</p>
</div>
<div class="field">
<label for="password" class="label">Password</label>
<p class="control">
<input type="password" class="input" name="password" id="password" v-if="!auto_password" placeholder="Manually input a password">
<b-checkbox name="auto_generate" class="m-t-15" v-model="auto_password">Auto Generate Password</b-checkbox>
</p>
</div>
<button class="button is-success">Create User</button>
</form>
</div>
</div>
</div>
#endsection
#section('scripts')
<script>
var app = new Vue({
el: '#app',
data: {
auto_password: true
}
});
</script>
#endsection
looking for help.
Thanks in advance.
Related
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>
I have following code tried out.
class Vendor extends CI_Controller{
function __construct(){
parent::__construct();
}
public function vendor_add(){
$this->load->helper('url');
$this->load->view('header');
$this->load->view('sidebar');
$this->load->view('add_vendor');
$this->load->view('footer');
}
public function save(){
$this->load->helper(array('form','url'));
$this->load->model('Save_vendor');
$vendor_data = array(
'ven_name'=> $this->input->post['firstName'],
'ven_shop'=>$this->input->post['companyName'],
'ven_email_id'=>$this->input->post['email'],
'ven_contactno'=>$this->input->post['contactno'],
'ven_othercontactno'=>$this->input->post['contactno2'],
'ven_commission'=>$this->input->post['assigncommission'],
'ven_accname'=>$this->input->post['bankaccname'],
'ven_accountno'=>$this->input->post['bankaccno'],
'ven_ifsccode'=>$this->input->post['ifsccode'],
'ven_type'=>$this->input->post['optionsRadios']
);
$this->Save_vendor->vendor_insertdata($vendor_data);
redirect(base_url().'/vendor/vendor_add');
}
}
/* Model File */
class Save_vendor extends CI_Model{
public function vendor_insertdata($vendor_data){
$this->db->insert('tbl_vendor',$vendor_data);
}
/* VIew FIle */
<!-- BEGIN CONTENT -->
<div class="page-content-wrapper">
<div class="page-content">
<!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->
<!-- BEGIN PAGE HEADER-->
<h3 class="page-title">
Add Vendor <small> Add New Vendor</small>
</h3>
<div class="row">
<div class="col-md-12">
<div class="portlet-body form">
<?php echo base_url();?>
<!-- BEGIN FORM-->
<form action="<?php echo base_url("index.php/Vendor/save") ?>" class="horizontal-form" method="post">
<div class="form-body">
<h3 class="form-section">Add Vendor</h3>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<div class="radio-list">
<label class="radio-inline">
<input type="radio" name="optionsRadios" id="1" value="1" checked> Shop Vendor </label>
<label class="radio-inline">
<input type="radio" name="optionsRadios" id="2" value="2"> Vendor </label>
</div>
</div>
</div>
<!--/span-->
<div class="col-md-4">
<div class="form-group">
<label class="control-label">Vendor Name<span class="required">*</span></label>
<input type="text" id="firstName" class="form-control" name="firstName">
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label">Company/Shop/Business Name<span class="required">*</span></label>
<input type="text" id="companyName" class="form-control" name="companyName" >
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="control-label">Email Id<span class="required">*</span></label>
<input type="text" id="email" class="form-control" name="email">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="control-label">Contact No<span class="required">*</span></label>
<input type="text" id="firstName" class="form-control" name="contactno" >
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="control-label">2nd Contact No</label>
<input type="text" id="firstName" class="form-control" name="contactno2">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="control-label">PIN Code<span class="required">*</span></label>
<input type="text" id="pincode" class="form-control" name="pincode" >
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="control-label">Assign Commision %<span class="required">*</span></label>
<input type="text" id="assigncommission" class="form-control" name="assigncommission">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="control-label">BANK Account Name<span class="required">*</span></label>
<input type="text" id="firstName" class="form-control" name="bankaccname" >
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="control-label">Account Number<span class="required">*</span></label>
<input type="text" id="bankaccno" class="form-control" name="bankaccno" >
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label class="control-label">IFSC Code<span class="required">*</span></label>
<input type="text" id="ifsccode" class="form-control" name="ifsccode">
</div>
</div>
</div>
<div class="form-actions right">
<button type="submit" class="btn yellow-crusta"> Add Vendor</button>
</div>
</form>
</div>
</div>
</div>
<!-- END CONTENT -->
</div>
<!-- END CONTAINER -->
Above code but it will give an error Database error occured. Column name not be null. I am beginner in codeigniter please any suggestions for it.
I want to add data in my database.but it is not working.
Check your table "tbl_vendor" in which you are inserting values. One or more field is defined as NOT NULL means it will not accept empty value. You have to pass value to that field which is marked as NOT NULL.
Please read Codeigniter Query Builder reference first. You're making big mistakes. Your code should be like below:
$vendor_data = array(
'ven_name'=> $this->input->post['firstName'],
'ven_shop'=>$this->input->post['companyName'],
'ven_email_id'=>$this->input->post['email'],
'ven_contactno'=>$this->input->post['contactno'],
'ven_othercontactno'=>$this->input->post['contactno2'],
'ven_commission'=>$this->input->post['assigncommission'],
'ven_accname'=>$this->input->post['bankaccname'],
'ven_accountno'=>$this->input->post['bankaccno'],
'ven_ifsccode'=>$this->input->post['ifsccode'],
'ven_type'=>$this->input->post['optionsRadios']
);
$this->db->insert('your_table_name', $vendor_data);
When i post a Message from my web page it returns a ? in the browser such as this,
I believe both the HTML and the php to be correct
The html......
`enter code here`
<form class="form-horizontal">
<fieldset>
<div class="form-group is-empty">
<label for="Name" class="col-md-2 control- label">Name</label>
<div class="col-md-10">
<input type="text" class="form-control" id="Name" placeholder="Name">
</div>
</div>
<div class="form-group is-empty">
<label for="Email" class="col-md-2 control-label">Email</label>
<div class="col-md-10">
<input type="email" class="form-control" id="Email" placeholder="Email">
</div>
</div>
<div class="form-group is-empty">
<label for="Message" class="col-md-2 control-label">Message</label>
<div class="col-md-10">
<input type="text" class="form-control" id="Message" placeholder="Message">
</div>
</div>
<div class="form-group">
<form action="sendcontact.php" method="post">
<div class="col-md-10 col-md-offset-2">
<button type="submit">Send Message</button>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</section>
enter code here
you have declare form method and its action in form tag. Something like as follows
<form action="actionPage.php" method="POST"> //you can send data in get method or post method
Hope this will work for you...
action="yourLoctionUrl" tell the form where to submit data.
if you will do it empty then it will show ?yourinput fields&other inputs
<form action="sendcontact.php" method="post" class="form-horizontal">
<fieldset>
<div class="form-group is-empty">
<label for="Name" class="col-md-2 control- label">Name</label>
<div class="col-md-10">
<input type="text" class="form-control" id="Name" placeholder="Name">
</div>
</div>
<div class="form-group is-empty">
<label for="Email" class="col-md-2 control-label">Email</label>
<div class="col-md-10">
<input type="email" class="form-control" id="Email" placeholder="Email">
</div>
</div>
<div class="form-group is-empty">
<label for="Message" class="col-md-2 control-label">Message</label>
<div class="col-md-10">
<input type="text" class="form-control" id="Message" placeholder="Message">
</div>
</div>
<div class="form-group">
<div class="col-md-10 col-md-offset-2">
<button type="submit">Send Message</button>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
You have used form tag twice in your coding. put your action and post in starting form tag as i did.
You didn't close the second form tag. Go for this:
<form action="sendcontact.php" method="post">
<div class="col-md-10 col-md-offset-2">
<button type="submit">Send Message</button>
</div>
</form>
I'm trying to hide the regular content and display a thank you message in it's place after a form is sent. However when the form sends, the fields reset but the thank you message won't appear. Please help. I'm not that great with jQuery.
I'm also using the foundation abide.js, don't know if that makes difference or not.
Here is the ajax code.
$(function() {
// Get the form.
var form = $('#form');
// Get the messages div.
var formMessages = $('#thanks');
// Set up an event listener for the contact form.
$(form).submit(function(event) {
// Stop the browser from submitting the form.
event.preventDefault();
var formData = $(form).serialize();
$.ajax({
type: 'POST',
url: $(form).attr('action'),
data: formData
}).done(function(response) {
$('#thanks').show();
$(form).hide();
// Clear the form.
$('#name').val('');
$('#email').val('');
$('#number').val('');
})
});
});
This is the code for the form.
<div class="newsletter" id="contact">
<div class="row footer-top">
<div class="large-12 medium-12 columns updates" id="thanks" style="display: none;">
<h4>Thanks! We'll be in touch shortly.</h4>
</div>
<div class=" large-12 medium-12 column updates" id="normal">
<h4>Want more info? Contact us!</h4>
<p>Sign up to stay in touch with what's happening. Don't Worry, we don't spam.</p>
</div>
</div>
<form data-abide id="form" method="post" action="wp-content/themes/myles_custom/mailer.php">
<div class="row">
<div class="large-8 large-centered columns">
<label>
Name:
<input type="text" name="name" id="name" placeholder="Name" value="<?php if(isset($name)){echo htmlspecialchars($name);} ?>" required pattern="[a-zA-Z]+">
</label>
<small class="error">Name is required.</small>
</div>
</div>
<div class="row">
<div class="large-8 large-centered columns">
<label>
Email:
<input type="email" id="email" name="email" placeholder="Email" value="<?php if(isset($email)){echo htmlspecialchars($email);} ?>" required>
</label>
<small class="error">Email is required</small>
</div>
</div>
<div class="row">
<div class="large-8 large-centered columns">
<label>
Number:
<input type="tel" pattern="number" id="number" name="number" placeholder="Name" value="<?php if(isset($number)){echo htmlspecialchars($number);} ?>" required>
</label>
<small class="error">Number is required</small>
</div>
</div>
<div class="row">
<div class="large-8 large-centered columns">
<label>
Campus:
<select id="campus" name="campus">
<option>FSU</option>
<option>FAMU</option>
<option>TCC</option>
</select>
</label>
<small class="error">Campus is required</small>
</div>
</div>
<div id="sucks" style="display: none;">
<label for="address" id="adress_label" style: "display: none;">Address</label>
<input name="address" id="address" type="text" style="display: none;">
</div>
<div class="row">
<div class="large-12 columns" style="text-align: center;">
<button id="submit" type="submit" value="Send">Submit</button>
</div>
</div>
</form>
</div>
You have a extra closing bracket in the code, and I also would not use $(form) with jquery instead use an id reference $("#form").
I made a quick working example at https://jsfiddle.net/mum1m1sc/
$("#myForm").submit(function(event) {
// Stop the browser from submitting the form.
event.preventDefault();
var formData = $("#myForm").serialize();
$.ajax({
type: 'POST',
url: $("#myForm").attr('action'),
data: formData
}).done(function(response) {
$('#thanks').show();
$("#myForm").hide();
// Clear the form.
$('#name').val('');
$('#email').val('');
$('#number').val('');
});
});
<div class="newsletter" id="contact">
<div class="row footer-top">
<div class="large-12 medium-12 columns updates" id="thanks" style="display: none;">
<h4>Thanks! We'll be in touch shortly.</h4>
</div>
<div class=" large-12 medium-12 column updates" id="normal">
<h4>Want more info? Contact us!</h4>
<p>Sign up to stay in touch with what's happening. Don't Worry, we don't spam.</p>
</div>
</div>
<form data-abide id="myForm" method="post" action="">
<div class="row">
<div class="large-8 large-centered columns">
<label>
Name:
<input type="text" name="name" id="name" placeholder="Name" value="" required pattern="[a-zA-Z]+">
</label>
<small class="error">Name is required.</small>
</div>
</div>
<div class="row">
<div class="large-8 large-centered columns">
<label>
Email:
<input type="email" id="email" name="email" placeholder="Email" value="" required>
</label>
<small class="error">Email is required</small>
</div>
</div>
<div class="row">
<div class="large-8 large-centered columns">
<label>
Number:
<input type="tel" id="number" name="number" placeholder="Name" value="">
</label>
<small class="error">Number is required</small>
</div>
</div>
<div class="row">
<div class="large-8 large-centered columns">
<label>
Campus:
<select id="campus" name="campus">
<option>FSU</option>
<option>FAMU</option>
<option>TCC</option>
</select>
</label>
<small class="error">Campus is required</small>
</div>
</div>
<div id="sucks" style="display: none;">
<label for="address" id="adress_label" style: "display: none;">Address</label>
<input name="address" id="address" type="text" style="display: none;">
</div>
<div class="row">
<div class="large-12 columns" style="text-align: center;">
<button id="submit" type="submit" value="Send">Submit</button>
</div>
</div>
</form>
<div id="thanks" style="display:none;">
<h3>Thanks</h3>
</div>
hope that helps.
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>