Home php as using a hidden tag & lt; Input Type = "Hidden" &...

as using a hidden tag & lt; Input Type = “Hidden” & gt; Transfer the variable by the GET method into the php script?

Author

Date

Category

I’m new to web development. I am trying on the Create Table of Arbitrary Size using the HTML and PHP language. I need to be hidden to store the size of the table and click the button to increase or decrease it. Posted by the code drawing code itself and it works fine, but it is impossible to pass there a variable with a table size. And it is not that the Vedas SuperGlobal Massif GET is empty. I use such a code.

& lt; html & gt;
  & lt; Body & gt;
    & lt; Form Method = "Get" & gt;
      & lt; Input Type = "Hidden" name = "Size" value = "10" & gt;
    & lt; / form & gt;
    & lt;? php include 'php / test.php'; ? & gt; // file in which table is drawn
  & lt; / body & gt;
& lt; / html & gt;

Suggest other storage options for a hidden variable. I will be glad if you still give advice on creating buttons to reduce and increase the size.


Answer 1, Authority 100%

page.php

& lt; html & gt;
  & lt; Body & gt;
    & lt; Form Method = "Get" Action = "Page. PHP" & GT;
      & lt;? php
        If (ISset ($ _GET ['Size'])) {
          $ Size = $ _Get ['Size'];
        } else {
          $ Size = 3;
        }
        If (ISset ($ _GET ['Inc'])) {
          $ Size ++;
        } else {
          if (ISSET ($ _Get ['Dec']) & amp; & amp; ($ Size & gt; 1)) {
            $ Size--;
          }
        }
      ? & gt;
      & lt; Input Type = "Hidden" name = "Size" value = "& lt;? = $ Size? & gt;" & gt;
      & lt; Input Type = "submit" name = "DEC" value = "Reduce" & gt;
      & lt; Input Type = "submit" name = "Inc" value = "Enlarge" & gt;
    & lt; / form & gt;
    & lt;? php
      include 'table.php';
    ? & gt;
& lt; / body & gt;
& lt; / html & gt;

Table.php

& lt; table & gt;
& lt;? php
  Global $ Size;
  For ($ i = 1; $ i & lt; = $ Size; $ i ++) {
    Echo "& lt; TR & GT;";
    For ($ j = 1; $ j & lt; = $ Size; $ j ++) {
      Echo "\ N & LT; TD & GT; Cell $ i: $ J & LT; / TD & GT;";
    }
    Echo '& lt; / tr & gt;';
  }
? & gt;
& lt; / Table & gt;
& lt; style & gt;
  Table, TD {
    Border: 1px Solid Gray;
  }
& lt; / style & gt;

Answer 2

$ _ get empty due to the fact that the form you want to send (submit) to store a variable that changes from the client, you can apply the following tactics:

  1. You form a separate JS script that reads the value of the table size change event (change input-a) and transmits via AJAX
  2. script processor takes a value via $ _ get / $ _ post and generates an HTML table code and gives it back JS script;
  3. JS Skipte gets a response with HTML table code and draws it.

Another option is to change your shape to & lt; Form Method = "Get" Action "/" & gt; . In Action, prescribe the path path where the table will be displayed. Adjust the required & lt; input type = "submit" & gt; either on js make submit molds by pressing the button. Here it is possible to overload a page.

I advise you to use the first method – much better solution.


Answer 3

Your script is available with a global $ _GET array with parameters, simply indicate the Action parameter form.

& lt; html & gt;
  & lt; Body & gt;
    & lt; Form Method = "Get" Action = "/" & gt;
      & lt; Input Type = "Hidden" name = "Size" value = "10" & gt;
    & lt; / form & gt;
    & lt;? php
     Global $ Size;
     $ Size = $ _Get ["Size"]; // Use $ Size for dimension
     if (! $ Size) $ Size = 10; // default meaning
     include 'php / test.php'; ? & gt; // file in which table is drawn
  & lt; / body & gt;
& lt; / html & gt;

But it is better to use JS for this task.


Answer 4

In the Optracks page:

& lt; form method = "get" action = "send-data.php" & gt;
    & lt; Input Type = "Hidden" name = "Size" value = "10" & gt;
    & lt; Input Type = "submit" value = "Send" & gt;
  & lt; / form & gt;

in the recipient page (Send-data.php):

& lt;? php echo $ _get ['size']? & gt; // here 10 is printed

If you want to try POST, then simply replace all the words Get on POST in all pages

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions