简体   繁体   English

Laravel 4重定向与片段URL不起作用

[英]Laravel 4 Redirect with fragment url not working

I'm creating a web app using laravel 4. I'm having an issue with redirecting back to the previous page with a fragment identifier after a form submission. 我正在使用laravel 4创建一个Web应用程序。提交表单后,我使用片段标识符重定向回上一页时遇到问题。 It just redirects slightly below the top of the page instead of to the specified location. 它只是重定向到页面顶部下方,而不是重定向到指定位置。 How can I make this work? 我该如何进行这项工作?

here's my html: 这是我的html:

<section id="name" class="row">
    <div class="large-4 large-centered medium-8 medium-centered columns">
        <h3 class="text-center white top-marg-2 bot-marg-2">{{{ trans('header.changeName') }}}</h3>
            {{ Form::open(['action' => 'AccountController@changeName']) }}
                @include('layout.form.first-name')
                @include('layout.form.last-name')
                @include('layout.form.submit')
            {{ Form::close() }}
    </div>
</section>

the included files are my form fields. 包含的文件是我的表单字段。

This is my get route: 这是我的路线:

Route::get('account/edit', 'AccountController@getEditProfile');

This is my post route: 这是我的张贴路线:

Route::post('account/name', 'AccountController@changeName');

This is my controller function: 这是我的控制器功能:

public function changeName() {

    $validator  = UserValidate::Name(Input::all());
    $firstName  = Input::get('first_name');
    $lastName   = Input::get('last_name');

    if ($validator->fails()) {

        return Redirect::to("account/edit"."#name")->withErrors($validator)->withInput();

    } else {

        $user = User::find(Auth::id());
        $user->first_name = $firstName;
        $user->last_name = $lastName;
        $user->save();

        return Redirect::to("account/edit"."#name")
        ->with('success', trans('modals.account5'));
    }
}

Any help would be much appreciated. 任何帮助将非常感激。

Thanks 谢谢

It turns out I had set "autofocus" on two form fields on two different forms on the page. 事实证明,我已经在页面上两个不同表单上的两个表单域上设置了“自动对焦”。 That was the problem 那是问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM