Laravel:如何使页面提交给自己

时间:2017-02-28 09:31:48

标签: php html forms laravel

我正在编辑一个用于编辑用户个人资料的页面,但我希望该页面在提交时正在提交给自己,并显示已成功编辑该个人资料的消息。请问我该怎么做?

这是什么工作?

        <div class="row">

          <div class="text-center title">Pricing</div>

          <div class="text-center desc col-md-8 col-md-push-2">

            {{$sitename}} 

          </div>


<div class="container" style="padding-top: 60px;">
  <h1 class="page-header">Edit Profile</h1>
  <div class="row">
    <!-- left column -->

    <form class="form-horizontal" role="form" method="post" action="/profile">
    <div class="col-md-4 col-sm-6 col-xs-12">
      <div class="text-center">
        <img id="ShowImage" src="#"/>
        <img src="http://localhost:8234/img/index.png" class="avatar img-circle img-thumbnail" alt="avatar" width="200" height="200">
        <h6>Upload a different photo...</h6>
        <input type="file" class="text-center center-block well well-sm" name="avatar_path" id="avatar_path" onchange="readURL(this);">
      </div>
    </div>
    <!-- edit form column -->
    <div class="col-md-8 col-sm-6 col-xs-12 personal-info">
      <div class="alert alert-info alert-dismissable">
        <a class="panel-close close" data-dismiss="alert">×</a> 
        <i class="fa fa-coffee"></i>
        This is the <strong>Profile Page</strong>. Use this to <strong>ONLY</strong> change your peronsal details
      </div>
      <h3>Personal info</h3>
        <input class="form-control" value="{{$userInfo['data']['id']}}" type="hidden" name="user_id">
        <div class="form-group">
          <label class="col-lg-3 control-label">First Name:</label>
          <div class="col-lg-8">
            <input class="form-control" value="{{$userInfo['data']['first_name']}}" type="text" name="first_name">
          </div>
        </div>
        <div class="form-group">
          <label class="col-lg-3 control-label">Last Name:</label>
          <div class="col-lg-8">
            <input class="form-control" value="{{$userInfo['data']['last_name']}}" type="text" name="last_name">
          </div>
        </div>
        <div class="form-group">
          <label class="col-lg-3 control-label">Username:</label>
          <div class="col-lg-8">
            <input class="form-control" value="{{$userInfo['data']['profile']['username']}}" type="text" name="username">
          </div>
        </div>
        <div class="form-group">
          <label class="col-lg-3 control-label">Email Address:</label>
          <div class="col-lg-8">
            <input class="form-control" value="{{$userInfo['data']['email']}}" type="text" name="email">
          </div>
        </div>
        <div class="form-group">
          <label class="col-lg-3 control-label">Gender</label>
          <div class="col-lg-8">
            <div class="ui-select">
              <select id="gender" class="form-control" name="gender">
                <option value="{{$userInfo['data']['profile']['gender']}}" selected>{{$userInfo['data']['profile']['gender']}}</option>
                <option value="Male">Male</option>
                <option value="Female">Female</option>
                <option value="Other">Other</option>
              </select>
            </div>
          </div>
        </div>
        <div class="form-group">
          <label class="col-lg-3 control-label">City:</label>
          <div class="col-lg-8">
            <input class="form-control" value="{{$userInfo['data']['profile']['city']}}" type="text" name="city">
          </div>
        </div>
        <div class="form-group">
          <label class="col-lg-3 control-label">State:</label>
          <div class="col-lg-8">
            <input class="form-control" value="{{$userInfo['data']['profile']['state']}}" type="text" name="state">
          </div>
        </div>
        <div class="form-group">
          <label class="col-lg-3 control-label">Country:</label>
          <div class="col-lg-8">
            <input class="form-control" value="{{$userInfo['data']['profile']['country']}}" type="text" name="country">
          </div>
        </div>
        <div class="form-group">
          <label class="col-lg-3 control-label">Mobile:</label>
          <div class="col-lg-8">
            <input class="form-control" value="{{$userInfo['data']['profile']['mobile']}}" type="text" name="mobile">
          </div>
        </div>
        <div class="form-group">
          <label class="col-lg-3 control-label">Occupation:</label>
          <div class="col-lg-8">
            <input class="form-control" value="{{$userInfo['data']['profile']['occupation']}}" type="text" name="occupation">
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-3 control-label"></label>
          <div class="col-md-8">
            <input class="bkgrnd-blue text-white btn btn-primary" value="Update Profile" type="submit">
            <span></span>
            <a href="/profile/{{$userInfo['data']['id']}}" class="bkgrnd-blue text-white btn btn-primary">Cancel</a>
          </div>
        </div>
      </form>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

此解决方案来自https://laravel.io/forum/01-30-2015-form-submission-to-the-same-page。希望它有所帮助

我已经完成了显示页面的get路径。然后,我确实发布了一个帖子来发布表单数据。

然后我将$ data变量传递给blade,我在其中执行了一个isset来检查它是否已创建,显示结果

显示初始页

public function destinationSearchGet(){
    $headData = array('pageTitle' => 'Admin Home - View all destinations');
    return view('admin.destination_search', $headData);
}

将数据发布回同一页面并创建新变量

public function destinationSearchPost(){
    $headData = array('pageTitle' => 'Admin Home - Search results');
    $formData = Request::input('destination');
    $data = ParentRegionList::destinationSearch($formData);
    return view('admin.destination_search', $headData)->with(compact('data'))
}

使用刀片检查是否存在

 @if (isset($data))
   <p>{{dd($data)}}</p>
 @endif
相关问题