[Помогите] how to get error on selected language validateForm()

Тема в разделе "OpenCart", создана пользователем affgon, 13 июн 2017.

  1. affgon

    affgon

    Регистрация:
    19 янв 2014
    Сообщения:
    125
    Симпатии:
    412
    how to get error on selected language

    validateForm() opencart 1.5.6.4

    // array languages_edit

    PHP:
    $languages_edit $this->request->post['languages_edit'];
    // Post array

    PHP:
    foreach ($this->request->post['article_description'] as $language_id => $value) {
           if  ((
    utf8_strlen($value['name']) < 1) || (utf8_strlen($value['name']) > 255))  {
               
    $this->error['name'][$language_id] = $this->language->get('error_name');      
           }      
       }
    i need to get error if post name not matched on post language_id

    EX.
    language = FR , RU , EN ,TH , LA
    and i select language_edit = RU , FR , TH //set error if not post in this language
    and post name['FR'] , name['TH'] // this post

    it must show error name['RU'] because language RU it selected on language_edit
    but language LA must not show error because it not selected on language_edit

    THANK. :Smile:
     
  2. Dotrox

    Dotrox Команда форума

    Регистрация:
    27 ноя 2012
    Сообщения:
    3.198
    Симпатии:
    1.306
    You can't do this.
    $this->language->get always return text in current active language. And it is correct way, because this language is chosen by current user.
     
  3. affgon

    affgon

    Регистрация:
    19 янв 2014
    Сообщения:
    125
    Симпатии:
    412
    slove it
    1 .create language error data
    PHP:
    if (isset($this->error['languages_edit'])) {
               
    $this->data['error_languages_edit'] = $this->error['languages_edit'];
           } else {
               
    $this->data['error_languages_edit'] = '';
           }
    2. create get language_edit data
    PHP:
    if (isset($this->request->post['languages_edit'])) {
               
    $this->data['languages_edit'] = $this->request->post['languages_edit'];
           } elseif (isset(
    $this->request->get['article_id'])) {
               
    $this->data['languages_edit'] = $this->model_author_article->getLanguagesEdit($this->request->get['article_id']);
           } else {
               
    $this->data['languages_edit'] = array();
           }
    3. create error if post name not match in language_edit post
    PHP:
    if (empty($this->request->post['languages_edit'])) {
               
    $this->error['languages_edit'] = $this->language->get('error_languages_edit');
               
    $this->session->data['error'] = 'ERROR Unselect Language';
           }
           
           
                       
           foreach (
    $this->request->post['article_description'] as $language_id => $value) {       
               if  (!empty(
    $this->request->post['languages_edit']) && ((utf8_strlen($value['name']) < 1) || (utf8_strlen($value['name']) > 255)) && in_array($language_id,$this->request->post['languages_edit']))  {   
                   
    $this->error['name'][$language_id] = $this->language->get('error_name');
               }
               
    $this->session->data['error'] = 'ERROR Not match Language';
           }
    4. save data post to DB
    PHP:
           $article_id $this->db->getLastId();
           
           if (isset(
    $data['languages_edit'])) {
               foreach (
    $data['languages_edit'] as $language) {
                       
    $value $data['article_description'][$language]   ;           
                       
    $this->db->query("INSERT INTO " DB_PREFIX "blog_article_description SET
                       article_id = '" 
    . (int)$article_id "',
                       author_id = '" 
    $this->author->getId() . "',                   
                       language_id = '" 
    . (int)$language "',   
                       name = '" 
    $this->db->escape($value['name']) . "',
                       short_description = '" 
    $this->db->escape($value['short_description']) . "',
                       description = '" 
    $this->db->escape($value['description']) . "',
                       meta_description = '" 
    $this->db->escape($value['meta_description']) . "',
                       meta_keyword = '" 
    $this->db->escape($value['meta_keyword']) . "',
                       image_thumb = '" 
    $this->db->escape($value['image_thumb']) . "',
                       video_thumb = '" 
    $this->db->escape($value['video_thumb']) . "',
                       thumb_title = '" 
    $this->db->escape($value['thumb_title']) . "',
                       tag = '" 
    $this->db->escape($value['tag']) . "',
                       date_added = NOW(),
                       status = '" 
    . (int)$value['status'] . "',
                       sort_order = '" 
    . (int)$value['sort_order'] . "'                    
                       "
    );

               }
           }
    THANK :Smile: