Women in Technology

Hear us Roar



Article:
  PHP Form Handling
Subject:   hi!!! from Lima Perú
Date:   2006-01-27 14:31:04
From:   julito_montoya
hi there I just modified your source code hope to help somebody!!
byeee
Julio
gugli100@gmail.com




<?php



function validate_form(){
echo "<br>validado";
if (isset( $_POST['input1'] )) $input1 = $_POST['input1'];
if (isset( $_POST['input2'] )) $input2 = $_POST['input2'];
if (isset( $_POST['input3'] )) $input3 = $_POST['input3'];

if ($input1==1)
$ListaErrores["Error1"]="Ingrese la 1";
if ($input2==2)
$ListaErrores["Error2"]="Ingrese la 2";
if ($input3==3)
$ListaErrores["Error3"]="Ingrese la 3";

return $ListaErrores;
}



function show_form(){

if ($num_args = func_num_args()>0)
$Errores=func_get_arg(0);


echo '<form method="POST" action="';
echo $_SERVER['PHP_SELF'];
echo '">';
echo 'NUMBER1 <input name="input1" type="text" />'; echo $Errores["Error1"]; echo "
";
echo 'NUMBER2 <input name="input2" type="text" />'; echo $Errores["Error2"]; echo "
";
echo 'NUMBER3 <input name="input3" type="text" />'; echo $Errores["Error3"]; echo "
";
echo '<input type="hidden" name="_submit_check" value="1"/>
<input type="submit" name="Order">
</form>
';
}


function process_form(){
echo "
procesado";
//ejecuto el controliu

}



//--------------------------------------------------------------------------


if (array_key_exists('_submit_check',$_POST)) {
// If validate_form() returns errors, pass them to show_form()
if ($form_errors = validate_form()) {
show_form($form_errors);
} else {
// The submitted data is valid, so process it
process_form();
}
} else {
// The form wasn't submitted, so display
show_form();
}



?>

Full Threads Newest First

Showing messages 1 through 3 of 3.

  • hi!!! from Lima Perú
    2006-04-16 07:54:42  MarcelJong [View]

    Hello Julito. When I run this code exactly as stated here I get the following error messages:

    Notice: Undefined variable: Errores in c:\data\dev\forms\test.php on line 29
    NUMBER2
    Notice: Undefined variable: Errores in c:\data\dev\forms\test.php on line 31
    NUMBER3
    Notice: Undefined variable: Errores in c:\data\dev\forms\test.php on line 33
    • hi!!! from Lima Perú
      2007-08-26 05:16:00  julito_montoya [View]

      Hello MarcelJong,
      I just review the code and works fine.
      Maybe is the version of your Apache/PHP
      bye
    • hi!!! from Lima Perú
      2007-12-05 22:10:54  pot [View]