How do I receive data from a form using the HTML class attribute?

2

I know it's possible to "call" the name of a form into a php file. But in a php file, it is possible to "call" a class made in a form to get the same effect of "calling" the name, that is, how to send data from a form to a php file through a class? >

Specifying, to send through the name I use the following php code:

$variável = $_POST['name'];

But how do I if instead of name is a class?

OBS 1; I already tried to replace the name with the class, but it did not work. OBS 2; I do not have access to the form file, so I can not just enter a name to use the code mentioned above.

Form:

<table>
    <form name="form" method="post" action="">
        <tr>
            <td>
                <label>Email</label>
            </td>
            <td>
                <input type="text" name="email">
            </td>
        </tr>
        <tr>
            <td>
                <label>Senha</label>
            </td>
            <td>
                <input type="password" name="senha">
            </td>
        </tr>
        <input type="submit" class="botao-login" value="Login">
    </form>
</table>

Note that the login button does not have the name.I'm trying to make a function in php for login authentication, whose function is to "isset". Namely, pressing the button the following php code runs: / p>

php code

<?php
$usuario = $_POST['usuario'];
$senha   = $_POST['senha'];
$botao   = $_POST['é aqui que costumo por o name do botão'];

if (isset($botao)) {
    if ($usuario == "" or $senha == "") {
        $mensagem = "Campo em branco";
    } elseif ($usuario != $_COOKIE['usuario'] or $senha != $_COOKIE['senha']) {
        $mensagem = "Usuáriorio ou senha inválido";
    } elseif ($usuario == $_COOKIE['usuario'] && $senha == $_COOKIE['senha'] && $_COOKIE['tipo_conta'] == "administrador") {
        header("Location:php/administrador.php");
    } elseif ($usuario == $_COOKIE['usuario'] && $senha == $_COOKIE['senha'] && $_COOKIE['tipo_conta'] == "registrado") {
        header("Location:php/registrado.php");
    } elseif ($usuario == $_COOKIE['usuario'] && $senha == $_COOKIE['senha'] && $_COOKIE['tipo_conta'] == "indefinido") {
        header("Location:php/indefinido.php");
    }
}
?>

The php code is not on the same page that the form is found in. As mentioned earlier, the php code is executed by pressing the button, but for the code to work, it is feasible that it has a name so I can Is there any php code for the "isset" function to work without the need for a name?

    
asked by anonymous 17.10.2015 / 21:59

1 answer

3

The class and id selectors are attribute selectors, and are typically used to identify an html element. In common cases, these elements are used to identify specific elements to be stylized using (CSS) style sheets, with the id attribute being used to identify elements with unique properties, and the class attribute for multiple elements with the same properties.

The name attribute is used to reference a javascript element, or a reference to the form, after it has been submitted. Basically they work as banners when submitting a form. For example, if you have several rad with different id , and we put the same attribute name , during form submission, only the value the selected radio button will be passed. «1»

At the end, we come to the conclusion that receiving form data via class or id attributes is not possible.

You can even try a few laps, using Ajax , and reading the values of the fields identified with the id attribute instead of name , but at the end of the process, it is necessary to define a method for requesting, in order to exchange data typed in the form, with the script on the server, remembering that the requests to the server only accept identifiers of type name .

Example:

<html>
<body>
<form>
<input type="text" name="nome" value="Meu nome com name"/>
<input type="text" id="nome" value="Meu nome com id"/>  
<button onclick="mostra()">Mostrar</button>
</form>
<script>
function mostra(){
    var nome = document.getElementsByName('nome')[0].value;
    var id = document.getElementById('nome').value;

    alert('atributo name: ' + nome + '\n  atributo id: ' + id);
}
</script>

</body>
</html>
    
18.10.2015 / 00:52