Registering form is not storing data in database - html

Well I am using this form to register a user in database but It is not successfully being storing data. While RegisterContoller.php is in Auth section. And I have given route: Auth::routes();. But still I why it is not storing data.
Register.blade.php
<form style="margin-left: 30%; margin-right: 30%; margin-top: 5%;" class="form-horizontal" method="POST" action="{{ route('register') }}">
{{ csrf_field() }}
<div class="form-group organic-form-2 {{ $errors->has('name') ? ' has-error' : '' }}">
<label for="name">Your Name *</label>
<input id="name" class="form-control" type="text" name="name" value="{{ old('name') }}" required autofocus>
#if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
#endif
</div>
<div class="form-group organic-form-2 {{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email">Your Email *</label>
<input id="email" class="form-control" type="email" name="email" value="{{ old('email') }}" required>
</div>
<div class="form-group organic-form-2">
<label>Password *</label>
<input class="form-control" type="Password">
</div>
<div class="form-group organic-form-2">
<label>Repeat Password *</label>
<input class="form-control" type="Password">
</div>
<div class="form-group remember-me">
<div class="checkbox pull-left">
<label>
<input type="checkbox" name="value1"> Privacy Policy Agreement?
</label>
</div>
</div>
<div class="form-group footer-form">
<button class="btn btn-brand pill" type="submit">SUBMIT</button>
</div>
</form>
</div>
</div>
</div>
</section>
</div>
RegisterController.php
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
}
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}

It seems you miss input names in your form.
Instead of:
<div class="form-group organic-form-2">
<label>Password *</label>
<input class="form-control" type="Password">
</div>
<div class="form-group organic-form-2">
<label>Repeat Password *</label>
<input class="form-control" type="Password">
</div>
use:
<div class="form-group organic-form-2">
<label>Password *</label>
<input class="form-control" type="Password" name="password">
</div>
<div class="form-group organic-form-2">
<label>Repeat Password *</label>
<input class="form-control" type="Password" name="password_confirmation">
</div>

Related

Image is not saving on my public path - laravel

im trying to save a profile image on a register blade, the images are going to database with the name but couldn't be save on my public/imgs repository, so i can't even show on a view. Can someone help me to resolve this problem? the name of the image on my database is "foto".
public function store
public function store(StoreUpdatePost $request)
{
$data = $request->all();
if($request->foto('foto')->isValid()){
$file = $request->foto->storeAs('public/users',$nameFile);
$file = str_replace('public/','app/',$file);
$data['foto'] = $file;
}
User::create($data);
//foto upload
if($request->hasFile('foto') && $request->file('foto')->isValid()){
$requestFoto = $request->foto;
$extension = $requestFoto->extension();
$fotoName = md5($requestFoto->getClientOriginalName() . strtotime("now")) . "." . $extension;
$request->foto->move(public_path('imgs\users'), $fotoName);
$data->foto = $fotoName;
$data->save();
}
}
VIEW REGISTER BLADE
#extends('layouts.app')
#section('content')
<div class="container"><!---->
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card" >
<br>
<div class="textocs">
<h4>CADASTRE-SE</h4>
</div>
<br><br>
<div class="card-body">
<form method="POST" enctype=”multipart/form-data” action="{{ route('register') }}">
#csrf
<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Nome') }}</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control #error('name') is-invalid #enderror" name="name" value="{{ old('name') }}" required autocomplete="name" autofocus>
#error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
<br>
</div>
</div>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-mail:') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control #error('email') is-invalid #enderror" name="email" value="{{ old('email') }}" required autocomplete="email">
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
<br>
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Senha:') }}</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control #error('password') is-invalid #enderror" name="password" required autocomplete="new-password">
#error('password')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
<br>
</div>
</div>
<div class="form-group row">
<label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Redigite a senha:') }}</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required autocomplete="new-password">
</div>
<br>
</div><br>
<div class="form-group row">
<label for="cidade" class="col-md-4 col-form-label text-md-right">{{ __('Cidade') }}</label>
<div class="col-md-6">
<input id="cidade" type="text" class="form-control #error('cidade') is-invalid #enderror" name="cidade" value="{{ old('cidade') }}" required autocomplete="cidade" autofocus>
#error('cidade')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
<br>
</div>
</div>
<div class="form-group row">
<label for="numero" class="col-md-4 col-form-label text-md-right">{{ __('Número') }}</label>
<div class="col-md-6">
<input id="numero" type="number" class="form-control #error('numero') is-invalid #enderror" name="numero" value="{{ old('numero') }}" required autocomplete="numero" autofocus>
#error('numero')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
<br>
</div>
</div>
<div class="form-group row">
<label for="foto" class="col-md-4 col-form-label text-md-right">{{ __('Foto') }}</label>
<div class="col-md-6">
<label for="foto">Foto:</label>
<input type="file" class="form-control-file" name="foto" >
<br>
</div>
</div>
<br><br>
<button type="submit" class="btn btn-primary">
{{ __('Cadastrar') }}
</button>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
MIGRATION TO ADD FIELDS ON USERS TABLE
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddCamposTableUsers extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('cidade');
$table->string('numero');
$table->string('foto')->nullable();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
Schema::dropIfExists('users');
});
}
}

what is wrong in this it is not inserting [duplicate]

i have a small problem here and it is that the image field doesn't have a default value as the complier said but actually i assigned a value for it i know that this error pops up when the field should have a value but the programmer didn't assign a value to it i know all of this but i already assigned a value to my field so what i am missing here
controller
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
'image' => ['required' , 'image' , 'mimes:jpeg,png,jpg', 'max:2048'],
]);
}
protected function create(array $data)
{
$imageName = time().'.'.request()->image->getClientOriginalExtension();
request()->image->move(public_path('images'), $imageName);
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'image' => $imageName,
'password' => Hash::make($data['password']),
]);
}
view
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Register') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('register') }}" enctype="multipart/form-data">
#csrf
<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control #error('name') is-invalid #enderror" name="name" value="{{ old('name') }}" required autocomplete="name" autofocus>
#error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control #error('email') is-invalid #enderror" name="email" value="{{ old('email') }}" required autocomplete="email">
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control #error('password') is-invalid #enderror" name="password" required autocomplete="new-password">
#error('password')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required autocomplete="new-password">
</div>
</div>
<label class="col-md-4 col-form-label text-md-right" >Upload a picture</label>
<div class="custom-file mb-3 col-sm-6">
<input type="file" class="custom-file-input center" id="image" name="image">
<label class="custom-file-label" for="customFile"></label>
</div>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Register') }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
the problem is mainly from the controller but i said that i put the view just in case you want to see it
small note : the image is uploading and it is stored at public folder just like the code said but its name doesn't save at the database also the field image is string at my database because i just want its name so i could view it
snap shot
Set a default image for your image field. Also make sure you have made it fillable, if not set it in protected $fillable in your model User.php
You will get this error when a user doesn't upload an image.
$table->string('image')->default('default.jpg');//You can also add .png
Now have a default image in your storage with name default.jpg
This way the image will have a default value if user doesn't' upload it.
You need to add the default value or make that field null in the migration file, not the controller or view.
$table->string('image')->nullable();
or...
$table->string('image')->default('value');

laravel | ajax, if form incomplete send email

Hello fellow developers,
I am trying to solve a problem I am having and can't seem to find the correct answer a possible link or explanation will be very helpful.
I want to add an ajax function on the email field once the email is entered the name, surname and email should be saved to the database without the submit button being pressed. So that a (complete your form) email can be send 2 hours later.
I am really new to ajax and already using parsley for front end verification
Would anybody be able to assist?
Regards
{{ csrf_field() }}
<div class="form-group">
<label for="`name" class="name">First Name:</label>
<input type="text" name="name" id="name" class="form-control" required=" "
data-parsley-minlength="6" data-parsley-trigger="blur">
</div>
<div class="form-group">
<label for="surname" class="surname">Surname:</label>
<input type="text" name="surname" id="surname" class="form-control"
required=" " data-parsley-minlength="6" data-parsley-trigger="blur">
</div>
<div class="form-group">
<label for="email" class="email">Email Address:</label>
<input type="text" name="email" id="email" class="form-control" required=" "
data-parsley-type="email" data-parsley-trigger="blur">
</div>
<div class="form-group">
<label for="`size" class="size">Size of company:</label>
<input type="text" name="size" id="size" class="form-control" required=" "
data-parsley-type="integer" data-parsley-trigger="blur">
</div>
<div class="form-group">
<label for="`income" class="income">Income:</label>
<input type="text" name="income" id="income" class="form-control" required="
" data-parsley-type="integer" data-parsley-trigger="blur">
</div>
<div class="form-group" style="padding-bottom: 10px">
<label>Position in Company:</label>
<select name="position" id="position" class="form-control" value=" {{
old('position') }}" required=" " data-parsley-trigger="blur">
#foreach(App\Http\Utilities\Position::all() as $position)
<option value="{{ $position }}">{{ $position }}</option>
#endforeach
</select>
</div>
<div class="form-group">
<textarea name="message" id="message" class="form-control" rows="4" data-
parsley-maxlength="1000" data-parsley-trigger="blur">Enter text here...
</textarea>
</div>
<div class="form-group">
<label for="path" class="path">Accept Terms and Conditions
<input type="checkbox" name="path" class="form-control" required=" " data-
parsley-trigger="blur"></label>
</div>
<div class="form-group">
<input type="file" class="form-control" name="cv" id="cv" data-parsley-
trigger="blur">
</div>
<button type="submit"class="btn btn-primary">Submit details</button>

Can't submit form with "attributes" input field

I have a form with the following setup:
<div class="row">
<div class="col-3">
#include('acp.sidebar')
</div>
<div class="col-9">
#if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form class="form-horizontal" role="form" method="POST" action="{{ url('acp/provider/add') }}" enctype="multipart/form-data">
{{ csrf_field() }}
<input type="hidden" name="id">
<fieldset>
<legend>Grunddaten</legend>
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="form-group">
<label for="description">Beschreibung</label>
<textarea class="form-control" id="description" name="description" required></textarea>
</div>
<div class="form-group">
<label for="url">Domain</label>
<input type="text" class="form-control" id="url" name="url" required>
</div>
<div class="form-group">
<label for="ref">Ref-Code</label>
<input type="text" class="form-control" id="ref" name="ref" required>
</div>
<div class="form-group">
<label for="image">Logo</label>
<input type="file" name="image" id="image" class="form-control" accept="image/*">
</div>
<div class="form-group">
<label for="checkboxes">Payment-Anbieter</label>
<div>
#foreach($paymentProviders as $key => $provider)
<label class="checkbox-inline" for="checkboxes-{{$key}}">
<input name="paymentProviders[]" id="checkboxes-{{$key}}" value="{{$provider->id}}" type="checkbox">
<img src="{{url('/images/paymentProvider/small/'.$provider->image)}}">
{{$provider->name}}
</label>
#endforeach
</div>
</div>
</fieldset>
<fieldset>
<legend>Crawler</legend>
<div class="form-group">
<label for="attributes">Suchattribute</label>
<input type="text" class="form-control" id="attributes" name="attributes" required>
</div>
<div class="form-group">
<label for="crawlerType">Typ</label>
<select id="crawlerType" name="crawlerType" class="form-control">
#foreach($crawlerTypes as $crawlerType)
<option value="{{$crawlerType}}">{{$crawlerType}}</option>
#endforeach
</select>
</div>
</fieldset>
<div class="form-group">
<div class="pull-right">
<button type="submit" class="btn btn-primary">
Absenden
</button>
</div>
</div>
</form>
</div>
</div>
As you can see there is a input named "attributes" down below. When I add this, I can't submit my form. It's like clicking on a button with no "submit" attribute.
After removing or renaming this input, it works. It's not a big thing to rename my input - I'm just interested if this is a bug, or a for me unkown feature.
I'm using Bootstrap v4.0.0-alpha.6 and Laravel 5.4.22.

Laravel : Form not submitting but everything looks right?

I have a very strange problem with Laravel . I'm sure I miss something but not sure what.
When submit there's no record in DB. But it's very strange that not submit even without validator. Here is the code.
The model:
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
class Registration extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
/**
* The database table used by the model.
*
* #var string
*/
protected $table = 'register';
protected $fillable = array('first_name','middle_name','last_name','address','phone','email','age','growth','weight','shoe_size','cloth_size','languages','eye_color');
}
The Controller :
<?php
class RegistrationController extends BaseController {
public function getAgency() {
return View::make('agency');
}
public function postAgency(){
$rules = array(
'first_name' => 'required',
'middle_name' => 'required',
'last_name' =>'required',
'address' => 'required',
'phone' => 'required',
'email' => 'required|email',
'age' => 'required',
'growth' =>'required',
'weight' => 'required',
'shoe_size' => 'required',
'cloth_size' => 'required',
'languages' => 'required',
'eye_color' => 'required'
);
$validator = Validator::make(Input::all(),$rules);
if ($validator->fails()) {
return Redirect::to('/agency')->withErrors($validator)->withInput();
}
else {
$registration = new Registration;
$registration->first_name = Input::get('first_name');
$registration->middle_name = Input::get('middle_name');
$registration->last_name = Input::get('last_name');
$registration->address = Input::get('address');
$registration->phone = Input::get('phone');
$registration->email = Input::get('email');
$registration->age = Input::get('age');
$registration->growth = Input::get('growth');
$registration->weight = Input::get('weight');
$registration->shoe_size = Input::get('shoe_size');
$registration->cloth_size = Input::get('cloth_size');
$registration->languages = Input::get('languages');
$registration->eye_color = Input::get('eye_color');
$registration->save();
return Redirect::to('/agency')->with('global',"Thank You!");
}
}
}
The View (agency.blade.php):
#extends('layouts.main')
#section('content')
<div class="container">
<div class="stepwizard">
<div class="stepwizard-row setup-panel">
<div class="stepwizard-step">
1
<p><img src="images/leftShoe.png" alt="" class="shoes"></p>
</div>
<div class="stepwizard-step">
2
<p><img src="images/rightShoe.png" alt="" class="shoes"></p>
</div>
<div class="stepwizard-step">
3
<p><img src="images/duoShoes.png" alt="" class="shoes"></p>
</div>
</div>
</div>
<form method="POST" action="{{URL::action('agency-post')}}">
<div class="row setup-content" id="step-1">
<div class="col-md-12">
<button class="btn btn-primary nextBtn btn-lg pull-right" type="button" >Next</button>
</div>
</div>
<div class="row setup-content" id="step-2">
<div class="col-xs-12">
<div class="col-md-12">
<div class="form-group">
<label>First Name</label>
<input type="text" id="name" class="form-control" name="first_name" placeholder="First Name">
#if ($errors->has('first_name')) <p class="help-block">{{ $errors->first('first_name') }}</p> #endif
</div>
<div class="form-group">
<label >Middle Name</label>
<input type="text" id="name" class="form-control" name="middle_name" placeholder="Middle Name">
#if ($errors->has('middle_name')) <p class="help-block">{{ $errors->first('middle_name') }}</p> #endif
</div>
<div class="form-group">
<label >Last Name</label>
<input type="text" id="name" class="form-control" name="last_name" placeholder="Last Name">
#if ($errors->has('last_name')) <p class="help-block">{{ $errors->first('last_name') }}</p> #endif
</div>
<div class="form-group">
<label >Address</label>
<input type="text" id="name" class="form-control" name="address" placeholder="Address">
#if ($errors->has('address')) <p class="help-block">{{ $errors->first('address') }}</p> #endif
</div>
<div class="form-group">
<label >Phone</label>
<input type="text" id="name" class="form-control" name="phone" placeholder="Phone">
#if ($errors->has('phone')) <p class="help-block">{{ $errors->first('phone') }}</p> #endif
</div>
<div class="form-group">
<label >Email</label>
<input type="email" id="email" class="form-control" name="email" placeholder="super#cool.com">
#if ($errors->has('email')) <p class="help-block">{{ $errors->first('email') }}</p> #endif
</div>
<div class="form-group">
<label >Age</label>
<input type="text" id="email" class="form-control" name="age" placeholder="Age">
#if ($errors->has('age')) <p class="help-block">{{ $errors->first('age') }}</p> #endif
</div>
<div class="form-group">
<label >Growth</label>
<input type="text" id="email" class="form-control" name="growth" placeholder="Growth">
#if ($errors->has('growth')) <p class="help-block">{{ $errors->first('growth') }}</p> #endif
</div>
<div class="form-group">
<label >Weight</label>
<input type="text" id="email" class="form-control" name="weight" placeholder="Weight">
#if ($errors->has('weight')) <p class="help-block">{{ $errors->first('weight') }}</p> #endif
</div>
<div class="form-group">
<label >Shoe size</label>
<input type="text" id="email" class="form-control" name="shoe_size" placeholder="Shoe size">
#if ($errors->has('shoe_size')) <p class="help-block">{{ $errors->first('shoe_size') }}</p> #endif
</div>
<div class="form-group">
<label >Size Clothing</label>
<input type="text" id="email" class="form-control" name="cloth_size" placeholder="Cloth Size">
#if ($errors->has('cloth_size')) <p class="help-block">{{ $errors->first('cloth_size') }}</p> #endif
</div>
<div class="form-group">
<label >Spoken Languages</label>
<input type="text" id="email" class="form-control" name="languages" placeholder="Spoken Languages">
#if ($errors->has('languages')) <p class="help-block">{{ $errors->first('languages') }}</p> #endif
</div>
<div class="form-group">
<label >Eye Color</label>
<input type="text" id="email" class="form-control" name="eye_color" placeholder="Eye Color">
#if ($errors->has('eye_color')) <p class="help-block">{{ $errors->first('eye_color') }}</p> #endif
</div>
<div class="form-group">
<button class="btn btn-primary nextBtn btn-lg pull-right" type="button" >Next</button>
</div>
</div>
</div>
<div class="row setup-content" id="step-3">
<div class="col-xs-12">
<div class="col-md-12">
<h3> Additional Information</h3>
<div class="form-group">
<label class="control-label">Skills</label>
<textarea maxlength="500" class="form-control" rows="5" placeholder="Enter your skills"></textarea>
</div>
<div class="form-group">
<label class="control-label">Additional Information</label>
<textarea maxlength="500" type="text" class="form-control" rows="5" placeholder="Enter additional information for you"></textarea>
</div>
{{Form::token()}}
{{Form::submit('Finish!')}}
</div>
</div>
</div>
Route.php
Route::get('/agency',array(
'as' => 'agency',
'uses' => 'RegistrationController#getAgency'
));
Route::post('/agency',array(
'as' => 'agency-post',
'uses' => 'RegistrationController#postAgency'
));
It's more strange that when write in loop $validator->fails() { return 'fails';}
page only reload nothing happens.