How to display a null date in a Net Core view - asp.net-core-mvc

I have a model with date type properties that can be null
[Display(Name = "Vig. Conf.")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true, NullDisplayText = "-")]
public DateTime? VigenciaConfeccion
{
get => _vigenciaConfeccion;
set
{
if (_vigenciaConfeccion != value)
{
_vigenciaConfeccion = value;
OnPropertyChanged(nameof(VigenciaConfeccion));
}
}
}
This is the view that where the error is generated in the format of the three date labels.
#model WebProcesoTela.Models.VDiagramaDetailModel
#{
// ViewData["Title"] = "Details";
Layout = null;
}
<div class = "container-fluid">
<h2>Detalle del renglón</h2>
<hr/>
<div class="row">
<div class="col-sm-2">
<label asp-for="DiagramaId" class="control-label">#Html.DisplayNameFor(model => model.DiagramaId)</label>
<input asp-for="DiagramaId" class="form-control text-center" readonly disabled/>
</div>
<div class="col-sm-2">
<label asp-for="DiagramaDetailId" class="control-label">#Html.DisplayNameFor(model => model.DiagramaDetailId)</label>
<input asp-for="DiagramaDetailId" class="form-control text-center" readonly disabled/>
</div>
<div class="col-sm-4">
<label asp-for="CompradorName" class="control-label">#Html.DisplayNameFor(model => model.CompradorName)</label>
<input asp-for="CompradorName" class="form-control" readonly disabled/>
</div>
<div class="col-sm-2">
<label asp-for="ClaveLinea" class="control-label">#Html.DisplayNameFor(model => model.ClaveLinea)</label>
<input asp-for="ClaveLinea" class="form-control" readonly disabled/>
</div>
<div class="col-sm-2">
<label asp-for="VigenciaBonmoro" class="control-label">#Html.DisplayNameFor(model => model.VigenciaBonmoro)</label>
<input type="date" asp-for="VigenciaBonmoro" asp-format="{0:yyyy-MM-dd}" class="form-control" readonly disabled/>
</div>
</div>
<div class="row">
<div class="col-sm-2">
<label asp-for="VigenciaBannio" class="control-label">#Html.DisplayNameFor(model => model.VigenciaBannio)</label>
<input type="date" asp-for="VigenciaBannio" asp-format="{0:yyyy-MM-dd}" class="form-control" readonly disabled/>
</div>
<div class="col-sm-2">
<label asp-for="VigenciaConfeccion" class="control-label">#Html.DisplayNameFor(model => model.VigenciaConfeccion)</label>
<input type="date" asp-for="VigenciaConfeccion" asp-format="{0:yyyy-MM-dd}" class="form-control" readonly disabled/>
</div>
<div class="col-sm-8">
<label asp-for="ComentariosTejido" class="control-label">#Html.DisplayNameFor(model => model.ComentariosTejido)</label>
<input asp-for="ComentariosTejido" class="form-control" readonly disabled/>
</div>
</div>
<div class="row">
<div class="col-sm-2">
<label asp-for="FolioTejido" class="control-label">#Html.DisplayNameFor(model => model.FolioTejido)</label>
<input asp-for="FolioTejido" class="form-control" readonly disabled/>
</div>
<div class="col-sm-2">
<label asp-for="FolioTejedor" class="control-label">#Html.DisplayNameFor(model => model.FolioTejedor)</label>
<input asp-for="FolioTejedor" class="form-control" readonly disabled/>
</div>
<div class="col-sm-2">
<label asp-for="Bannio" class="control-label">#Html.DisplayNameFor(model => model.Bannio)</label>
<input asp-for="Bannio" class="form-control" readonly disabled/>
</div>
<div class="col-sm-3">
<label asp-for="TejedorName" class="control-label">#Html.DisplayNameFor(model => model.TejedorName)</label>
<input asp-for="TejedorName" class="form-control" readonly disabled/>
</div>
<div class="col-sm-3">
<label asp-for="AcabadorName" class="control-label">#Html.DisplayNameFor(model => model.AcabadorName)</label>
<input asp-for="AcabadorName" class="form-control" readonly disabled/>
</div>
</div>
<div class="row">
<div class="col-sm-4">
<label asp-for="DeptoCategoriaName" class="control-label">#Html.DisplayNameFor(model => model.DeptoCategoriaName)</label>
<input asp-for="DeptoCategoriaName" class="form-control" readonly disabled/>
</div>
<div class="col-sm-2">
<label asp-for="PedidoInterno" class="control-label">#Html.DisplayNameFor(model => model.PedidoInterno)</label>
<input asp-for="PedidoInterno" class="form-control" readonly disabled/>
</div>
<div class="col-sm-2">
<label asp-for="ModeloId" class="control-label">#Html.DisplayNameFor(model => model.ModeloId)</label>
<input asp-for="ModeloId" class="form-control" readonly disabled/>
</div>
<div class="col-sm-4">
<label asp-for="PiezaName" class="control-label">#Html.DisplayNameFor(model => model.PiezaName)</label>
<input asp-for="PiezaName" class="form-control" readonly disabled/>
</div>
</div>
<div class="row">
<div class="col-sm-2">
<label asp-for="Variante" class="control-label">#Html.DisplayNameFor(model => model.Variante)</label>
<input asp-for="Variante" class="form-control text-center" readonly disabled/>
</div>
<div class="col-sm-2">
<label asp-for="TipoFondoName" class="control-label">#Html.DisplayNameFor(model => model.TipoFondoName)</label>
<input asp-for="TipoFondoName" class="form-control" readonly disabled/>
</div>
<div class="col-sm-6">
<label asp-for="ColorName" class="control-label">#Html.DisplayNameFor(model => model.ColorName)</label>
<input asp-for="ColorName" class="form-control" readonly disabled/>
</div>
<div class="col-sm-2">
<label asp-for="CodigoColorProv" class="control-label">#Html.DisplayNameFor(model => model.CodigoColorProv)</label>
<input asp-for="CodigoColorProv" class="form-control" readonly disabled/>
</div>
</div>
<div class="row">
<div class="col-sm-3">
<label asp-for="TipoCuelloName" class="control-label">#Html.DisplayNameFor(model => model.TipoCuelloName)</label>
<input asp-for="TipoCuelloName" class="form-control" readonly disabled/>
</div>
<div class="col-sm-2">
<label asp-for="GpoCodigoTallaName" class="control-label">#Html.DisplayNameFor(model => model.GpoCodigoTallaName)</label>
<input asp-for="GpoCodigoTallaName" class="form-control" readonly disabled/>
</div>
<div class="col-sm-2">
<label asp-for="TotalPiezas" class="control-label">#Html.DisplayNameFor(model => model.TotalPiezas)</label>
<input type="text" asp-for="TotalPiezas" class="form-control" readonly disabled/>
</div>
<div class="col-sm-5">
<label asp-for="TelaNameDD" class="control-label">#Html.DisplayNameFor(model => model.TelaNameDD)</label>
<input asp-for="TelaNameDD" class="form-control" readonly disabled/>
</div>
</div>
<div class="row">
<div class="col-sm-2">
<label asp-for="EstampadoId" class="control-label">#Html.DisplayNameFor(model => model.EstampadoId)</label>
<input asp-for="EstampadoId" class="form-control" readonly disabled/>
</div>
<div class="col-sm-3">
<label asp-for="EstampadoName" class="control-label">#Html.DisplayNameFor(model => model.EstampadoName)</label>
<input asp-for="EstampadoName" class="form-control" readonly disabled/>
</div>
<div class="col-sm-7">
<label asp-for="EstampadoEspecificacion" class="control-label">#Html.DisplayNameFor(model => model.EstampadoEspecificacion)</label>
<input asp-for="EstampadoEspecificacion" class="form-control" readonly disabled/>
</div>
</div>
<div class="row">
<div class="col-sm-2">
<label asp-for="CodigoEstampado" class="control-label">#Html.DisplayNameFor(model => model.CodigoEstampado)</label>
<input asp-for="CodigoEstampado" class="form-control" readonly disabled/>
</div>
<div class="col-sm-3">
<label asp-for="HilanderoName" class="control-label">#Html.DisplayNameFor(model => model.HilanderoName)</label>
<input asp-for="HilanderoName" class="form-control" readonly disabled/>
</div>
<div class="col-sm-3">
<label asp-for="HiloNameDD" class="control-label">#Html.DisplayNameFor(model => model.HiloNameDD)</label>
<input asp-for="HiloNameDD" class="form-control" readonly disabled/>
</div>
<div class="col-sm-4">
<label asp-for="HiloComposicion" class="control-label">#Html.DisplayNameFor(model => model.HiloComposicion)</label>
<input asp-for="HiloComposicion" class="form-control" readonly disabled/>
</div>
</div>
<div class="row">
<div class="col-sm-2">
<label asp-for="HiloGrsMt2" class="control-label">#Html.DisplayNameFor(model => model.HiloGrsMt2)</label>
<input asp-for="HiloGrsMt2" class="form-control" readonly disabled/>
</div>
<div class="col-sm-3">
<label asp-for="TejidoEspecificacion" class="control-label">#Html.DisplayNameFor(model => model.TejidoEspecificacion)</label>
<input asp-for="TejidoEspecificacion" class="form-control" readonly disabled/>
</div>
<div class="col-sm-2">
<label asp-for="TelaAcabadoName" class="control-label">#Html.DisplayNameFor(model => model.TelaAcabadoName)</label>
<input asp-for="TelaAcabadoName" class="form-control" readonly disabled/>
</div>
<div class="col-sm-5">
<label asp-for="Nota" class="control-label">#Html.DisplayNameFor(model => model.Nota)</label>
<input asp-for="Nota" class="form-control" readonly disabled/>
</div>
</div>
<div class="row">
<div class="col-sm-2 offset-sm-6">
<label asp-for="TotalTelaKilos" class="control-label">#Html.DisplayNameFor(model => model.TotalTelaKilos)</label>
<input asp-for="TotalTelaKilos" class="form-control" readonly disabled/>
</div>
<div class="col-sm-2">
<label asp-for="TotalTelaMetros" class="control-label">#Html.DisplayNameFor(model => model.TotalTelaMetros)</label>
<input asp-for="TotalTelaMetros" class="form-control" readonly disabled/>
</div>
<div class="col-sm-2">
<label asp-for="TotalTelaKgsSinMerma" class="control-label">#Html.DisplayNameFor(model => model.TotalTelaKgsSinMerma)</label>
<input asp-for="TotalTelaKgsSinMerma" class="form-control" readonly disabled/>
</div>
</div>
<div class="row"></div>
</div>
<hr />
<div class="form-group">
<!-- Barra de Botones Details Modal -Regresar- -->
<partial name="~/Views/Shared/Controls/_BtnsDetailsModal.cshtml"/>
</div>
When I load the view and the date is null, the "Input tag" shows "dd/MM/yyyy"
The editor asks me to put more details, but I don't know what else to put, since the problem is very simple.
The "input" tags display "dd/mm/yyyy" when the field is null.
What can I do so that it doesn't show me anything?

I think you can try to change the style of the date input. Using onfocu and onblur action
<div class="form-group">
<label asp-for="VigenciaConfeccion" class="control-label"></label>
<input asp-for="VigenciaConfeccion" class="form-control" onfocus="(this.style.color='#000')" onblur="if(!this.value)this.style.color='transparent'" />
<span asp-validation-for="VigenciaConfeccion" class="text-danger"></span>
</div>
#section Scripts{
<script>
$("#VigenciaConfeccion").focus();
$("#VigenciaConfeccion").blur();
</script>
}

Related

In the contact creation I want to assign a customer or supplier from a dropdown

I have two problems.
1. Problem: When I add my selection to the razor page all required fields validation from the model do not work anymore.
Validation from model without selection
No Validation when I add my selection
When dropdown are in the Razor html no validation works and it crashes with NULL Values which I want to prevent. Like it is without select options.
Why is that?
2. Problem: When I select a customer from my drop down (CustomerDropDown.CusId) I would like to fill the ID into my ID field of contacts (contacts.CustomerId). How can I reach the selected value from dropdown and post it to my contact contacts.CustomerId?
== c# code ==
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Mvc.Rendering;
using WorkCollaboration.Data;
using WorkCollaboration.Models;
namespace WorkCollaboration.Pages.Contacts
{
public class CreateModel : PageModel
{
private readonly WorkCollaboration.Data.WorkCollaborationContext _context;
public CreateModel(WorkCollaboration.Data.WorkCollaborationContext context)
{
_context = context;
}
public async Task<IActionResult> OnGetAsync()
{
CustomerDropDownDisp = await _context.CustomerDropDown.ToListAsync(); // Added for DropDown
SupplierDropDownDisp = await _context.SupplierDropDown.ToListAsync(); // Added for DropDown
return Page();
}
[BindProperty]
public Contact Contact { get; set; }
public IEnumerable<CustomerDropDown> CustomerDropDownDisp { get; set; }
public IEnumerable<SupplierDropDown> SupplierDropDownDisp { get; set; }
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see https://aka.ms/RazorPagesCRUD.
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
_context.Contact.Add(Contact);
await _context.SaveChangesAsync();
return RedirectToPage("/ContactsOverview/Index");
}
}
}
== Razor Page Code ==
#page
#using WorkCollaboration.Models
#model WorkCollaboration.Pages.Contacts.CreateModel
#{
ViewData["Title"] = "Create";
ViewData["RandomId"] = Guid.NewGuid().GetHashCode();
}
<h1>Create</h1>
<h4>Contact</h4>
<p>
<a asp-page="/ContactsOverview/Index">Back to Index</a>
</p>
<hr />
<div class="row">
<div class="col-md-4">
<form method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Contact.ContactId" class="control-label"></label>
<input asp-for="Contact.ContactId" value='#ViewData["RandomId"]' readonly="readonly" class="form-control" />
<span asp-validation-for="Contact.ContactId" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.LastName" class="control-label"></label>
<input asp-for="Contact.LastName" class="form-control" />
<span asp-validation-for="Contact.LastName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.FirstName" class="control-label"></label>
<input asp-for="Contact.FirstName" class="form-control" />
<span asp-validation-for="Contact.FirstName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.CustomerId" class="control-label"></label>
</div>
<select id="CusId" asp-for="CustomerDropDownDisp" asp-items="#(new SelectList(Model.CustomerDropDownDisp,"CusId","CusName"))">
<option value="">--Choose Customer--</option>
<option value="1" selected>None</option>>
</select>
<div class="form-group">
<input asp-for="Contact.CustomerId" class="form-control" />
<span asp-validation-for="Contact.CustomerId" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.SupplierId" class="control-label"></label>
</div>
<select id="SupId" asp-for="SupplierDropDownDisp" asp-items="#(new SelectList(Model.SupplierDropDownDisp,"SupId","SupName"))">
<option value="">--Choose Supplier--</option>
<option value="1" selected>None</option>>
</select>
<div class="form-group">
<input asp-for="Contact.SupplierId" class="form-control" />
<span asp-validation-for="Contact.SupplierId" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.PrivateStreet" class="control-label"></label>
<input asp-for="Contact.PrivateStreet" class="form-control" />
<span asp-validation-for="Contact.PrivateStreet" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.PrivateStreetNo" class="control-label"></label>
<input asp-for="Contact.PrivateStreetNo" class="form-control" />
<span asp-validation-for="Contact.PrivateStreetNo" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.PrivateStreetAdditionalInfo" class="control-label"></label>
<input asp-for="Contact.PrivateStreetAdditionalInfo" class="form-control" />
<span asp-validation-for="Contact.PrivateStreetAdditionalInfo" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.PrivateZip" class="control-label"></label>
<input asp-for="Contact.PrivateZip" class="form-control" />
<span asp-validation-for="Contact.PrivateZip" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.PrivateTown" class="control-label"></label>
<input asp-for="Contact.PrivateTown" class="form-control" />
<span asp-validation-for="Contact.PrivateTown" class="text-danger"></span>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Contact.PrivateCountry, htmlAttributes: new { #class = "form-group" })
<div class="form-group">
#Html.DropDownListFor(model => model.Contact.PrivateCountry, new List<SelectListItem>
{
new SelectListItem {Text = "CH", Value = "CH", Selected = true },
new SelectListItem {Text = "D", Value = "D" },
new SelectListItem {Text = "FL", Value = "FL" },
}, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.Contact.PrivateCountry, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<label asp-for="Contact.PrivatePhone" class="control-label"></label>
<input asp-for="Contact.PrivatePhone" class="form-control" />
<span asp-validation-for="Contact.PrivatePhone" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.BusinessPhone" class="control-label"></label>
<input asp-for="Contact.BusinessPhone" class="form-control" />
<span asp-validation-for="Contact.BusinessPhone" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.MobilePhone" class="control-label"></label>
<input asp-for="Contact.MobilePhone" class="form-control" />
<span asp-validation-for="Contact.MobilePhone" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.Mail" class="control-label"></label>
<input asp-for="Contact.Mail" class="form-control" />
<span asp-validation-for="Contact.Mail" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
Back to List
</div>
</form>
</div>
</div>
Thank you for your help on how to get selected value (dropdown) to the corresponding contacts Id field.
Here is a demo:
<div class="row">
<div class="col-md-4">
<form method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Contact.ContactId" class="control-label"></label>
<input asp-for="Contact.ContactId" value='#ViewData["RandomId"]' readonly="readonly" class="form-control" />
<span asp-validation-for="Contact.ContactId" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.LastName" class="control-label"></label>
<input asp-for="Contact.LastName" class="form-control" />
<span asp-validation-for="Contact.LastName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.FirstName" class="control-label"></label>
<input asp-for="Contact.FirstName" class="form-control" />
<span asp-validation-for="Contact.FirstName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.CustomerId" class="control-label"></label>
</div>
<select id="CusId" asp-for="CustomerDropDownDisp" asp-items="#(new SelectList(Model.CustomerDropDownDisp,"CusId","CusName"))">
<option value="">--Choose Customer--</option>
<option value="1" selected>None</option>>
</select>
<div class="form-group">
<input asp-for="Contact.CustomerId" class="form-control" />
<span asp-validation-for="Contact.CustomerId" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.SupplierId" class="control-label"></label>
</div>
<select id="SupId" asp-for="SupplierDropDownDisp" asp-items="#(new SelectList(Model.SupplierDropDownDisp,"SupId","SupName"))">
<option value="">--Choose Supplier--</option>
<option value="1" selected>None</option>>
</select>
<div class="form-group">
<input asp-for="Contact.SupplierId" class="form-control" />
<span asp-validation-for="Contact.SupplierId" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.PrivateStreet" class="control-label"></label>
<input asp-for="Contact.PrivateStreet" class="form-control" />
<span asp-validation-for="Contact.PrivateStreet" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.PrivateStreetNo" class="control-label"></label>
<input asp-for="Contact.PrivateStreetNo" class="form-control" />
<span asp-validation-for="Contact.PrivateStreetNo" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.PrivateStreetAdditionalInfo" class="control-label"></label>
<input asp-for="Contact.PrivateStreetAdditionalInfo" class="form-control" />
<span asp-validation-for="Contact.PrivateStreetAdditionalInfo" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.PrivateZip" class="control-label"></label>
<input asp-for="Contact.PrivateZip" class="form-control" />
<span asp-validation-for="Contact.PrivateZip" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.PrivateTown" class="control-label"></label>
<input asp-for="Contact.PrivateTown" class="form-control" />
<span asp-validation-for="Contact.PrivateTown" class="text-danger"></span>
</div>
<div class="form-group">
#Html.LabelFor(model => model.Contact.PrivateCountry, htmlAttributes: new { #class = "form-group" })
<div class="form-group">
#Html.DropDownListFor(model => model.Contact.PrivateCountry, new List<SelectListItem>
{
new SelectListItem {Text = "CH", Value = "CH", Selected = true },
new SelectListItem {Text = "D", Value = "D" },
new SelectListItem {Text = "FL", Value = "FL" },
}, new { #class = "form-control" })
#Html.ValidationMessageFor(model => model.Contact.PrivateCountry, "", new { #class = "text-danger" })
</div>
</div>
<div class="form-group">
<label asp-for="Contact.PrivatePhone" class="control-label"></label>
<input asp-for="Contact.PrivatePhone" class="form-control" />
<span asp-validation-for="Contact.PrivatePhone" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.BusinessPhone" class="control-label"></label>
<input asp-for="Contact.BusinessPhone" class="form-control" />
<span asp-validation-for="Contact.BusinessPhone" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.MobilePhone" class="control-label"></label>
<input asp-for="Contact.MobilePhone" class="form-control" />
<span asp-validation-for="Contact.MobilePhone" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Contact.Mail" class="control-label"></label>
<input asp-for="Contact.Mail" class="form-control" />
<span asp-validation-for="Contact.Mail" class="text-danger"></span>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
Back to List
</div>
</form>
</div>
</div>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
<script>
$("#CusId").on("change", function () {
$("#Contact_CustomerId").val($("#SupId").val());
});
$("#SupId").on("change", function () {
$("#Contact_SupplierId").val($("#SupId").val());
});
</script>
result:

How to solve this error in laravel "Name and email address are required if not a client"

I'm getting an error as "Name and email address are required if not a client" while running the below mentioned code.
Find below the Controller Code:
class UserController extends Controller
{
public function insertform(){
return view('test');
}
public function create(){
$user=Whmcs::AddClient([
'firstname' => Input::get('firstname'),
'lastname' => Input::get('lastname'),
'email' => Input::get('email'),
'address1' => Input::get('address1'),
'city' => Input::get('city'),
'state' => Input::get('state'),
'postcode' => Input::get('postcode'),
'country' => Input::get('country'),
'phonenumber' => Input::get('phonenumber'),
'password2' => Input::get('password2'),
]);
return $user;
}
}
Find below the route code:
Route::get('insert', 'UserController#insertform');
Route::post('create', 'UserController#create')->name('user.create');
The blade file is given below
<div id="content" class="app-content" role="main">
<div class="app-content-body ">
<div class="bg-light lter b-b wrapper-md">
<h1 class="m-n font-thin h3">Sign up</h1>
</div>
<div class="wrapper-md" ng-controller="FormDemoCtrl">
<div class="row">
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading font-bold">create an account</div>
<div class="panel-body">
<form class="bs-example form-horizontal" action="
{{route('user.create')}}" method="post">
<input type = "hidden" name = "_token" value = "<?php echo
csrf_token(); ?>">
<div class="form-group">
<label class="col-lg-2 control-label">firstname</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="firstname"
placeholder="Name">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">lastname</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="lastname"
placeholder="Name">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">Email</label>
<div class="col-lg-6">
<input type="email" class="form-control" name="email"
placeholder="Email">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">address1</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="address1"
placeholder="Subject">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">city</label>
<div class="col-lg-6">
<select class="form-control" name="city">
<option value="-- Select --">-- Select --</option>
<option value="Coimbatore">Coimbatore</option>
<option value="Chennai">Chennai</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">state</label>
<div class="col-lg-6">
<select class="form-control" name="state">
<option value="-- Select --">-- Select --</option>
<option value="Tamilnadu">Tamilnadu</option>
<option value="Andhra">Andhra</option>
<option value="Karnataka">Karnataka</option></select>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">country</label>
<div class="col-lg-6">
<select class="form-control" name="country">
<option value="-- Select --">-- Select --</option>
<option value="India">India</option>
<option value="China">China</option>
<option value="Australia">Australia</option></select>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">postcode</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="postcode"
placeholder="postcode">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">phonenumber</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="phonenumber"
placeholder="phonenumber">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">password</label>
<div class="col-lg-6">
<input type="password" class="form-control" name="password2"
placeholder="password">
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button type="submit" class="btn btn-sm btn-
success">Login</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
When I run the above code I'm getting an error as below:
{"result":"error","message":"Name and email address are required if not a client"}
suggest me a solution to solve this and post the data in laravel.

How to retrieve the post value and validate in controller using laravel?

In my route file
Route::get('griev_reg_form', 'GrievanceRegisterController#show');
Route::post('griev_reg_form', 'GrievanceRegisterController#postdata');
and in controller
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\GrievanceRegister;
use App\Department;
use Input;
use Validator;
use Redirect;
use Session;
class GrievanceRegisterController extends Controller
{
public function show()
{
$departments = Department::orderBy('edesc','ASC')->get();
return view('griev_reg_form', array('departments' => $departments));
}
public function postdata()
{
$data = Input::all();
// print_r($data);
echo $name = Input::get('name');
$rules = array(
'name' => 'required',
'email_address' => 'required|email',
'g-recaptcha-response' => 'required|captcha',
);
$validator = Validator::make($data, $rules);
if ($validator->fails()){
echo "1";
return Redirect::to('/griev_reg_form')->withInput()->withErrors($validator);
}
else{
// Do your stuff.
}
}
}
?>
and in the view file
{!! Form::open(array('url'=>'griev_reg_form','method'=>'POST', 'id'=>'myform')) !!}
<div class="box-body">
<div class="form-group">
<label class="col-sm-3 control-label">Grievance Case:
</label>
<label>
<input type="radio" name="gretype" class="minimal" checked>
</label>
<label>Normal Case
</label>
<label>
<input type="radio" name="gretype" class="minimal">
</label>
<label>
NRI
</label>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Grievance/Demand/Suggestion/Others:
</label>
<label>
<input type="radio" name="sugg_demand" class="minimal" checked value="G">
</label>
<label>Grievance
</label>
<label>
<input type="radio" name="sugg_demand" class="minimal" value="S">
</label>
<label>
Suggestion
</label>
<label>
<input type="radio" name="sugg_demand" class="minimal"
value="D">
</label>
<label>
Demand
</label>
<label>
<input type="radio" name="sugg_demand"
class="minimal" value="O">
</label>
<label>
Others
</label>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Department/Office:
</label>
<select class="form-control select2" name="dept_name" style="width: 28%;">
<option value="">Select Department</option>
<?php
foreach($departments as $result)
{
?>
<option value="<?php echo $result->deptcode; ?>"><?php echo $result->edesc; ?></option>
<?php
}
?>
</select>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Mobile No:</label>
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-phone"></i>
</div>
<input type="text" class="form-control" name="mobileno">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Alternative Mobile No:</label>
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-phone"></i>
</div>
<input type="text" class="form-control" name="amobileno">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Received Date:</label>
<div class="input-group date">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="text" class="form-control" name="recvd_date" id="datepicker" readonly="">
</div>
<!-- /.input group -->
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Name:</label>
<input type="text" class="form-control" name="cname">
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Individual or Group Complainant(s):
</label>
<label>
<input type="radio" name="indiv_grp" value="I" class="minimal" checked>
</label>
<label>Individual
</label>
<label>
<input type="radio" name="indiv_grp" value="G" class="minimal">
</label>
<label>Group
</label>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">AADHAR Card Number:</label>
<input type="text" class="form-control" name="idproofdetail">
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Address:</label>
<input type="text" class="form-control" name="address1">
</div>
<div class="form-group">
<input type="text" class="form-control box-right" name="address2">
</div>
<div class="form-group">
<input type="text" class="form-control box-right" name="address3">
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Pin code:</label>
<input type="text" class="form-control" name="pincode">
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Email:</label>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope"></i></span>
<input type="email" class="form-control" placeholder="Email" name="email_address">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">District:
</label>
<select class="form-control select2" name="district_problem" style="width: 28%;">
</select>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">विधानसभा निर्वाचन क्षेत्र /Assembly Constituency:
</label>
<select class="form-control select2" name="ac_problem" style="width: 28%;">
</select>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Area:
</label>
<label>
<input type="radio" value="urban" name="problem_area" class="minimal" checked>
</label>
<label>Urban
</label>
<label>
<input type="radio" value="rural" name="problem_area" class="minimal">
</label>
<label>
Rural
</label>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Town/Block:
</label>
<select class="form-control select2" name="city_problem" style="width: 28%;">
</select>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Please Enter Specific Details about Your Grievance </label>
<textarea class="form-control" rows="3" name="Description" placeholder="Enter ..."></textarea>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">What do you want?</label>
<textarea class="form-control" rows="3" name="remedies" placeholder="Enter ..."></textarea>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Upload(Relevant Document):</label>
<input type="file" class="form-control">
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Captcha</label>
<label class="col-sm-3 control-label">
{!! app('captcha')->display(); !!}
</label>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Submit
</button>
</div>
</div>
</form>
when i click on submit button without filling any data, its doesn't go
on validation part
Please provide help how can i check the post value of input fileds as well as
captcha and also validate accordingly
I have checked your view..I didnt find any input field named as "name", you have "cname" so maybe you validation rule should be:
$rules = array(
'cname' => 'required',
'email_address' => 'required|email',
'g-recaptcha-response' => 'required|captcha'
);
In case you are using >=5.3 version then you should use:
public function postdata(Request $request)
{
//validation
$validationArray = [
'cname' => 'required',
'email_address' => 'required|email',
'g-recaptcha-response' => 'required|captcha'
];
$validator = Validator::make($request->all(),$validationArray);
if ($validator->fails()) {
$response = ['errors' => $validator->messages()->all()];
return Response::json($response,200);
}
//here if validation is successful
}
Ofcourse add at top of controller: use Illuminate\Http\Request;

laravel form model binding not working laravel 5.4

I have gone through similar posts on SO but nothing has worked for me and also not found relative answer. Even it is not updating data.
{!! Form::model($editClient, [ 'method' => 'PATCH','route' => ['clients.update', $editClient->id],'class' => 'form-horizontal', 'id'=>'edit-client' ]) !!}
#include('clients._form')
I am using form as partial
Route:
Route::resource('clients', 'ClientController');
Controller Method:
public function edit($id)
{
$editClient = User::findOrFail($id);
return view('clients.edit', compact('editClient'));
}
HTML:
<div class="form-group">
<label class="control-label col-sm-2" for="username">Username:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="email" name="user_name" placeholder="Enter Username">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="email">Email:</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="Enter email">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="pwd">Password:</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="pwd" name="password" placeholder="Enter password">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="contact">Contact Number: </label>
<div class="col-sm-10">
<input type="number" class="form-control" id="contact" name="contact" placeholder="Enter Contact Number">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
From the Laravel Collective docs for Form model binding (https://laravelcollective.com/docs/5.4/html#form-model-binding):
{{ Form::model($user, ['route' => ['user.update', $user->id]]) }}
You have $editClient whereas I think your model is probably $client

how to write ckeditor code in laravel form view in laravel

Hello everyone i want to add ckeditor in my view which has multiple divs. How can i do that by adding this ckeditor code:
<title>A Simple Page with CKEditor</title>
<script src="../ckeditor.js"></script>
</head>
<body>
<form>
<textarea name="editor1" id="editor1" rows="10" cols="80">
This is my textarea to be replaced with CKEditor.
</textarea>
<script>
// Replace the <textarea id="editor1"> with a CKEditor
// instance, using default configuration.
CKEDITOR.replace( 'editor1' );
</script>
</form>
</body>
And this is my view
#extends('sadmin.main-template')
#section('title', 'Super admin Dashboard')
#section('title', 'Add Plan')
#section('content')
<div class="col-lg-9 col-md-9 col-sm-9 col-xs-12 right-sidebar admin-client add-client">
#include('partials.errors')
<form action="{{url('sadmin/add_plan')}}" class="toggle-disabled" method="post">
{!! csrf_field() !!}
<h3 class="title">Add a plan</h3>
<div class="form-group">
<label >You Can Create Your Plan Here</label>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 left-client-title">
<div class="form-group">
<label class="form-label name">
<span class="form-name">Name</span>
<input type="text" class="form-control" id="name" name="name" placeholder="" data-validation="custom" data-validation-regexp="^([A-Za-z ]+)$">
</label>
</div>
<div class="form-group">
<label class="form-label name">
<span class="form-name">Price</span>
<input type="text" class="form-control" id="name" name="price" placeholder="" data-validation="custom" data-validation-regexp="^([A-Za-z ]+)$">
</label>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 right-client-title">
<div class="form-group">
<label class="form-label name">
<span class="form-name">Allowed Users</span>
<input type="text" class="form-control" id="name" name="allowed_users" placeholder="" data-validation="custom" data-validation-regexp="^([A-Za-z ]+)$">
</label>
</div>
<div class="form-group">
<label class="form-label name">
<span class="form-name">Can Trail</span>
<input type="text" class="form-control" id="canTrail" name="can_trail" placeholder="" data-validation="custom" data-validation-regexp="^([A-Za-z ]+)$">
</label>
</div>
</div>
<div class="form-group">
<label class="form-label name">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 left-client-title">
<span class="form-name">Trail Duration</span>
<input type="text" class="form-control" id="password" name="trail_duration" placeholder="" data-validation="custom" data-validation-regexp="^([A-Za-z ]+)$">
</label>
<div class="form-group">
<label class="form-label name">
<span class="form-name">Detail 1</span>
<input type="text" class="form-control" id="passwordConfirmation" name="detail1" placeholder="" data-validation="custom" data-validation="required">
</label>
</div>
</div>
<div class="form-group">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 right-client-title">
<label class="form-label name">
<span class="form-name">Detail 2</span>
<input type="text" class="form-control" id="phoneNumber" name="detail2" placeholder="" data-validation="custom" data-validation-regexp="^([A-Za-z ]+)$">
</label>
<div class="form-group">
<label class="form-label name">
<span class="form-name">Staff Profiles</span>
<input type="text" class="form-control" id="planName" name="staff_profiles" placeholder="" data-validation="custom" data-validation-regexp="^([A-Za-z ]+)$">
</label>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 left-client-title">
<div class="form-group">
<label class="form-label name">
<span class="form-name">Space Management</span>
<input type="text" class="form-control" id="planPrice" name="space_management" placeholder="" data-validation="custom" data-validation-regexp="^([A-Za-z ]+)$">
</label>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 right-client-title">
<div class="form-group">
<label class="form-label name">
<span class="form-name">Currency Unit</span>
<input type="text" class="form-control" id="allowedUsers" name="currency_unit" placeholder=""data-validation="custom" data-validation-regexp="^([A-Za-z ]+)$" >
</label>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 right-client-title">
<div class="form-group">
<label class="form-label name">
<span class="form-name">Location charges</span>
<input type="text" class="form-control" id="allowedUsers" name="location_charges" placeholder=""data-validation="custom" data-validation-regexp="^([A-Za-z ]+)$" >
</label>
</div>
</div>
</div>
<p> </p>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 text-center">
<div align="center">
<button type="submit" class="btn btn-success" style="padding-left:90px; padding-right:90px;"><strong>Submit</strong></button>
</div>
</div>
</div>
</section>
</div>
#endsection
How i can apply ckeditor code in each div any help would be appreciated.

Resources