Direct access Action Form

Asked

Viewed 35 times

0

Speak guys, recently I started studying php and I’m facing some problems, the most recent was the following.

I have a login/registration form and we have the following code.

<form action="/includes/login/class_registro.php" method="post">
            <div class="input-container">
                <input type="text" id="reg_username" required="required" name="username" autocomplete="off" />
                <label for="reg_username">Usuario</label>
                <div class="bar"></div>
            </div>
            <div class="input-container">
                <input type="email" id="reg_email" required="required" name="email" autocomplete="off"/>
                <label for="reg_email">Email</label>
                <div class="bar"></div>
            </div>
            <div class="input-container">
                <input type="password" id="reg_pwd" required="required" name="password" autocomplete="off"/>
                <label for="reg_pwd">Senha</label>
                <div class="bar"></div>
            </div>
            <div class="input-container">
                <input type="password" id="reg_confirm_pwd" required="required" autocomplete="off"/>
                <label for="reg_confirm_pwd">Repita a senha</label>
                <div class="bar"></div>
            </div>
            <div class="button-container">
                <button name="btn_rg" value="enviar"><span>Concluir</span></button>
            </div>
        </form>

The problem is that if the user does www.meusite.com.br/includes/login/class_registro.php he can access the file normally, then I did the following::

//Verifica se o acesso foi realizado diretamente pela URL
$enviou = (isset($_POST["btn_rg"]) && !empty($_POST["btn_rg"])) ? true :          false;
if (!$enviou) {
header("Location: http://www.meusite.com.br/login");
}
//Verifica se o acesso foi realizado diretamente pela URL

But I was wondering if there would be some "better" way to do this, the same happens for www.meusite.com.br/includes/login/class_login.php

  • more simplified, dispenses with if ... and puts only $sent = ((isset($_POST["Submit"]) && !Empty($_POST["Submit"])) ? header("Location: http://www.meusite.com.br/login") : false;

2 answers

0

Instead of using

<button name="btn_rg" value="enviar"><span>Concluir</span></button>

try to use

<input type="submit" value ="Enviar">

Served?

  • But the form is being sent normally Herbert, my problem is to make the url to which the form is being sent which is /includes/login/class_registro.php not to be accessed directly.

  • 1

    Did you ever test it? The type button was not meant to be used to give a Submit in the form ... I think the moment you use Submit in the form it will assign the method only to the click of the button ...

0

Gentlemen, I’m having a similar problem. Except my action doesn’t work. It worked a few months ago, but I didn’t keep the solution and when I went back to work on the project, there’s the error again.

<div class="container">

<form class="form-horizontal" id="frmcontatoazul" action="loja/controller/envio.php" method="get">
  <fieldset>

    <!-- Form Name -->
    <legend>Contato</legend>

    <!-- Text input-->
    <div class="form-group">
      <label class="col-md-4 control-label" for="txtinputnome">Nome</label>  
      <div class="col-md-8">
        <input id="txtinputnome" name="txtinputnome" placeholder="Escreva seu nome completo" class="form-control input-md" required="required" type="text" />
        <span class="help-block">help</span>  
      </div>
    </div>

    <!-- Text input-->
    <div class="form-group">
      <label class="col-md-4 control-label" for="txtinputemail">Email</label>  
      <div class="col-md-8">
        <input id="txtinputemail" name="txtinputemail" placeholder="Coloque um email válido" class="form-control input-md" required="required" type="email" />
        <span class="help-block">help</span>  
      </div>
    </div>

    <!-- Textarea -->
    <div class="form-group">
      <label class="col-md-4 control-label" for="txtinputarea">Mensagem</label>
      <div class="col-md-8">                     
        <textarea class="form-control" id="txtinputarea" rows="6" name="txtinputarea" placeholder="Digite sua Pergunta"></textarea>
      </div>
    </div>

    <!-- Button -->
    <div class="form-group">
      <label class="col-md-4 control-label" for="btnenviar"></label>
      <div class="col-md-8">
        <button id="btnenviar" name="btnenviar" class="btn btn-primary btn-lg">Enviar</button>
        <?php
          var_dump($_GET);
        ?>
      </div>
    </div>


  </fieldset>
</form>

Now I’ll send you the structure of my files. And a photo of the page I’m creating. I’m using the Smarty php engine. I already tried "sending", the complete path as it is, sending.php, the way with sending.php at the end, only with sending and nothing works.

Browser other questions tagged

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