Home>

The essence is such that I have a form on the main page -the method is activated by pressing the button, makes data in the database and returns me back. However, when I try to restart the page after that, the method works again and in the database is accounted for exactly the same record, although the form is already empty and, it would seem, there is nothing to send. (Yes, and why the method works at all, if I press F5) I do not understand what the problem

Form from the main page

<
FORM ACTION= "{{ROUTE ('CALCULATE')}}"
                     Method= "POST"
                       Enctype= "MultiPart /Form-Data"
                       class= "Form-inline PY-5" >
                   @csrf.
                   ≪
DIV Class= "Form-inline W-100 Justify-Content-Between Align-Content-Center Border P-2 MY-2 Rounded Blue-Light-BG" >
                       ≪
label class= "col-4" for= "workplaces" >
                           Number of jobs
                       ≪
/label >
                       ≪
INPUT TYPE= "NUMBER" NAME= "WP" CLASS= "COL-2 FORM-CONTROL TEXT-CENTER" >
                       ≪
span class= "col-4" >
The number of jobs is calculated as the amount of employees + Number of separately costing equipment (printers, faxes). ≪
/span >
                   ≪
/div >
                   ≪
DIV Class= "Form-inline W-100 Justify-Content-Between Align-Content-Center Border P-2 MY-2 Rounded Blue-Light-BG" >
                       ≪
label class= "col-4" for= "hl" >
                           Laboratory length <
Span class= "Text-Muted PX-2" >
in meters <
/span >
                       ≪
/label >
                       ≪
INPUT TYPE= "NUMBER" NAME= "HL" CLASS= "COL-2 FORM-CONTROL TEXT-CENTER" >
                       ≪
span class= "col-4" >
Specify the length of the laboratory. ≪
/span >
                   ≪
/div >
                   ≪
DIV Class= "Form-inline W-100 Justify-Content-Between Align-Content-Center Border P-2 MY-2 Rounded Blue-Light-BG" >
                       ≪
label class= "col-4" for= "wl" >
                           Laboratory Width <
Span class= "Text-Muted PX-2" >
in meters <
/span >
                       ≪
/label >
                       ≪
INPUT TYPE= "NUMBER" NAME= "WL" CLASS= "COL-2 FORM-CONTROL TEXT-CENTER" >
                       ≪
span class= "col-4" >
Specify the laboratory width. ≪
/span >
                   ≪
/div >
                   ≪
DIV Class= "Form-inline W-100 Justify-Content-Between Align-Content-Center Border P-2 MY-2 Rounded Blue-Light-BG" >
                       ≪
label class= "col-4" for= "ct" >
                           Type of cable
                       ≪
/label >
                       ≪
SELECT NAME= "CT" CLASS= "COL-2 FORM-CONTROL" ID= "CABLE" ONCHANGE= "MYFUNCTION ()" >
                           @if ($ Values!= "")
                           @Foreach ($ Values->
WHERE ('Category', 'Cable') as $ value)
                               ≪
Option Class= "Text-Center" Value= "{{$ value->
Title}} ">
                                   {{$ value->
title}}
                               ≪
/Option >
                           @endforeach.
                           @endif.
                       ≪
/SELECT >
                       ≪
span class= "col-4" >Type of network cable by means of data transmission between devices. ≪ /span >
                   ≪
/div >
                   ≪
DIV Class= "Form-Inline W-100 Justify-Content-Between Align-CONTER BORDER P-2 MY-2 Rounded Blue-Light-BG" ID= "Connection" Hidden >
                       ≪
label class= "col-4" for= "cc" >
                           Connection category
                       ≪
/label >
                       ≪
SELECT NAME= "CC" CLASS= "COL-2 FORM-CONTROL" >
                           @if ($ Values!= "")
                           @Foreach ($ Values->
WHERE ('Category', 'Connection') as $ value)
                           ≪
Option Class= "Text-Center" Value= "{{$ value->
Title}} ">
                               {{$ value->
title}}
                           ≪
/Option >
                           @endforeach.
                           @endif.
                       ≪
/SELECT >
                       ≪
span class= "col-4" >
Category 5E -Provides data transfer rate at 100MB /S <
BR >
                                           Category 6 -Provides data transfer rate at 1000MB /s. ≪
/span >
                   ≪
/div >
                   ≪
DIV Class= "Form-inline W-100 Justify-Content-Between Align-Content-Center Border P-2 MY-2 Rounded Blue-Light-BG" >
                       ≪
label class= "col-4" for= "tp" >
                           Type of network topology
                       ≪
/label >
                       ≪
SELECT NAME= "TP" CLASS= "COL-2 FORM-CONTROL" >
                           @if ($ Values!= "")
                           @Foreach ($ Values->
Where ('Category', 'TOPOLOGY') AS $ Value)
                               ≪
Option Class= "Text-Center" Value= "{{$ value->
Title}} ">
                                   {{$ value->
title}}
                               ≪
/Option >
                           @endforeach.
                           @endif.
                       ≪
/SELECT >
                       ≪
span class= "col-4" >
Topology determines the network structure on how all the components are interconnected with each other. ≪
/span >
                   ≪
/div >
                   ≪
DIV Class= "Form-inline W-100 Justify-Content-Between Align-Content-Center Border P-2 MY-2 Rounded Blue-Light-BG" >
                       ≪
label class= "col-4" for= "SW" >
                           Svitche
                       ≪
/label >
                       ≪
DIV Class= "COL-2 PX-0 MX-0" >
                           ≪
span >
                               ≪
SELECT NAME= "SW" CLASS= "FORM-CONTROL COL" >
                                   @if ($ Values!= "")
                                   @Foreach ($ Values->
Where ('Category', 'Switch') AS $ Value)
                                       ≪
Option Class= "Text-Center" Value= "{{$ value->
Title}} ">
                                           {{$ value->
title}}
                                       ≪
/Option >
                                   @endforeach.
                                   @endif.
                               ≪
/SELECT >
                               ≪
Span class= "Form-inline" >
                                   ≪
Label Class= "COL Text-Muted" >
Number <
/label >
                                   ≪
INPUT TYPE= "NUMBER" NAME= "SWC" CLASS= "COL-5 FORM-CONTROL TEXT-CENTER MY-2" TITLE= "Number of" Value= "1" >
                               ≪
/span >
                           ≪
/span >
                       ≪
/div >
                       ≪Span Class= "COL-4" > Network switch is an electronic device that combines several computers and /or other digital devices to the local network <
/span >
                   ≪
/div >
                   ≪
DIV Class= "Form-inline W-100 Justify-Content-Between Align-Content-Center Border P-2 MY-2 Rounded Blue-Light-BG" >
                       ≪
label for= "ad" class= "col-4" >
                           Additionally
                       ≪
/label >
                       ≪
DIV Class= "COL-2 PX-0 MX-0" ID= "Filters" >
                           ≪
span >
                               ≪
SELECT NAME= "AD []" Class= "Form-Control W-100" >
                                   @if ($ Values!= "")
                                       @Foreach ($ Values->
WHERE ('Category', 'Additional') as $ Value)
                                           ≪
Option Class= "Text-Center" Value= "{{$ value->
Title}} ">
                                               {{$ value->
title}}
                                           ≪
/Option >
                                       @endforeach.
                                   @endif.
                               ≪
/SELECT >
                               ≪
Span class= "Form-inline" >
                                   ≪
Label Class= "COL Text-Muted" >
Number <
/label >
                                   ≪
INPUT TYPE= "NUMBER" NAME= "ADC []" Class= "COL-5 Form-Control Text-Center MY-2" title= "Number of" Value= "1" >
                               ≪
/span >
                           ≪
/span >
                       ≪
/div >
                       ≪
DIV Class= "COL-4" >
                           ≪
Button Type= "Button"
                                   Class= "BTN BTN-Outline-Primary"
                                   OnClick= "addFilter" id= "addFilter" >
Add Field
                           ≪
/Button >
                           ≪
Button Type= "Button"
                                   Class= "BTN BTN-Outline-Dark"
                                   OnClick= "RemoveFilter" id= "RemoveFilter" >
Remove the field
                           ≪
/Button >
                       ≪
/div >
                   ≪
/div >
                   ≪
DIV Class= "W-100 Justify-Content-Center Form-Inline" >
                       ≪
DIV CLASS= "COL" >
                           ≪
Button Type= "submit" class= "BTN-LG BTN-PRIMARY MY-3" >
Calculate <
/Button >
                       ≪
/div >
                   @if (ISset ($ Total_Price))
                       ≪
DIV CLASS= "COL" >
                           ≪
Label >
Material Cost: {{$ Total_Price}} <
/label >
                       ≪
/div >
                   @endif.
                   ≪
/div >
               ≪
/Form >

Form Processing Method

Public Function Calculate (Request $ Request)
   {
       $ Calcdata= $ Request->
All ();
       //Data Validation
       $ Validator= Validator :: Make ($ Calcdata,
           [
               'WP'= >
 'Required | Min: 1 | Integer |',
               'HL'= >
 'Required | Min: 1 | Integer |',
               'WL'= >
 'Required | Min: 1 | Integer |',
               'SWC'= >
 'Required | Min: 1 | Integer'
           ]);
       if ($ validator->
fails ()) {
           RETURN REDIRECT (ROUTE ('MAIN-PAGE'))
               ->
Withrrors ($ Validator)
               ->
withInput ();
       }
       //Installing the main size for calculations (width or length)
       if ($ Calcdata ['HL'] >
 $ Calcdata ['WL']) {
           $ size= $ calcdata ['hl'];
       }
       ELSE {
           $ Size= $ calcdata ['WL'];
       }//Price and Cable Name (Connection Type For Twisted Couple) IF ($ Calcdata ['CT']== 'Twisted Couple')
       {
           $ Connection= Value :: WHERE ('TITLE', $ CALCDATA ['CC']) ->
first ();
           $ Cable= [
               'n'= >
 $ Calcdata ['CT'],
               'p'= >
 $ Connection->
Value
               'CC'= >
 $ Calcdata ['CC']
           ];
       }
       ELSE {
           $ Cable= [
               'n'= >
 $ Calcdata ['CT'],
               'p'= >
 Value :: WHERE ('TITLE', $ CALCDATA ['CT']) ->
first () ->
Value
               'CC'= >
 "''
           ];
       }
       //Calculation of the cost of the cable based on the required length according to the topology and sizes of the cabinet
       if ($ Calcdata ['TP']== 'Tire Topology')
       {
           $ length= 3 + $ Size + $ Calcdata ['WP'] /2;
           $ Cable += [
               'f'= >
 "3m + Laboratory length + Number of workplaces /2",
               'c'= >
 $ Length,
               'pt'= >
 INTVAL ($ length * $ Cable ['p'])];
       }
       Elseif ($ Calcdata ['TOPOLOGY']== 'Star Topology')
       {
           $ length= 3 + $ Size + $ Calcdata ['Workplaces'] * 1.5;
           $ Cable += [
               'f'= >
 "3m + Laboratory length + Number of jobs * 1.5",
               'c'= >
 $ Length,
               'pt'= >
 Intval ($ Length * $ Cable ['P'])
               ];
       }
       ELSE.
       {
           $ length= 3 + $ Size /2 * 6.28;
           $ Cable += [
               'f'= >
 "3m + Laboratory length /2 + 2pi",
               'c'= >
 $ Length,
               'pt'= >
 INTVAL ($ length * $ Cable ['p'])];
       }
       //Channel Cable
       $ CANAL= [
           'f'= >
 $ Cable ['F']
           'c'= >
 $ Cable ['C']
           'p'= >
 Value :: Where ('Title', Cable Cable ') ->
first () ->
Value
       ];
       $ CANAL += [
           'pt'= >
 $ canal ['p'] * $ canal ['C']
       ];
       //Sockets -//-Network Sockets
       $ socket= [
           'f'= >
 'Number of jobs * 2',
           'c'= >
 $ Calcdata ['WP'] * 2,
           'p'= >
 Value :: WHERE ('TITLE', 'Socket') ->
first () ->
Value
       ];
       $ Socket += [
           'pt'= >
 $ socket ['p'] * $ socket ['C']
       ];
       $ p_socket= [
           'f'= >
 'Number of jobs * 2',
           'c'= >
 $ Calcdata ['WP'] * 2,
           'p'= >
 Value :: WHERE ('TITLE', 'NETWORK SALET') ->
first () ->
Value
       ];
       $ p_socket += [
           'pt'= >
 $ p_socket ['p'] * $ p_socket ['c']
       ];
       //Svitch
       $ SwitchGet= Value :: WHERE ('TITLE', $ CALCDATA ['SW']) ->
first ();
       $ Switch= [
           'n'= >
 $ Switchget->
title
           'p'= >
 $ Switchget->
Value
           'c'= >
 $ Calcdata ['SWC'],
       ];
       $ Switch += [
           'pt'= >
 $ Switch ['p'] * $ switch ['C']
       ];
       //Total price
       $ Total_Price= $ Socket ['PT'] + $ p_socket ['pt'] + $ Cable ['PT'] + $ Switch ['Pt'] + $ canal ['pt'];
       //Creating a record
       $ Calc= New Calculation ();
       if (auth :: user ())
       $ Calc->
user_id= auth :: user () ->
ID;
       ELSE.
       {
           $ Calc->
user_id= 0;
       }
       $ Calc->
Socket_F= $ Socket ['F'];
       $ Calc->
socket_c= $ socket ['C'];
       $ Calc->
socket_p= $ socket ['p'];
       $ Calc->
socket_pt= $ socket ['pt'];
       $ Calc->
p_socket_f= $ p_socket ['f'];
       $ Calc->
p_socket_c= $ p_socket ['c'];
       $ Calc->
p_socket_p= $ p_socket ['p'];
       $ Calc->
p_socket_pt= $ p_socket ['pt'];
       $ Calc->
Cable_F= $ Cable ['F'];
       $ Calc->
Cable_n= $ Cable ['n'];
       $ Calc->
Cable_cc= $ Cable ['CC'];
       $ Calc->
Cable_c= $ Cable ['C'];$ Calc-> Cable_p= $ Cable ['P'];
       $ Calc->
Cable_pt= $ Cable ['Pt'];
       $ Calc->
Switch_n= $ Switch ['n'];
       $ Calc->
Switch_c= $ Switch ['C'];
       $ Calc->
switch_p= $ switch ['p'];
       $ Calc->
Switch_pt= $ Switch ['PT'];
       $ Calc->
canal_f= $ canal ['f'];
       $ Calc->
canal_c= $ caanal ['C'];
       $ Calc->
canal_p= $ caanal ['p'];
       $ Calc->
canal_pt= $ canal ['pt'];
       $ Calc->
Total= $ Total_Price;
       $ Calc->
Save ();
       if (ISset ($ Calcdata ['AD'])) {
           Foreach ($ Calcdata ['AD'] AS $ i= >
$ Add) {
               $ ad= new additioanl ();
               $ AD->
calc_id= $ Calc->
ID;
               $ AD->
Add_n= Value :: WHERE ('TITLE', $ Add) ->
first () ->
title;
               $ AD->
add_c= $ Calcdata ['ADC'] [$ i];
               $ AD->
Add_p= Value :: Where ('Title', $ Add) ->
first () ->
Value;
               $ AD->
add_pt= $ Calcdata ['ADC'] [$ i] * Value :: WHERE ('TITLE', $ Add) ->
first () ->
Value;
               $ AD->
Save ();
               $ Total_Price += $ AD->
add_pt;
               DB :: Table ('Calculations') ->
Update (['Total'= >
 $ Total_Price]);
           }
       }
       Return View ('index', ['Total_price'= >
 $ Total_Price]);
   }

in Web.php and PageController'e All "Pure" Browser -Microsoft Edge

I apologize for the big number of code, I really do not know what kind of info may need to solve it.

Google -I did not find anything, or I do not know how to search

Possible duplicate question: how not to handle data from the form again when updating the sentence after sending

InDevX2021-06-10 10:11:09

In fact, a fairly old problem, with a bunch of solutions .. as an option -redirect to do through the header () or Unset ($ _ post) should help

InDevX2021-06-10 10:11:09

You return the View from the function, and all the entered data remains in the $ _POST array. So that they are cleared, make a redirect from the function to the same page, or just back Return back ();

Anton Mironov2021-06-10 10:11:09