L
L
Ler Den2016-08-15 02:25:52
Laravel
Ler Den, 2016-08-15 02:25:52

How to display data from a form in another PHP/Laravel page?

Hello. There is a following task.
On the page, the user enters their data and submits the form. During the submission, a password is generated, which must be displayed on a new page. I can't display the password on the new page. In its place is just emptiness, no data and no errors.
As I see:
index.php

<form id="trialForm" method="post" name="trialForm" class="ui form">
                      <input type="email" id="emailCompany" name="emailCompany" placeholder="Email Address" data-validate="email-address" autocomplete="off" required="required">
                      <input type="text" id="nameCompany" name="nameCompany" placeholder="Company Name" data-validate="company-title" autocomplete="off" required="required">
                      <input type="hidden" name="_token" value="{{{ csrf_token() }}}" />
                      <input type="hidden" name="_psw" value="{{{ str_random(8) }}}" /> <!--генерируем пароль-->
                      <button type="submit" class="ui huge green button">
                       Start Trial
                    </button>
                  </form>

After sending, we redirect to a new page. How routing is organized:
routes.php
Route::post( '/' ,function() { return Redirect::to('/success'           , 301); });
Route::get( '/success' ,'Production\[email protected]' );

Success Function in Website.php
public function Success(request $request)
    {
      $psw = $request->get('_psw'); //получаем значение из отправленной формы
      return view('pages.success.Success', compact("psw"));
    }

Then on the Success.php page we display our password:
<div class="ui two column grid">
              <div class="column">
                Your temporary password
                <br />
                <b id="copyTarget">{{ $psw }}</b>
              </div>
              <div class="column">
                <div id="copyButton" class="ui button">Click to Copy</div>
              </div>
            </div>

Of course, the password can be stored on the client, but I still need to transfer it to the server. It looks like the data has gone somewhere. I suspect that in routes.php , when redirecting, data from the form is not transferred. Or maybe the problem is something else.
PS When I try to display in pure php <?php echo $_POST["_psw"] ?> I get the error "Undefined index: _psw". It turns out that the data from the POST was not transferred to the page success.php
I can't figure out how to transfer the data?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Murfy, 2019-07-19
@qxcoder

I can assume that the action parameter of the form is lost :)

<form id="trialForm" method="post" action="/" name="trialForm" class="ui form">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question