【问题标题】:Adding an extra field for Zizaco/confide keeps resulting in error为 Zizaco/confide 添加额外的字段会导致错误
【发布时间】:2014-01-14 13:52:45
【问题描述】:

您好,我正在使用 Laravel(此框架的新手)和 Zizaco/Confide 包。我已经设法根据自己的需求和偏好进行了很多编辑,但我似乎无法解决这个关于添加新输入字段以以管理员身份创建新用户的问题

查看 form.day_of_birth 字段

该错误表明该字段未填写(我已检查在屏幕上提交后打印会话数组)

在 AdminUserController 中,我更改了 PostEdit() 方法和 PostCreate() 方法,添加了以下内容

public function postCreate()
{
    $this->user->username = Input::get( 'username' );
    $this->user->email = Input::get( 'email' );
    $this->user->birthday = Input::get( 'd__day_of_birth__m' );
    $this->user->password = Input::get( 'password' );

    // The password confirmation will be removed from model
    // before saving. This field will be used in Ardent's
    // auto validation.
    $this->user->password_confirmation = Input::get( 'password_confirmation' );
    $this->user->confirmed = Input::get( 'confirm' );

    // Permissions are currently tied to roles. Can't do this yet.
    //$user->permissions = $user->roles()->preparePermissionsForSave(Input::get( 'permissions' ));

    // Save if valid. Password field will be hashed before save
    $this->user->save();

    if ( $this->user->id )
    {
        // Save roles. Handles updating.
        $this->user->saveRoles(Input::get( 'roles' ));

        // Redirect to the new user page
        return Redirect::to('admin/users/' . $this->user->id . '/edit')->with('success', Lang::get('admin/users/messages.create.success'));
    }
    else
    {
        // Get validation errors (see Ardent package)
        $error = $this->user->errors()->all();

        return Redirect::to('admin/users/create')
            ->withInput(Input::except('password'))
            ->with( 'error', $error );
    }
}

我在注册页面上几乎有相同的功能,供用户创建自己的帐户,这就像一个魅力。不知何故,它似​​乎不起作用..

在视图中我添加了这个

                 <div class="form-group {{{ $errors->has('d__day_of_birth__m') ? 'error' : '' }}}">
                <label class="col-md-2 control-label" for="day_of_birth">{{{ Lang::get('form.day_of_birth') }}}</label>
                <div class="col-md-10">
                    <input class="form-control js__birthdaypicker" placeholder="{{{ Lang::get('form.day_of_birth') }}}" type="text" name="day_of_birth" id="day_of_birth" value="{{{ Input::old('day_of_birth', isset($user) ? $user->email : null) }}}"/>
                    {{{ $errors->first('d__day_of_birth__m', '<span class="help-inline">:message</span>') }}}
                </div>
            </div>

【问题讨论】:

    标签: php mysql laravel laravel-4


    【解决方案1】:

    在 html 中,您将输入命名为 day_of_birth 而不是 d__day_of_birth__m

    【讨论】:

    • 是的,那是因为我使用的日期选择器提供了 2 种提交日期。一个是人类友好的版本(day_of_birth),另一个是我使用的版本(2013-12-27 示例)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-03
    • 2013-10-26
    相关资源
    最近更新 更多