How to make dynamic display in HTML + PHP?

0

I'm studying HTML and PHP, but there are things I can not figure out how to do it. After all, how do I get input data to process them? As in the keyboard with those <input type="text"> text fields. And after that, how do I adapt the page interface or update it with the new interface based on the data collected?

For ease, I put an example where you provide a square matrix size and according to the provided value the page interface makes available cells to be filled. The gif below illustrates this idea very simply, showing page changes to every modification of the string in the "order" field.

I thank you in advance for clarifying.

    
asked by anonymous 15.11.2017 / 01:07

1 answer

1

I discovered how it does, without the need for ajax, javascript, table and others. I'll explain by example. I made the whole square array dynamic interface in the "index.php" file.

First, I put the field that should update the interface. Using <form action="index.php" method="post"> , entry by field <input name="numeroDeEquações" type="text" /> will reopen the page "index.php" with variable $_POST['numeroDeEquações'] updated with the value that was passed in the field.

The second and final step is to determine the interface according to the value of the field. To do this, first check that $_POST['numeroDeEquações'] has been set. Then I check if the value is valid. According to the conditions, the interface is built.

Simple like that. Follow the code and thank everyone who tried to help.

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Matriz Quadrada</title>
    </head>
    <body>

        <form action="index.php" method="post">
            Ordem: &nbsp&nbsp <input name="numeroDeEquações" type="text" /><br />
        </form>

        <?php
            $inválido = true ;
            if( isset($_POST['numeroDeEquações']) ){
                $numeroDeEquações = $_POST['numeroDeEquações'] ;
                if( $numeroDeEquações>1 && $numeroDeEquações<10 ){
                    $inválido = false ;
                    for( $índice1=0 ; $índice1<$numeroDeEquações ; $índice1++ ){
                        for( $índice2=0 ; $índice2<$numeroDeEquações ; $índice2++ ){
                            echo( "<input size=1 type='text' />" ) ;
                        }
                        echo( "<br>" ) ;
                    }
                }
            }
            if( $inválido ) echo( "<br>Forneça um número de 2 a 9." ) ;
        ?>

    </body>
</html>
    
15.11.2017 / 02:12