2011-08-29 22 views
0

使用PyroCMS 1.3.1我已經構建了一個模型,它幾乎是所包含的聯繫人模型的複製粘貼版本,但只做了一些調整。當所有字段正確輸入時,所有內容都按預期工作。如果一個字段被遺漏或填寫不正確,表單不會提交 - 就像預期的那樣。在PyroCMS中未輸出表單驗證錯誤

但是,我似乎無法得到窗體驗證消息輸出,這讓我瘋狂。我確信我錯過了一些非常基本的東西,所以如果有人能指出,我會很感激。

查看文件(form.php的)包含此

<?php if (validation_errors()): ?> 
<div class="error-box"> 
    <?php echo validation_errors(); ?> 
</div> 
<?php elseif (isset($messages['error'])): ?> 
<div class="error-box"> 
    <p><?php echo $messages['error']; ?></p> 
</div> 
<?php endif; ?> 

控制器(plugin.php)看起來像這樣

class Plugin_mycustommodule extends Plugin { 

private $rules = array(
    array(
     'field' => 'firstname', 
     'label' => 'lang:mycustommodule_firstname_label', 
     'rules' => 'required|trim|max_length[80]' 
    ), 
    /* ... snip ... */ 
    array(
     'field' => 'license', 
     'label' => 'lang:mycustommodule_license_label', 
     'rules' => 'required' 
    ) 
); 

public function __construct() 
{ 
    $this->lang->load('mycustommodule'); 
} 

function form() 
{ 
    $this->load->library('form_validation'); 
    $this->load->helper('form'); 

    $this->form_validation->set_rules($this->rules); 

    // If the user has provided valid information 
    if ($this->form_validation->run()) 
    { 
     /* ... Custom processing here ... */ 

     // The try to send the email 
     if ($this->_send_email()) 
     { 
      $message = $this->attribute('confirmation', lang('mycustommodule_sent_text')); 

      // Store this session to limit useage 
      $this->session->set_flashdata('success', $message); 

      redirect(current_url()); 
     } 
     else 
     { 
      $message = $this->attribute('error', lang('mycustommodule_error_message')); 

      $data['messages']['error'] = $message; 
     } 
    } 

    // Set the values for the form inputs 
    foreach ($this->rules as $rule) 
    { 
     $form_values->{$rule['field']} = set_value($rule['field']); 
    } 

    $data['form_values'] = $form_values; 

    return $this->module_view('mycustommodule', 'form', $data, TRUE); 
} 

回答

0

因此,原來,雖然我工作的定製CodeIgniters語言文件我必須搞砸form_validation_lang.php上傳,因爲所有條目都是空的,即$lang['required'] = '';

因此,基本上驗證器尋找th e錯誤信息,找到一個空字符串,從輸出中刪除。懷疑有些愚蠢,只是不在我預期的地方。

讓我們希望這篇文章能夠拯救別人的麻煩。