0
I’m developing a Fomulário for a project and I needed to add images only that these images represent the place of the client’s chairs and when the user clicks on any of these chairs the place is marked, only that it is necessary to have this marked location displayed on another page next to the other form data like name, password, etc. Thus remaining:
Name: Java
Password: 123
Chosen chair: 1 - A , (And other chairs if the user has chosen more than one)
Unlike the form these images representing the client’s place are inside a div(making it easier to style them by CSS), and I came across the following error when I tried to create a variable in my PHP file for it to appear as the other information typed by the user:
Notice: Undefined index: tCadeira1 in C:\xampp\www\teste\dados.php on line 54
"tCadeira1" was the variable I created in PHP. Now I don’t know how to do it because I tried to put the closing of the tag form after div’s, inside the div but it’s no use.
My HTML file:
<form action="dados.php" method="post">
<input type="text" id="cNome" name="tNome" title="Com no máximo 20 letras" size="20" maxlength="20" placeholder=" Digite Seu Nome"/>
<input id="submit" type="image" src="imagens/ButtonAceitar.png" />
<input type="reset" id="resetar" value="" />
</form>
<div id="cadeiras">
<img src="imagens/cadeiraAzul.png" name="tCadeira1" onClick="cor(this)">
<img src="imagens/cadeiraAzul.png" name="tCadeira2" onClick="cor(this)">
<img src="imagens/cadeiraAzul.png" name="tCadeira3" onClick="cor(this)">
<img src="imagens/cadeiraAzul.png" name="tCadeira4" onClick="cor(this)">
</div>
My PHP file:
<?php
$nome = $_POST["tNome"];
$cadeira = $_POST["tCadeira1"];
echo "$nome, obrigado por se cadastrar e comprar o seu ingresso em nosso site.<br>Cadeira(as) escolhida(as): $cadeira ";
?>
My JS file:
function cor(e) {
if (e.getAttribute("src") == "imagens/cadeiraAzul.png") {
e.setAttribute("src", "imagens/cadeiraPreta.png");
}
else {
e.setAttribute("src", "imagens/cadeiraAzul.png");
}
}
Show solutions with possible tag languages of this question, if possible.
I tried to put the input but it did not recognize the same way, I tried to put the tag form after the div and when I clicked on the image it redirected to the other page with the user data containing the same error.
– Lone Tonberry
@Lonetonberry inputs are inside the FORM? No? If not it will not send even
– Guilherme Nascimento
When I did what you said I tried with the FORM tag above the div and it was not after tried to put after and it switched to the page.
– Lone Tonberry
It is not above, the inputs have to be within
<form> </form>
, no use putting away.– Guilherme Nascimento
Yes but I just want to add to the form apart from appearing the data typed by the user also appear typed on the other page the chairs chosen with onClick.
– Lone Tonberry
@Lonetonberry but you’re already saying something else, sorry to be honest, it’s not bad, but I think you don’t even know the basics of HTML and you’re driving all this like a runaway car, a lot of your mistake is for skipping the basics. For example, what the function
cor()
does? You didn’t inform. I’m not saying anything badly, I’m telling you to learn the best way possible without suffering so much.– Guilherme Nascimento
I will edit by placing this part of the JS, it changes the color of the chair passing the impression that it was selected by the user and if he clicks again it changes to the previous color, doing this with two images only.
– Lone Tonberry