HTML
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Registro de Estado Civil</title>
</head>
<body>
<h1>Registro de Estado Civil</h1>
<form action="php/procesar_formulario.php" method="post">
<label for="nombre">Nombre:</label>
<input type="text" name="nombre" id="nombre" required><br>
<label for="apellidoPaterno">Apellido Paterno:</label>
<input type="text" name="apellidoPaterno" id="apellidoPaterno"
required><br>
<label for="apellidoMaterno">Apellido Materno:</label>
<input type="text" name="apellidoMaterno" id="apellidoMaterno"
required><br>
<label for="ci">Carnet de Identidad:</label>
<input type="text" name="ci" id="ci" required><br>
<label for="estadoCivil">Estado Civil:</label>
<select id="estadoCivil" name="estadoCivil" required>
<option value="soltero">Soltero/a</option>
<option value="casado">Casado/a</option>
<option value="divorciado">Divorciado/a</option>
<option value="viudo">Viudo/a</option>
</select><br>
<input type="submit" value="Enviar">
</form>
</body>
</html>
PHP
<?php
$nombre = $_POST['nombre'];
$apellidoPaterno = $_POST['apellidoPaterno'];
$apellidoMaterno = $_POST['apellidoMaterno'];
$ci = $_POST['ci'];
$estadoCivil = $_POST['estadoCivil'];
$generarMensaje = function($nombre, $apellidoPaterno, $apellidoMaterno,
$ci, $estadoCivil) {
switch ($estadoCivil) {
case 'soltero':
return "$nombre $apellidoPaterno $apellidoMaterno (CI: $ci)
está soltero/a";
case 'casado':
return "$nombre $apellidoPaterno $apellidoMaterno (CI: $ci)
está casado/a";
case 'divorciado':
return "$nombre $apellidoPaterno $apellidoMaterno (CI: $ci)
está divorciado/a";
case 'viudo':
return "$nombre $apellidoPaterno $apellidoMaterno (CI: $ci)
está viudo/a";
default:
return "Error al ingresar el estado civil";
}
};
$mensaje = $generarMensaje($nombre, $apellidoPaterno, $apellidoMaterno,
$ci, $estadoCivil);
echo $mensaje;
?>