How to avoid erasing the form data when sending them in a POST?

0

Hello I have a form and I want to keep the information I capture in the inputs because when sending the information it is deleted and you have to be constantly filling in the inputs and I want to keep the information

<form action="" method="POST">
     <label for="">Servidor</label>
     <input type="text" id="servidor" name="servidor"    
     placeholder="Selecciona el servidor deseado"   >

  <label >Configuracion </label>
  <input type="text"id="configuracion" name="configuracion" placeholder="Selecciona la configuracion deseada"> 
  <button type="submit"  value="registrar" name="boton" id="boton"class="btn btn-primary">Registrar</button>
  </form>
    
asked by Neri Dex 03.01.2019 в 00:12
source

2 answers

0

You could help with session variables, for example:

On your controller where the post arrives:

$_SESSION['servidor'] = $_POST['servidor'];
$_SESSION['configuracion'] = $_POST['configuracion'];

In your view in the imputs:

<form action="" method="POST">
     <label for="">Servidor</label>
     <input type="text" id="servidor" name="servidor"    
     placeholder="Selecciona el servidor deseado" value="<?php echo $_SESSION['servidor'] ?? '' ?>"  >

  <label >Configuracion </label>
  <input type="text"id="configuracion" name="configuracion" placeholder="Selecciona la configuracion deseada" value="<?php echo $_SESSION['configuracion'] ?? '' ?>" > 
  <button type="submit"  value="registrar" name="boton" id="boton"class="btn btn-primary">Registrar</button>
  </form>

the ?? is available from version 7.1 of php if I remember correctly and is the equivalent to the isset, in case you do not have it available use the isset strong>

I hope it serves you. Greetings

    
answered by 03.01.2019 / 16:52
source
0

When sending the values by POST after having clicked on the submit button, these will be saved in the variable $ _POST, you just have to check that they exist in that variable, and it is as simple as doing this:

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>Formulario extenso</title>
	<link rel="stylesheet" href="">
	<script src="funciones/funciones.js"></script>
</head>
<body>
	

	<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
		
		<label for="nombre">Nombre:</label>
		<div id="ocultado">
		<input type="text" class="form-control" name="nombre" id="nombre" value="<?php if(isset($_POST['nombre'])){ echo $_POST['nombre'];} ?>" placeholder="tu nombre aqui">
		<label for="apellido">Apellido</label>
		<input type="text" name="apellido" id="apellido">
		<label for="empresa">Empresa:</label>
		<input type="text" name="empresa" id="empresa" >
		<br>
		<label for="SE">Software Especializado:</label>
		<select multiple name="mul[]" id="SE" size="3" >
			<option value="ACROBAT READER">ACROBAT READER</option>
			<option value="WINRAR">WINRAR</option>
			<option value="WINZIP">WINZIP</option>

		</select>

		<input type="radio" name="programadores" value="LUIS">
		<input type="radio" name="programadores" value="VICTOR">
		<br>
	</div>
		<button type="submit" name="enviar" value="enviar">mandar</button>
	</form>
    
answered by 03.01.2019 в 00:37