2017-02-28 41 views
0

我正在編輯用戶配置文件的頁面,但我希望正在處理的頁面在提交時提交給自己,並顯示一條消息,表明配置文件已被編輯成功。請問我該怎麼做?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

這是您的看法。你根本沒有寫在這裏的PHP。我們不能在這裏爲你寫代碼。您應該在控制器中寫入提交,並檢查提交按鈕何時單擊。 – Loko

回答

0

該解決方案來自https://laravel.io/forum/01-30-2015-form-submission-to-the-same-page。希望它有幫助

我已經做了一個獲取途徑來顯示頁面。然後我發佈了一篇文章發佈表單數據。

然後我通過$數據變量葉片在那裏我做了一個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 
相關問題