Welcome Guest, Not a member yet? Register   Sign In
Ajax and ci4 validation
#3

(05-16-2022, 06:28 PM)iRedds Wrote: Can you explain more precisely. For example, I do not understand what you are talking about.

Normally, I place my validation in the Model (sometimes place in controller) something like this;

PHP Code:
    $category $this->model->find($category_id);
        if (
$this->request->getMethod() === 'post') {
            
$category->fill($this->request->getPost());
            if (
$this->model->save($category)) {
                return 
redirect()->to('/admin/post/categories')
                                 ->
with('info''Success - category was updated');
            } else {
                return 
redirect()->back()
                                 ->
with('errors'$this->model->errors())
                                 ->
with('warning''Invalid Data')
                                 ->
withInput();
            }
        } else {
            
$this->data['category'] = $this->model->find($category_id);
            return 
view('/Admin/Category/category_update'$this->data    );
        } 

My rules are somethin like;


PHP Code:
protected $validationRules    = [
        
        
'category_name' => 'required|is_unique[category.category_name]|min_length[5]|max_length[50]',
        
'category_user_id' => 'required',
         
'category_description' => 'required|min_length[5]|max_length[250]',
        ];
    protected 
$validationMessages = [
        
'category_name' => [
            
'required' => 'The category name is required',
            
'is_unique' => 'The category already exists',
            
'min_length' => 'The minimum length is 5 characters',
            
'max_length' => 'The maximum length is 50 characters'
            
],
        
'category_description' => [
            
'required' => 'The category description is required',
            
'min_length' => 'The minimum length is 5 characters',
            
'max_length' => 'The maximum length is 50 characters'
            
],   
        ]; 

How would like use the above in case of using ajax. Is is possible?
Reply


Messages In This Thread
Ajax and ci4 validation - by spreaderman - 05-16-2022, 05:58 PM
RE: Ajax and ci4 validation - by iRedds - 05-16-2022, 06:28 PM
RE: Ajax and ci4 validation - by spreaderman - 05-16-2022, 10:05 PM
RE: Ajax and ci4 validation - by manager - 05-16-2022, 11:28 PM
RE: Ajax and ci4 validation - by manager - 05-16-2022, 11:09 PM
RE: Ajax and ci4 validation - by iRedds - 05-16-2022, 11:24 PM
RE: Ajax and ci4 validation - by spreaderman - 05-17-2022, 02:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB