POST is empty depending on the site I use

Asked

Viewed 596 times

2

I have a project in Codeigniter which is in a folder within the domain. The folder structure is as follows:

/domain/Web/project/

I will call it domain and project due to the name of client/website

I can access the site in two ways: www.meudominio.com.br/project or www.projecto.com.br.

But in all the forms I do, the variable $_POST is empty when filled by the site www.projecto.com.br (which should be correct because the customer wishes to access as a site isolated from its root). If I fill the Forms by the site www.meudominio.com.br/project the variable $_POST receives the data normally and I can continue with the navigation.

Is there any way I can make the two Urls receive the POST normally, as if they were one?

Follow the codes of form and the controller, for a form login:

<form method="POST" action="sac/nova_conversa">
    <input type="hidden" name="lojaID" id="lojaID" value="<?= @$lojaID; ?>" />
        <p>
            <label>Nome:</label>
            <input type="text" name="nome" id="nome" />
        </p>
        <p>
            <label>Telefone:</label>
            <input type="text" name="telefone" id="telefone" />
        </p>
        <p>
            <label>E-mail:</label>
            <input type="text" name="email" id="email" />
            <input type="submit" value="Entrar" class="entrar" />
        </p>
        <?PHP if ($this->session->flashdata('errors')) { ?>
            <p class="erro"><?= $this->session->flashdata('errors'); ?></p>
        <?PHP } ?>
    </form>

Controller:

public function nova_conversa() {
    if ($_POST) {
        $data["nome"] = $this->input->post("nome");
        $data["telefone"] = $this->input->post("telefone");
        $data["email"] = $this->input->post("email");

        if (($data["nome"] == "") or ($data["telefone"] == "") or ($data["email"] == "")) {
            $this->session->set_flashdata('errors', 'Digite seus dados');
            redirect("sac");
        } else {
            $usuarioID = $this->sac_model->novo_usuario($data);

            $data["lojaID"] = $this->input->post("lojaID");
            $conversaID = $this->sac_model->nova_conversa($usuarioID, $data["lojaID"]);

            $this->session->set_userdata('chat_usuarioID', $usuarioID);
            $this->session->set_userdata('conversaID', $conversaID);

            redirect("sac/abrir_conversa");
        }
    }
}

Thank you!

  • For this kind of situation, where is <b><input type="hidden" name="lojaID" id="lojaID" value="<?= @$lojaID; ?>" /></b>, you should use it like this <?php echo @$lojaID; ?>, then the item will be completed. If you inspect the code through the F12 Chrome will see that in the method used the value is empty, but if echo is used to print the value it assigns to html.

  • Assuming Apache: you can add your own content .htaccess that deals with the redirect? Looks to me like you’re making one redirect without contemplating the values of $_POST, so the form works in one location but not in the other.

1 answer

1

In the archive routes.php change this line:

$route['default_controller'] = "projeto";

In your file config.php put the following:

$config['base_url'] = '';
$config['index_page'] = '';

Use the following .htaccess in the directory that is mine index.php

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

My project is this way described above, I believe that if change this way will work the same way mine works.

I noticed that the URL is case sensitive so if the site folder name is uppercase, the URL should also be uppercase

If there is no doubt that all this setting is correct then you can check the following, the $route['default_controller'] = "projeto"; is a setting that defines that when accessing your site the first controller that will be loaded is the projeto.php and the method called within it will be the index, if this is redirecting to another method then you should also pass on your data $_POST and $_GET

In short...

www.meudominio.com.br -> default_controller/index -> default_controller/projeto
www.meudominio.com.br/projeto -> default_controller/projeto

That’s probably the explanation for your problem!

Browser other questions tagged

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