Ver Mensaje Individual
  #5 (permalink)  
Antiguo 31/07/2014, 02:32
Avatar de airofued
airofued
 
Fecha de Ingreso: julio-2014
Mensajes: 3
Antigüedad: 9 años, 9 meses
Puntos: 0
Respuesta: Llevar variables de una pagina a otra en html5

Logré solucionar el problema de la siguiente forma.

Agregué la siguiente tag al final de input "required"

O sea,

<input class="Formulario" name="Nombre" type="text" placeholder="Escriba su nombre" autocomplete="on" autofocus="autofocus" required>

y cambié el input del botón

Ejem:

<input id="submit" type="button" name="submit" value="Voltar" onclick="enviar('Formulario.html')"/>
</form>

Nuevo:

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

Y tuve también que cambiar form por esto:

<form method="post" action="resultado.php" >

El siguiente código html es el que estaba malo:

Cita:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8"/>
<title>Formulario</title>
<style>
/** Css Simple **/
label {
display:block;
margin-top:20px;
letter-spacing:1px;
}
.formulario {
display:block;
margin:0 auto;
width:510px;
color: #666666;
font-family:Arial;
}
#submit {
width:85px;
height:35px;
border:none;
margin-top:20px;
cursor:pointer;
color: blue;
font-weight: bolder;
}

li {
color: red;
list-style: none;
text-align: center;
margin: 15px;
font-weight: bold;
}
h2 {
color: #003399;
}
input#FormularioCentrado{
text-align: center;
}
body {
background-color: #cecece;
}
</style>
<script>
function enviar(formulario){
document.testeum.action=formulario;
document.testeum.submit();
}

</script>
</head>

<body>
<div id="interfaceDoUsuario">
<!--- Formulario -->
<section class="formulario">
<ul>
<li>
<h2>Formulario</h2>
</li>
<li>
<form name="testeum" action="resultado.php" method="post">
<label for="name">Nome:</label>
<input id="FormularioCentrado" type="text" placeholder="" autocomplete="on"required>
</li>
<li>
<label for="apelido">Apelido:</label>
<input id="FormularioCentrado" type="text" placeholder="" autocomplete="on" required>
</li>
<li>
<label for="cidade">Cidade:</label>
<input id="FormularioCentrado" type="text" placeholder="" autocomplete="on" required>
</li>
<li>
<label for="idade">Idade:</label>
<input id="FormularioCentrado" type="text" placeholder="" autocomplete="on" required>
</li>
<!-- Botão de Submit -->
<li>
<input id="submit" type="submit" name="submit" value="Calcular"><br>
</form>
</li>
</ul>
</section>

</div>

</body>

</html>
Este es el nuevo corregido:

Cita:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8"/>
<title>Calcular</title>
<style>
/** Css Simple **/
label {
display:block;
margin-top:20px;
letter-spacing:1px;
}
.formulario {
display:block;
margin:0 auto;
width:510px;
color: #666666;
font-family:Arial;
}
#submit {
width:85px;
height:35px;
border:none;
margin-top:20px;
cursor:pointer;
color: blue;
font-weight: bolder;
}

li {
color: red;
list-style: none;
text-align: center;
margin: 15px;
font-weight: bold;
}
h2 {
color: #003399;
}
input.FormularioCentrado {
text-align: center;
}
body {
background-color: #cecece;
}
</style>
</head>

<body>
<div id="interfaceDoUsuario">
<!--- Formulario -->
<section class="formulario">
<ul>
<li>
<h2>Calcular</h2>
</li>
<li>
<form method="post" action="resultado.php">
<label for="A">A:</label>
<input class="FormularioCentrado" name="Nombre" type="text" placeholder="Escriba su nombre" autocomplete="on" autofocus="autofocus" required><br>
</li>
<li>
<label for="B">B:</label>
<input class="FormularioCentrado" name="Apellido" type="text" placeholder="Escriba su apellido" autocomplete="on" required><br>
</li>
<li>
<label for="C">C:</label>
<input class="FormularioCentrado" name="Ciudad" type="text" placeholder="Escriba su ciudad" autocomplete="on" required><br>
</li>
<li>
<label for="D">D:</label>
<input class="FormularioCentrado" name="Edad" type="text" placeholder="Escriba su edad" autocomplete="on" required><br>
</li>
<!-- Botão de Submit -->
<li>
<input id="submit" type="submit" name="submit" value="Resultado"><br>
</form>
</li>
</ul>
</section>

</div>

</body>

</html>

Luego de arreglar mi código HTML tuve que crear un archivo .php con el siguiente código:

Cita:
<?php
if (get_magic_quotes_gpc() === 1) {
$_POST['Nombre'] = stripslashes($_POST['Nombre']);
$_POST['Apellido'] = stripslashes($_POST['Apellido']);
$_POST['Ciudad'] = stripslashes($_POST['Ciudad']);
$_POST['Edad'] = stripslashes($_POST['Edad']);
}
$A = $_POST['Nombre'];
echo '<p>Su nombre es: ' . htmlspecialchars($Nombre) .'</p>';
$B = $_POST['Apellido'];
echo '<p>Su apellido es: ' . htmlspecialchars($Apellido) .'</p>';
$C = $_POST['Ciudad'];
echo '<p>Su ciudad es: ' . htmlspecialchars($Ciudad) .'</p>';
$D = $_POST['D'];
echo '<p>Su edad es: ' . htmlspecialchars($Edad) .'</p>';
?>
Y esa fue la solución.