0

PyroCMS 1.3.1を使用して、付属の連絡先モデルのコピーアンドペーストバージョンに近いモデルを作成しましたが、いくつかの調整が加えられています。すべてのフィールドが正しく入力されると、すべてが期待どおりに機能します。フィールドが省略されているか、間違って入力されている場合、フォームは送信されません-期待どおりです。

しかし、フォーム検証メッセージを出力することができないようで、これは私を夢中にさせています。私は非常に基本的なものを見逃したと確信しているので、誰かがそれを指摘することができれば私は感謝するでしょう。

ビューファイル(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);
}
4

1 に答える 1

0

form_validation_lang.phpしたがって、CodeIgniters言語ファイルのカスタマイズに取り組んでいる間、すべてのエントリが空だったため、のアップロードを台無しにしたに違いありません。$lang['required'] = '';

したがって、基本的にバリデーターはエラーメッセージを探し、出力されないようにトリミングされた空の文字列を見つけました。何かばかげたことが疑われたように、私が期待した場所ではありませんでした。

この投稿が他の誰かのトラブルを救うことを願っています。

于 2011-09-02T07:17:55.017 に答える