简体   繁体   中英

How do I post url $_GET['params'] when submitting form?

I do this in my routes to check if $_GET exists

Route::get('/register', function(){
    if(isset($_GET['code'])){
        $referral = $_GET['code'];
    };

    return Response::view('user.register');
    }
);

Then in my view I do this

<div style='display:none'>
  <?php if (isset($referral)){ ?>
    {!! Form::hidden('referral', <?php $referral ?>) !!}
  <?php } ?>
</div>

But when I submit the form it doesn't show up.

Also I had to use display none because {!! Form::hidden etc...!!} actually shows up on the ui.

Relevant doc on Laravel requests input

Route::get('/register', function(\Illuminate\Http\Request $request){
    if ($request->has('code')) {
        $referral = $request->input('code');
    }

    // I imagine you actually send $referral to the view here...
    return Response::view('user.register');
    }
);

In view:

@if (isset($referral))
    {!! Form::hidden('referral', $referral) !!}
@endif

When a form is submitted, its data is usually sent by POST, not GET. Using the Request methods abstracts that away and is much better than using the raw PHP array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM