样式回声错误

时间:2014-10-24 23:25:02

标签: php css forms login

我已经创建了一个注册页面,如果验证没有通过,它将回显错误。错误将始终显示在表单的顶部。我希望它们出现在表单下面,所以我添加了一个div。但这不起作用,因为它使每个错误都有一个单独的div,而不是在一个div中包含所有错误。如何在窗体下面的一个div中创建所有错误?

if (Input::exists()) {
    if (Token::check(Input::get('token'))) {

        $validate = new Validate();
        $validation = $validate->check($_POST, array(
        //validation

        if ($validation->passed()) {
            $user = new User();
            //pass information to database

                Session::flash('home', 'You have been registered and can now log in!');
                Redirect::to('index.php');
            } catch (Exception $e) {
                die($e->getMessage());
            }
        } else {
            foreach ($validation->errors() as $error) {
                echo '<div id="r-error"><p id="error">', $error, '</p></div>';
            }
        }
    }
}
?>

1 个答案:

答案 0 :(得分:3)

只需将<div>取出循环即可。在循环之前回显开头,然后在循环之后回显闭合。

if (Input::exists()) {
    if (Token::check(Input::get('token'))) {

        $validate = new Validate();
        $validation = $validate->check($_POST, array(
        //validation

        if ($validation->passed()) {
            $user = new User();
            //pass information to database

                Session::flash('home', 'You have been registered and can now log in!');
                Redirect::to('index.php');
            } catch (Exception $e) {
                die($e->getMessage());
            }
        } else {
            echo '<div id="r-error">';
            foreach ($validation->errors() as $error) {
                echo '<p class="error">', $error, '</p>';
            }
            echo '</div>';
        }
    }
}
?>