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 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化