86 lines
2.5 KiB
PHP
86 lines
2.5 KiB
PHP
<?php
|
|
|
|
$errors = array(); // array to hold validation errors
|
|
$data = array(); // array to pass back data
|
|
|
|
function setheaders() {
|
|
$fp = fopen('registro.csv', 'w');
|
|
$cabezal = array('Nombre', 'Apellido','TipoDoc','Documento',
|
|
'Direccion','Pais','Ciudad', 'Telefono', 'Email',
|
|
'Profesión','Financiación','Detalle Financiación');
|
|
fputcsv($fp,$cabezal);
|
|
fclose($fp);
|
|
}
|
|
|
|
function registrar($fila) {
|
|
$fp = fopen('registro.csv', 'a');
|
|
fputcsv($fp,$fila);
|
|
fclose($fp);
|
|
}
|
|
|
|
// validate the variables ======================================================
|
|
$data['nombre'] = $_POST['nombre'];
|
|
$data['apellido'] = $_POST['apellido'];
|
|
$data['tipodoc'] = $_POST['doctype'];
|
|
$data['nrodoc'] = $_POST['docnro'];
|
|
$data['direccion'] = $_POST['dir'];
|
|
$data['pais'] = $_POST['pais'];
|
|
$data['ciudad'] = $_POST['ciudad'];
|
|
$data['telefono'] = $_POST['tel'];
|
|
$data['email'] = $_POST['email'];
|
|
$data['profesion'] = $_POST['profesion'];
|
|
$data['financiacion'] = $_POST['financiacion'];
|
|
$data['detallefinan'] = $_POST['detallefinan'];
|
|
|
|
if (empty($_POST['nombre']))
|
|
$errors['nombre'] = 'Nombre is required.';
|
|
|
|
if (empty($_POST['apellido']))
|
|
$errors['apellido'] = 'Apellido is required.';
|
|
|
|
if (empty($_POST['doctype']))
|
|
$errors['doctype'] = 'No seleccionó un tipo de doc';
|
|
|
|
if (empty($_POST['docnro']))
|
|
$errors['docnro'] = 'No ingreso un documento';
|
|
|
|
if (empty($_POST['dir']))
|
|
$errors['dir'] = 'No ingreso una direccion';
|
|
|
|
if (empty($_POST['pais']))
|
|
$errors['pais'] = 'Ingrese el pais de presedencia';
|
|
|
|
if (empty($_POST['ciudad']))
|
|
$errors['ciudad'] = 'Ingrese ciudad de presedencia';
|
|
|
|
if (empty($_POST['tel']))
|
|
$errors['ciudad'] = 'Telefono de contacto vacio o incorrecto';
|
|
|
|
if (empty($_POST['email']))
|
|
$errors['email'] = 'E-Mail de contacto vacio o incorrecto';
|
|
|
|
if (empty($_POST['profesion']))
|
|
$errors['email'] = 'indique profesion';
|
|
|
|
if( !file_exists("registro.csv"))
|
|
setheaders();
|
|
|
|
// return a response ===========================================================
|
|
// if there are any errors in our errors array, return a success boolean of false
|
|
if ( ! empty($errors)) {
|
|
|
|
// if there are items in our errors array, return those errors
|
|
$data['success'] = false;
|
|
$data['errors'] = $errors;
|
|
}
|
|
else {
|
|
$fila = $data;
|
|
registrar($fila);
|
|
$data['success'] = true;
|
|
$data['message'] = 'Registro exitoso';
|
|
}
|
|
|
|
// return all our data to an AJAX call
|
|
echo json_encode($data);
|
|
|
|
?>
|