When I try to upload an image within Laravel the validation is not working. Here my validation string...
'cover' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048'
The validation error I get is The cover must be an image. It does work however when I only have the required rule.
What is the problem?
You can remove the rule 'image' on your validation :
'cover' => 'required|mimes:jpeg,png,jpg,gif,svg|max:2048',
Hope it help u :)
try this
'cover' => 'required|image|max:2048',
Related
I'm trying to validate an image upload that looks like the following:
$this->validate($request, [
'admin_image'=> 'nullable|image|dimensions:min_width=600,min_height=600',
]);
when the selected image too small then laravel shows error:
The Admin Image has invalid image dimensiona
I think that message is not saying specifically that in which dimension the image small, eg: width or height.
I'm expecting error message like:
The Admin Image width cannot be less than 600px and
The Admin Image height cannot be less than 600px
here 'Admin image' is the attribute name & '600' is the value I given in rules
So, I wanted to make a custom error message for min_width and max_widthin custom messages array on validation.php, that look like the following:
'admin_image' => [
'dimensions.min_width' => 'The :attribute dimension (width) cannot be less than :min_width px',
'dimensions.min_height' => 'The :attribute dimension (height) cannot be less than :min_height px',
],
But unfortunately that doesn't work & Laravel continues to show the default message.
Please understand that
I need 2 separate error message for dimensions:min_width=600 & dimensions:min_height=600
like I tried in the custom error messages array.
I know this is very simple but I'm doing something wrong.
Any help will be highly appreciated
Add the custom error message in validation.php as below:
'admin_image' => [
'dimensions' => [
'min_width' => 'The :attribute dimension (width) cannot be less than :min_width px'
]
]
I have following URL rule in my configuration file:
'rules' => [
'http://<store_url:\w+>.example.com/<product_name:\w+>' => 'index/index'
]
I type http://mystore2.example.com/iphone-15 and I got 404 error. What am I doing wrong?
try this after the last slash \w+(-\w+)+ to match hyphenated words. It could be 'http://<store_url:\w+>.example.com/<product_name:\w+(-\w+)+>' Let me know if it worked
In my project I used an image cropper widget. I setup the widget, that it save in frontend/web/upload. But in backend I save the images to frontend too.
This is working perfect. Then i want to show the image on the backend, if its exist. And i want to reach the frontend.
Thats why i want to set my own aliases in params-local.php file.
But I using vhosts to my webpages and I want to set Aliases to them.
In Yii2 documentation i found an article from aliases, but it wont help me. I mean i tried to use but it wont work.
I tried this:
return [
'aliases' => [
'#front' => 'http://front.mypage.dev',
'#back' => 'http://back.mypage.dev',
],
];
And I also tried this aswell:
Yii::setAlias('#front', 'http://front.mypage.dev');
Yii::setAlias('#back', 'http://back.mypage.dev');
But when i try to echo Yii::getAlias('#front'); it sais
Invalid Parameter – yii\base\InvalidParamException
Invalid path alias: #front
Maybe someone has a solution for this?
Thanks a lot.
Add in backend/config/params.php like:
return [
'front' => 'http://front.mypage.dev',
'back' => 'http://back.mypage.dev',
];
and use it from:
Yii::$app->params['front']
Yii::$app->params['back']
Let me know your thought.
Try this:
Yii::setAlias('#front', 'http://front.mypage.dev');
Yii::setAlias('#back', 'http://back.mypage.dev');
echo Yii::getAlias('#front');
echo Yii::getAlias('#back');
echo Yii::getAlias('#frontend/path/to/file');
echo Yii::getAlias('#backend/path/to/file');
Yii2 Playground
setting-aliases-in-yii2-within-the-app-config-file
I want to check for a posted data if present so that I can set a form field as required or not, without having to create a custom rule.
Is it possible to use/load/call CodeIgniter's input library inside the config file (specifically the form_validation.php config file) and get user posted data without having to use the native $_POST variable?
my code goes something like this...
...
array(
'field' => 'dob_day',
'label' => 'Day',
'rules' => (($this->ci->input->post('include_person') === 'yes') ? 'required|' : '') . 'integer|max_length[2]|greater_than[0]|less_than[32]|valid_birth_date'
),
...
Obviously, my approach does not work. hehe. If there's an alternative efficient codeigniter way of doing what i'm thinking, please let me know.
Thanks for all your help! :)
See this:
MANUAL
try this example, in this mode you can at runtime change your rules:
$this->form_validation->set_rules('dob_day', 'Day', 'your new rules');
Okay, I ended up with putting the logic in the controller, and just using inline validation. But to have inline validation work without having to set all the rules, I used the code from this website to allow both inline and config rules to mix.
http://brettic.us/2010/09/13/codeigniter-form-validation-mix-rule/
Cheers!
We're using Zend_Filter_Input to validate a Dojo From at Backend. There is "option" Input Element where we have to verify that the submitted value is allowed.
Problem: If nothing is selected the Zend_Validate_inArray Validator returns
" you must provide an non Empty value"
thats fine, but we have to change the message. I cant find the proper way to do this..
'FIELD' => array(new Zend_Validate_InArray($allowedValues),
'messages' => 'MESSAGE_WRONG_VALUE',
'default' => ''
),
Does someone know how to change the "isEmpty" Message?
It is Zend Framework 1.11.12
Try this:
$element->setRequired(true)->addErrorMessage('Your message');