Post repeated on sending the data to the controller, how do I solve it?

0

I'm trying to develop a php mvc system but I came across this problem in Create. The post is sending multiple repeated data I do not know why this is happening.

Myviewcreateislikethis

<formid="form1" action="<?php echo BASE_URL; ?>Products/Create" method="post">
    <div class="form-group">
        <label for="exampleInputEmail1">Nome</label>
        <input type="text" value="" class="form-control" name="name" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email">
    </div>

    <button type="submit" class="btn btn-success">Cadastrar</button><br><br>
</form>

There is only one field because I was testing, now my method in the controller

public function Create(){
        $this->view->title = 'Novo';
        $this->view->dados = $_POST;

        if($_POST){
            //$this->view->errors = 'Não é um número';

            var_dump($_POST);

            $result = $this->Create($_POST['name']);

            if($result == true){
                $this->Redirect('Index');
            }

            $this->view->Render('Create');
            exit;
        }
        var_dump($_POST['name']);
        //$this->view->dados = $_POST;



        $this->view->Render('Create');
    }

I put the var_dump it was there that I saw why it gave error in the insert, it is multiplying the post now I do not understand why.

    
asked by anonymous 01.05.2018 / 17:06

1 answer

1

The post is not being sent several times, you are reading it several times, when calling a function inside the function itself, creating an infinite loop:

You have a function Create and within it it calls Create :

public function Create(){
    //...
   $result = $this->Create($_POST['name']);
    //...
}

As your code is not making much sense, note that you create the Create function but it does not receive any parameters, but within it you call the same function by passing a variable

    
02.05.2018 / 03:51