表单提交后,在 laravel 中向用户显示提交的数据
Posted
技术标签:
【中文标题】表单提交后,在 laravel 中向用户显示提交的数据【英文标题】:after form submission display the submitted data to user in laravel 【发布时间】:2019-11-14 23:37:03 【问题描述】:我在 Laravel 中有一个表单,当用户提交数据时,数据会发送到数据库和我的电子邮件。现在,当用户提交数据时,我想将用户重定向到向用户显示提交数据的不同页面。为此,我做了以下操作,
HTML
<form id="" method="POST" enctype="multipart/form-data" action=" route('register.store') ">
@csrf
<input id="website" name="website" type="text" value="">
<!-- Leave for security protection, read docs for details -->
<div id="middle-wizard">
<div class="step">
<!-- <h3 class="main_question"><strong>1/5</strong>Primary Applicant Name</h3> -->
<label>Applicant Name</label>
<div class="form-group">
<input type="text" name="firstname" class="form-control required" placeholder="First Name">
</div>
<div class="form-group">
<input type="text" name="lastname" class="form-control required" placeholder="Last Name">
</div>
<div class="form-group">
<label for="file">Applicant Photo</label>
<input type="file" name="Photo" class="form-control required" >
</div>
<label>Company Details</label>
<div class="form-group">
<input type="text" name="company" class="form-control required" placeholder="Name of the Company">
</div>
<div class="form-group">
<input type="text" name="designation" class="form-control required" placeholder="Designation">
</div>
</div>
<!-- /step-->
<div class="step">
<label>Company Address</label>
<div class="form-group">
<input type="text" name="address" class="form-control required" placeholder="Street Address">
</div>
<div class="form-group">
<input type="text" name="addressline2" class="form-control" placeholder="Address Line 2">
</div>
下面是表单提交后显示的页面。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Email</title>
</head>
<body>
<h5>Name: $reg->firstname." ".$reg->lastname</h5>
<h5>Experience: $reg->experience</h5>
<h5>Company: $reg->company</h5>
<h5>Address: $reg->address." ".$reg->addressline2</h5>
<h5>City: $reg->city</h5>
<h5>State: $reg->state</h5>
<h5>Pin: $reg->pin</h5>
<h5>Country: $reg->country</h5>
<h5>Mobile Number: $reg->mobilenumber</h5>
<h5>Whatsapp: $reg->Whatsapp</h5>
<h5>Alternate Number: $reg->alternatenumber</h5>
<h5>Email: $reg->Email</h5>
<h5>Company Regn. Number: $reg->CompanyRegNumber</h5>
<h5>Date Incorporation or Busi_Stp: $reg->Date_Incorporation_orBusi_Stp</h5>
<h5>GSTIN: $reg->GSTIN</h5>
<h5>Services Offered: $reg->Services_Offered</h5>
<h5>Annual Turnover: $reg->Annual_Turnover</h5>
<h5>Declaration: $reg->Declaration</h5>
<h5>Fee: $reg->Fee." ".$reg->Fee1." ".$reg->Fee2." ".$reg->Fee3</h5>
<h5>Mode_of_Payment: $reg->Mode_of_Payment</h5>
<h5>Recommended by (A): $reg->Recommended_by_A</h5>
<h5>Recommended by (B): $reg->Recommended_by_B</h5>
<h5>Confirmation: $reg->confirmation</h5>
<h5>Terms and Conditions: $reg->termsandconditions</h5>
<h5> </h5>
<h5> </h5>
<br>
<h5>Applicant Photo</h5>
<img src=" $message->embed(storage_path("app/public/".$b_phot)) "><br>
<h5>Receipt</h5>
<img src=" $message->embed(storage_path("app/public/".$recipt)) "><br>
<h5></h5>
<img src=" $message->embed(storage_path("app/public/".$sign)) ">
</body>
</html>
控制器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Register;
use App\Mail\SendEmail;
use Session;
use Mail;
use Storage;
use Illuminate\Support\Facades\File;
class RegController extends Controller
public function index()
//
public function create()
//
public function store(Request $request)
// return $request;
// return $request->Fee;
$data = new Register;
$data->firstname = $request->firstname;
$data->lastname = $request->lastname;
$data->mobilenumber = $request->mobilenumber;
$data->experience = $request->experience;
$data->designation = $request->designation;
$data->confirmation = $request->confirmation;
$data->company = $request->company;
$data->address = $request->address;
$data->addressline2 = $request->addressline2;
$data->city = $request->city;
$data->state = $request->state;
$data->pin = $request->pin;
$data->country = $request->country;
$data->Whatsapp = $request->Whatsapp;
$data->alternatenumber = $request->alternatenumber;
$data->Email = $request->Email;
$data->CompanyRegNumber = $request->CompanyRegNumber;
$data->Date_Incorporation_orBusi_Stp = $request->Date_Incorporation_orBusi_Stp;
$data->GSTIN = $request->GSTIN;
$data->Services_Offered = $request->Services_Offered;
$data->Annual_Turnover = $request->Annual_Turnover;
$data->Declaration = $request->Declaration;
$data->termsandconditions = $request->termsandconditions;
// $data->Fee = $request->Fee;
$data->Mode_of_Payment = $request->Mode_of_Payment;
$data->Recommended_by_A = $request->Recommended_by_A;
$data->Recommended_by_B = $request->Recommended_by_B;
$fee = $request->Fee[0];
$data->Fee = $fee;
if(!empty($request->Fee[1]))
$data->Fee1 = $request->Fee[1];
if(!empty($request->Fee[2]))
$data->Fee2 = $request->Fee[2];
if(!empty($request->Fee[3]))
$data->Fee3 = $request->Fee[3];
if($request->hasFile('Photo'))
$image = $request->file('Photo');
$filename = time().$image->getClientOriginalName();
$destinationPath = public_path('uploads/Photo');
Storage::disk('public')->put($filename, File::get($image));
$data->Photo=$filename;
if($request->hasFile('Receipt'))
$image = $request->file('Receipt');
$filename = time().$image->getClientOriginalName();
$destinationPath = public_path('uploads/Receipt');
Storage::disk('public')->put($filename, File::get($image));
$data->Receipt=$filename;
if($request->hasFile('Signature'))
$image = $request->file('Signature');
$filename = time().$image->getClientOriginalName();
$destinationPath = public_path('uploads/Signature');
Storage::disk('public')->put($filename, File::get($image));
$data->Signature=$filename;
$data->save();
Session::flash('registered','reg');
$name = $request->firstname." ".$request->lastname;
$subject = "TEIA";
$message = $data->id;
$photo = $data->Photo;
$sign = $data->Signature;
$recipt= $data->Receipt;
// $email = 'zubairnazeroliyat@gmail.com';
$email = 'kmolugu@gmail.com';
// ->cc(['name1@domain.com','name2@domain.com'])
Mail::to($email)->send( new SendEmail($subject,$message , $photo ,$sign,$recipt));
return redirect('/');
public function show($id)
//
public function edit($id)
//
public function update(Request $request, $id)
//
public function destroy($id)
//
页面正在重定向到显示页面,但值没有随之而来。代码有什么问题?
提前致谢。
【问题讨论】:
您的控制器代码在哪里? 【参考方案1】:保存$data->save()
后试试return redirect('/')->with(['reg'=>$data]);
发送,希望能成功
【讨论】:
我应该在哪里关闭方括号 在$data->save()
之后用dd($data)
检查值是否存在【参考方案2】:
您还没有将 $reg 变量从控制器传递给查看。
这就是你必须发送 $reg 的原因。
【讨论】:
我将如何通过它以上是关于表单提交后,在 laravel 中向用户显示提交的数据的主要内容,如果未能解决你的问题,请参考以下文章