将输入值从一个页面发送到另一个页面

I'm working on Laravel project and I want to send my input values from the FORM from one page (the inscription page) to a pdf page (which I want the user to be able to download). I couldn't find a way to send them from that page to the other

input:all using the $request in the controller

<div class="fieldgroup">
                            <input type="text" style="color:0B0C51" onclick="submitform2()" name="cin" id="cin"
                                    placeholder="N°CIN" maxlength="8" class="required"></i><br>

                    </div>


                    <div class="fieldgroup">
                            <input type="text" style="color:0B0C51" v-model="prenom" name="prenom" id="prenom"
                                    placeholder="Prenom" class="required"><br>
                    </div>


                    <div class="fieldgroup">
                            <input type="text" style="color:0B0C51" v-model="nom" onclick="submitform2()" name="nom"
                                    id="nom" placeholder="Nom" class="required"><br>
                    </div>

                    <div class="fieldgroup">
                            <input type="mail" style="color:0B0C51" name="email" id="email" placeholder="Email"
                                    class="required" />

                    </div>

ViewController :

    class ViewController extends Controller
{

public function generatePDF(Request $request){
    $request=this.
    $data="form";
    $pdf= PDF::loadView('pdf',compact('data'));
    return $pdf->download('Terms.pdf');
}

}

web.php:

       Route::get('/pdf','ViewController@generatePDF');

inscriController:

public function store(Request $request)
{   
    $cin = $request->input('cin');
    $data = array(['cin'=>$cin ]);

    DB::table('form')->insert($data);

    return redirect('/pdf')->withInput();

This returns an empty form page without the input values

2个回答

It may be easier to load the pdf right in the store method of inscriController. As it is, you are redirecting and passing no data into the pdf generator / view. You set $request as the controller ($this), which has none of the form data, and then you pass a single word 'form' as your data-set into the PDF generator. I don't think this will work the way you wish - I assume the pdf view is looking for specific variables (not 'form'), and thus it is failing because those vars are missing. IE you'd want to pull those vars like $name = $request->get('name') and pass whatever pdf.blade.php view needs from your $request var.

If you don't want to do it all in the store function, perhaps pass it to a method in the same inscriController? This way you can easily push the actual request object into that method and pull the fields you need for the PDF view.

doulun9534
doulun9534 我认为的主要问题是你没有将任何变量传递给你的pdf视图。 您正在传递一个字符串(字面意思是“形式”一词将转到视图),而不是变量。 查看您的视图(pdf)并查看它需要的变量。 然后,您需要从$ request对象中提取这些变量,并通过compact函数将它们发送到视图。 就像你在视图中需要var $ name一样,然后在控制器中设置$ name并传递它:$ pdf = PDF :: loadView('pdf',compact('name'));
大约一年之前 回复
dongyong2906
dongyong2906 谢谢你的时间,但我实际上并不明白你的意思,你可以提供一个链接或一些代码来工作吗?
大约一年之前 回复

use $input = $request->all(); for getting the data and in same function instead of redirect u can just return view for your /pdf route.

like return view('yourpath.pdf', compact('input'));

drza10046
drza10046 谢谢你的回复,但我尝试过它并没有用
大约一年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问