3

フォーム検証エラーが機能しなくなりました。昨日は機能していました。何か間違ったことをしたに違いありませんが、見つからないようです。

ユーザー名とメールアドレスを入力すると、メールが送信され、「メールが送信されました!」とエコーされます。

情報を入力せずにサインアップをクリックするだけで、ビューをロードするユーザー/サインアップにリダイレクトされます。

controllers / user.php:

public function signup_validation() {
    $this -> load -> library('form_validation');

    $this -> form_validation -> set_rules('username', 'Username', 'trim|required|alpha|min_length[3]|max_length[25]');
    $this -> form_validation -> set_rules('email', 'Email', 'required|trim|valid_email|is_unique[users.email]');
    $this -> form_validation -> set_rules('password', 'Password', 'required|trim');
    $this -> form_validation -> set_rules('cpassword', 'Retype', 'required|trim|matches[password]');

    if ($this -> form_validation -> run()) {
        $key = md5(uniqid());

        $this -> load -> library('email', array('mailtype' => 'html'));
        $this -> load -> model('users');
        $this -> email -> from('', "");
        $this -> email -> to($this -> input -> post('email'));
        $this -> email -> subject('Confirm your account.');
        $message = "<p>Thank you for signing up!</p>";
        $message = "<p><a href='" . base_url() . "user/activate/$key'>Click here</a> to confirm your account.</p>";
        $this -> email -> message($message);
        if ($this -> users -> add_temp_user($key)) {
            if ($this -> email -> send()) {
                echo "The email has been sent!";
            } else {
                echo "Could not send the email.";
            }
        } else {
            echo "Problem adding user to database.";
        }
    } else {
        redirect('user/signup');
    }
}

views / signup.php

<form class="form-horizontal" action="<?php echo base_url() . 'user/signup_validation'; ?>" method="post" accept-charset="UTF-8">
    <?php echo validation_errors(); ?>
    <div class="control-group">
        <label class="control-label" for="inputEmail">Username</label>
        <div class="controls">
            <input name="username" type="text" id="inputUsername" placeholder="username" value="<?php echo $this -> input -> post('username'); ?>"/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="inputEmail">Email</label>
        <div class="controls">
            <input name="email" type="email" id="inputEmail" placeholder="email" value="<?php echo $this -> input -> post('email'); ?>"/>
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="inputPassword">Password</label>
        <div class="controls">
            <input name="password" type="password" id="inputPassword" placeholder="password" />
        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="inputRetype">Retype</label>
        <div class="controls">
            <input name="cpassword" type="password" id="inputRetype" placeholder="retype" />
        </div>
    </div>
    <div class="form-actions">
        <input name="signup_submit" type="submit" class="btn" value="Sign up" />
    </div>
</form>

ヘルパーを自動ロードします:

$autoload['helper'] = array('url', 'form');

.htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.

    ErrorDocument 404 /index.php
</IfModule> 
4

1 に答える 1

16

$this->load->view('sign_up');代わりに 置くredirect('user/signup');

ビューをロードし、そのページをロードするコントローラーメソッドにリダイレクトしないことにより、検証エラーが表示されます。

于 2013-02-17T15:20:22.817 に答える