Keep text in texbox when reloading a page using PHP

-1

I have an HTML page which is partially built with PHP. The issue is that I have a form where using HTML I have a textbox where with the method onchange="this.form.submit()" where an identification number is written down. With a php code, when sending this textbox and if the length of its content is greater than 0 , a second textbox appears where the user must register a name and in turn, with the method onchange="this.form.submit()" , when it is sent a third appears textbox where the last name of the person is written down. Obviously each time the page is reloaded each textbox retains its content. The problem is that in the case of the second textbox, where the name of the person must be written down, if for example, "Juan Jose" is placed when reloading, only "Juan" appears. I want to show "Juan Jose", that is, all the words. The code I use is the following:

    <b>CI:</b> <input  type="text" name="cedula" id="cedula" onchange="this.form.submit()" onblur="copiar()" value="<?php  $cedul = isset($_POST['cedula']) ? $_POST['cedula'] : null ; echo $cedul;?>"/>
  <?php
  $cedul = isset($_POST['cedula']) ? $_POST['cedula'] : null ;
    if (strlen($cedul)>0) { 
      $nombr = isset($_POST['nombre']) ? $_POST['nombre'] : null ;
      echo "<b>Nombre:</b> <input type='text' name='nombre' id='nombre'  onchange='this.form.submit()' value=$nombr ></>";
   }

   $nombr = isset($_POST['nombre']) ? $_POST['nombre'] : null ;
   $apellid = isset($_POST['apellido']) ? $_POST['apellido'] : null ;

   if (strlen($nombr)>0) { 
     echo "<b>Apellido:</b> <input type='text' name='apellido' id='nombre' id='apellido' onchange='this.form.submit()' value= $apellid> </>";
   }

...    Any help is appreciated. Greetings.

    
asked by Bladsimo 28.09.2018 в 17:37
source

1 answer

0

Although your logic is confusing, reading what you need should be so, since one depends on another, then it must be nested, that is to say in the first case, the name does not exist, but since the cedula arrives now it will exist, in the second case, as the cedula already exists, then the possibility exists that the cedula field will send it empty. for that reason you must always validate first that the cedula is full as well and so suesivamente, I hope to have made me understand and understand.

the code would be like this:

   <b>CI:</b> <input  type="text" name="cedula" id="cedula" onchange="this.form.submit()" onblur="copiar()" value="<?php  $echo isset($_POST['cedula']) ? $_POST['cedula'] : null ; ?>"/>
          //notese que optimice un poco este ternario de aqui
  <?php
  // $cedul = isset($_POST['cedula']) ? $_POST['cedula'] : null ;
  if (isset($_POST['cedula']) && !empty($_POST['cedula'])) { 
    $nombr = $_POST['cedula'];
    echo "<b>Nombre:</b> <input type='text' name='nombre' id='nombre'  onchange='this.form.submit()' value='$nombr'>";
                          //aqui faltaban las comillas
     // $nombr = isset($_POST['nombre']) ? $_POST['nombre'] : null ;
      //con este validas si si llego y si no esta vacio
     if (isset($_POST['nombre']) && !empty($_POST['nombre'])) { 
       $apellid = $_POST['nombre'];
       echo "<b>Apellido:</b> <input type='text' name='apellido' id='apllido' id='apellido' onchange='this.form.submit()' value= '$apellid' >";
     }
  }

I hope you serve and you tell me

    
answered by 28.09.2018 в 18:33