Send 10 values using the POST method, the values should be entered in a vector

Asked

Viewed 70 times

-4

The goal is the following: send 10 values using the POST method through the form, and insert them into a vector, which will later be printed.

Anyone who can help me thank you.

  • How so vector ? The 10 values that will be sent by the form you want inside an array ? That’s it ?

  • Like this, I have two input field in the form, one number type and the other Ubmit, when I submit I want the number entered in the number field to go to a position of the array, each new number inserted in a new position, and then with the vector already completed with the 10 numbers, print it out. I don’t know if it’s too clear...

  • All the code that already has for the purpose you indicated is useful and so should be put in the question, focusing on your real doubt, what you are not able to do in this code.

  • When you commit, the number that was in the input has to go to a specific position in the array ?

  • No, it will be inserted in the count of the array itself, ex: typed 23, goes to position [0], typed 78, goes to position [1]....

  • Welcome! Next time you ask a question, try asking it according to this post https://answall.com/help/mcve

  • it would also be interesting to read this post https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079

  • Thank you all for the tips! next I will try to follow the post indicated by Leo Caracciolo.

Show 3 more comments

1 answer

0


According to this comment by the author

"I have two input fields in the form, one type number and the other Ubmit, when I submit I want the number entered in the number field to go to a position of the array, each new number inserted in a new position, and then with the vector already complete with the 10 numbers, print it."

One of the ways to get this result is by using Sesssions.

PHP

session_start();

if(!empty($_POST['num']) && isset($_POST['num']) ){ 

    //contagem do numero de vezes que o formulário foi submetido
    $_SESSION['dez']=$_SESSION['dez']+1;

    $numPost = $_POST['num'];

    if ($_SESSION['num']==""){
        $_SESSION['num'] = $numPost;
    }else{
        $_SESSION['num'] = $_SESSION['num'].",".$numPost;
    }

    if ($_SESSION['dez']==10){  
        $meuarray = explode(',', $_SESSION['num']);
        print_r($meuarray);
        session_destroy();
    }

}

HTML

<form action="" method="post"> 
    <label><input type="number" name="num" value="" required><br>
    <input type="submit">
</form>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.