dongmangsha7354 2017-05-20 22:57
浏览 66
已采纳

如何在laravel中单击链接时将URL值添加到表单字段中

I want to create a ref link like this in laravel 5.4Registration form emails example.com For every registered user and when the link is click it should redirect to the registration form where the ref value is automatically get into the REF form field as given in the image. Here are the related images RegistrationController

  • 写回答

3条回答 默认 最新

  • doucan1979 2017-05-21 06:09
    关注

    Edit : Updated the link generation based on comments

    Generate the referral link using the logged in user's email. Assuming you have the logged in user as $user, if not replace it with auth()->user()->email. Note that this will need logged in user's email. So it goes without saying that you need to be logged in before to generate the ref link.

    If you pass the currently logged in user to your view from controller then do this, where $user = auth()->user();

    <a href="{{ route('register', ['ref' => $user->email]) }}" target="_blank">Referral register link</a>
    

    If you want to directly access the logged in user's email

    <a href="{{ route('register', ['ref' => auth()->user()->email]) }}" target="_blank">Referral register link</a>
    

    This is how it would look like in the view.

    <a href="http://example.com/register?ref=example@example.com" target="_blank">Referral register link</a>
    

    Add the following code in your registration form depending on how you create the form.

    <input type="text" name="referrer" value="{{ request('ref') }}">
    
    Or
    
    {!! Form::text('referrer', request('ref')) !!}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计