表单提交后,在laravel中将提交的数据显示给用户

时间:2019-07-04 09:04:58

标签: php html sql laravel

我在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:&nbsp;{{$reg->firstname."  ".$reg->lastname}}</h5>
	<h5>Experience:&nbsp;{{$reg->experience}}</h5>
	<h5>Company:&nbsp;{{$reg->company}}</h5>
	<h5>Address:&nbsp;{{$reg->address."  ".$reg->addressline2}}</h5>
	<h5>City:&nbsp;{{$reg->city}}</h5>
	<h5>State:&nbsp;{{$reg->state}}</h5>
	<h5>Pin:&nbsp;{{$reg->pin}}</h5>
	<h5>Country:&nbsp;{{$reg->country}}</h5>
	<h5>Mobile Number:&nbsp; {{$reg->mobilenumber}}</h5>
	<h5>Whatsapp:&nbsp;{{$reg->Whatsapp}}</h5>
	<h5>Alternate Number:&nbsp;{{$reg->alternatenumber}}</h5>
	<h5>Email:&nbsp;{{$reg->Email}}</h5>
	<h5>Company Regn. Number:&nbsp;{{$reg->CompanyRegNumber}}</h5>
	<h5>Date Incorporation or Busi_Stp:&nbsp;{{$reg->Date_Incorporation_orBusi_Stp}}</h5>
	<h5>GSTIN:&nbsp;{{$reg->GSTIN}}</h5>
	<h5>Services Offered:&nbsp;{{$reg->Services_Offered}}</h5>
	<h5>Annual Turnover:&nbsp;{{$reg->Annual_Turnover}}</h5>
	<h5>Declaration:&nbsp;{{$reg->Declaration}}</h5>
	<h5>Fee:&nbsp;{{$reg->Fee."  ".$reg->Fee1."  ".$reg->Fee2."  ".$reg->Fee3}}</h5>
	<h5>Mode_of_Payment:&nbsp;{{$reg->Mode_of_Payment}}</h5>
	<h5>Recommended by (A):&nbsp;{{$reg->Recommended_by_A}}</h5>
	<h5>Recommended by (B):&nbsp;{{$reg->Recommended_by_B}}</h5>
	<h5>Confirmation:&nbsp;{{$reg->confirmation}}</h5>
	<h5>Terms and Conditions:&nbsp;{{$reg->termsandconditions}}</h5>

	<h5>&nbsp;</h5>
	<h5>&nbsp;</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)
    {
        //
    }
}

页面正在重定向到显示页面,但值不随其而来。代码有什么问题?

谢谢。

2 个答案:

答案 0 :(得分:1)

您尚未将$ reg变量从控制器传递给视图。

这就是为什么您必须发送$ reg。

答案 1 :(得分:1)

保存$data->save()后再试一次,您可以将其与return redirect('/')->with(['reg'=>$data]);一起发送,希望它能工作