Support the ongoing development of Laravel.io →
posted 10 years ago
Validation
Last updated 2 years ago.
0

I would use the Validation class which you can read up about here: http://laravel.com/docs/4.2/validation

0

implementation or you have any example?

0
$validator = Validator::make(
    array(
        'name' => 'Dayle',
        'password' => 'lamepassword',
        'email' => '[email protected]'
    ),
    array(
        'name' => 'required',
        'password' => 'required|min:8',
        'email' => 'required|email|unique:users'
    )
);

First array is inputs and second is rules.

Last updated 10 years ago.
0

so far I have the following

$percents = Input::get('percent');
$descriptions = Input::get('description');

$rules = array(
		'percent' => 'required'
		'description' => 'required'
	);
0
$validator = Validator::make(
    array(
        'percent' => Input::get('percent'),
        'description' => Input::get('description'),
    ),
    array(
        'percent' => 'required',
        'description' => 'required',
    )
);

if ($validator->fails())
{
    // handle the failure here!
}

Hope this helps!

Last updated 10 years ago.
0

The big problem is that they are 46 percent and 46 description

0
percents = Input::get('percent');
descriptions = Input::get('description');

foreach ($percents  as $key => $percent) {
$fields['percent'.$key] = $percent;
$rules['percent'.$key] = 'required|numeric|between:0,100';
}
$validator = Validator::make($fields, $rules);

if ($validator->fails())
{
    return Redirect::back()->withErrors($validator)->withInput();
}

and descriptions validations????

0

Worked as follows, but would like to improve the code

//Form
{{ Form::text("percents[{$key}]") }}
{{ Form::textarea("descriptions[{$key}]") }}


//Controller
$percents = Input::get('percents');
$descriptions = Input::get('descriptions');

foreach ($porcentajes as $key => $porcentaje)
{
$fields['percents'.$key] = $porcentaje;
$fields['descriptions'.$key] = $descriptions[$key] ;
$rules['percents'.$key] = 'required|numeric|between:0,100';
$rules['descriptions'.$key] = 'required';
}

$validator = Validator::make($fields, $rules);

if ($validator->fails())
{
return Redirect::back()->withErrors($validator)->withInput();
}

//View
{{ str_replace('percents'.$key, 'Percent', $errors->first('percents'.$key, '<p class="text-danger">:message</p>')) }}

{{ str_replace('descriptions'.$key, 'Description', $errors->first('descriptions'.$key, '<p class="text-danger">:message</p>')) }}
0

Sign in to participate in this thread!

Eventy

Your banner here too?

montes2012 montes2012 Joined 11 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.