Jump to content

Multi-Step form Validation


Beedy555

Recommended Posts

Hi, i am trying to add validation to a multi-step form which goes through three stages, specifically at the second stage, to ensure that the user cannot continue if the form fields are left blank. I have tried to create an array which lists all required fields, and then loops through to check if they have been filled out correctly, however this approach did not work. I am using three static forms, with an action named "ad.php" which goes through each stage.

 

The form data i am working with looks like:

<div id="block-type-right">					
<?					
echo '<input type="text" name="nombre_emp"';
if( $_SESSION['add_ad_nombre_emp'] != "" )	echo ' value="'.$_SESSION['add_ad_nombre_emp'].'"';
echo '>';					
?>
</div>

 

there are several fields like this in the form i am using, and i need to ensure that they are filled out, before the user can progress to the third stage of the form.

 

the "ad.php" code looks like:

 

Header("Location: ".ROOT."insertar-anuncio/?step=2");

}elseif( $_POST['step'] == 2 ){

$_SESSION['add_ad_nombre_emp'] = addslashes($_POST['nombre_emp']);
$_SESSION['add_ad_direccion'] = addslashes($_POST['direccion']);
$_SESSION['add_ad_cp'] = addslashes($_POST['cp']);
$_SESSION['add_ad_sid'] = $_POST['sid'];
$_SESSION['add_ad_ssid'] = $_POST['ssid'];
$_SESSION['add_ad_pid'] = $_POST['pid'];
$_SESSION['add_ad_eid'] = $_POST['eid'];
$_SESSION['add_ad_empleados_id'] = $_POST['empleados_id'];
$_SESSION['add_ad_ebdita_id'] = $_POST['ebdita_id'];
$_SESSION['add_ad_volumen_id'] = $_POST['volumen_id'];
$_SESSION['add_ad_precio_id'] = $_POST['precio_id'];
$_SESSION['add_ad_other_eid'] = addslashes($_POST['other_eid']);
$_SESSION['add_ad_other_precio'] = addslashes($_POST['other_precio']);
$_SESSION['add_ad_other_ebdita'] = addslashes($_POST['other_ebdita']);
$_SESSION['add_ad_other_empleados'] = addslashes($_POST['other_empleados']);
$_SESSION['add_ad_other_volumen'] = addslashes($_POST['other_volumen']);
$_SESSION['add_ad_poblacion'] = addslashes($_POST['poblacion']);
$_SESSION['add_ad_ano_creacion'] = $_POST['ano_creacion'];
$_SESSION['add_ad_superficie'] = $_POST['superficie'];
$_SESSION['add_ad_titulo_1'] = addslashes($_POST['titulo_1']);
$_SESSION['add_ad_titulo_2'] = addslashes($_POST['titulo_2']);
$_SESSION['add_ad_actividad'] = addslashes($_POST['actividad']);
$_SESSION['add_ad_description'] = addslashes($_POST['description']);
$_SESSION['add_ad_razon'] = addslashes($_POST['razon']);
$_SESSION['add_ad_plan'] = $_POST['plan'];

Header("Location: ".ROOT."insertar-anuncio/?step=3");

 

however there is not validation for each of the fields. Some guidance would be greatly appreciated. Thankyou

 

Link to comment
https://forums.phpfreaks.com/topic/238756-multi-step-form-validation/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.