douyu9433 2019-06-19 23:06
浏览 350

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

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条回答 默认 最新

  • duanquyong8164 2019-06-19 23:30
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献