Envío de formularios PHP con respuestas en blanco eliminadas: detener el envío del mensaje del cuerpo si el campo está en blanco

versión corta de php Tengo un formulario con dos partes. Un solicitante y cosolicitante. Estoy tratando de obtenerlo de modo que si los campos de cosolicitante están vacíos o no se requierenphp el archivo no publicará todos los campos en blanco al enviarlo, ya que termino con dos páginas de títulos y ninguna entrada. El formulario se envía por correo electrónico en Enviar.

Acabo de agregar la sección de cosolicitante y está ocultadiv que se muestra cuando se selecciona una casilla de verificación.

Esta es la página en la que estoy trabajando.https://sundenmanagement.com/home1/index.php/test Código PHP completo: estoy tratando de obtener todos los campos con _co al final solo enviar cuando hay entrada de texto. entonces, si no hay un solicitante conjunto, no imprimirá todos los títulos presentados.

($ body_message. = 'Nombre:'. $ field_first_name_co. "\ r \ n";) estas secciones se imprimen como Nombre: y no quiero que se impriman si están en blanco

<?php
$field_rental_address = $_POST['ra_rental_address'];
$field_date_required = $_POST['ra_date_required'];
$field_first_name = $_POST['ra_first_name'];
$field_middle_name =$_POST['ra_middle_name'];
$field_last_name = $_POST['ra_last_name'];
$field_all_occupants = $_POST['ra_all_occupants'];
$field_num_pets = $_POST['ra_num_pets'];
$field_type_pets = $_POST['ra_pettype'];
$field_cur_phone = $_POST['ra_cur_phone'];
$field_cur_email = $_POST['ra_cur_email']; 
$field_dob = $_POST['ra_dob'];  
$field_sin = $_POST['ra_sin'];
$field_dl_num = $_POST['ra_dl_num'];
$field_dl_issued_prov= $_POST['ra_dl_issued_prov'];
$field_dl_issued_date = $_POST['ra_dl_issued_date'];
$field_dl_expires = $_POST['ra_dl_expires'];
$field_car_one_year =$_POST['ra_car_one_year'];
$field_car_one_make =$_POST['ra_car_one_make'];
$field_car_one_color =$_POST['ra_car_one_color'];
$field_car_one_plate =$_POST['ra_car_one_plate'];
$field_car_one_province =$_POST['ra_car_one_province'];
$field_car_two_year =$_POST['ra_car_two_year'];
$field_car_two_make =$_POST['ra_car_two_make'];
$field_car_two_color =$_POST['ra_car_two_color'];
$field_car_two_plate =$_POST['ra_car_two_plate'];
$field_car_two_province =$_POST['ra_car_two_province'];
$field_ref_one =$_POST['ra_ref_one'];
$field_ref_two =$_POST['ra_ref_two'];
$field_cur_address = $_POST['ra_cur_address'];  
$field_cur_city = $_POST['ra_cur_city']; 
$field_cur_province = $_POST['ra_cur_province'];
$field_cur_postal = $_POST['ra_cur_postal'];
$field_cur_rent = $_POST['ra_cur_rent'];
$field_residing_length = $_POST['ra_cur_residing_length'];  
$field_cur_reason_leaving = $_POST['ra_cur_reason_leaving'];
$field_cur_landlord =$_POST['ra_cur_landlord'];
$field_cur_landlords_phone = $_POST['ra_cur_landlords_phone'];
$field_prev_address = $_POST['ra_prev_address'];
$field_prev_city = $_POST['ra_prev_city'];
$field_prev_province = $_POST['ra_prev_province'];
$field_prev_postal = $_POST['ra_prev_postal'];
$field_prev_length = $_POST['ra_prev_length'];
$field_prev_rent= $_POST['ra_prev_rent'];
$field_prev_reason_leaving = $_POST['ra_prev_reason_leaving'];
$field_prev_landlord = $_POST['ra_prev_landlord'];
$field_prev_landlord_phone = $_POST['ra_prev_landlord_phone'];
$field_cur_employer = $_POST['ra_cur_employer'];
$field_cur_employer_phone = $_POST['ra_cur_employer_phone'];
$field_cur_employer_address = $_POST['ra_cur_employer_address'];
$field_cur_position = $_POST['ra_cur_position'];
$field_cur_job_years = $_POST['ra_cur_job_years'];
$field_cur_salary = $_POST['ra_cur_salary'];
$field_other_income = $_POST['ra_other_income'];
$field_bank_location = $_POST['ra_bank_location'];
$field_prev_employer = $_POST['ra_prev_employer'];
$field_prev_employer_phone = $_POST['ra_prev_employer_phone'];
$field_prev_position = $_POST['ra_prev_position'];
$field_prev_job_years = $_POST['ra_prev_job_years'];
$field_emer_one =$_POST['ra_emer_one'];
$field_emer_one_phone =$_POST['ra_emer_one_phone'];
$field_emer_one_relation =$_POST['ra_emer_one_relation'];
$field_emer_one_address =$_POST['ra_emer_one_address'];
$field_emer_two =$_POST['ra_emer_two'];
$field_emer_two_phone =$_POST['ra_emer_two_phone'];
$field_emer_two_relation =$_POST['ra_emer_two_relation'];
$field_emer_two_address =$_POST['ra_emer_two_address'];
foreach($_POST['check'] as $value) {
    $check_boxes .= $value." ";
}
$drop_down_item = $_POST['cf_drop_down'];
$field_first_name_co = $_POST['ra_first_name_co'];
$field_middle_name_co =$_POST['ra_middle_name_co'];
$field_last_name_co = $_POST['ra_last_name_co'];
$field_all_occupants_co = $_POST['ra_all_occupants_co'];
$field_num_pets_co = $_POST['ra_num_pets_co'];
$field_type_pets_co = $_POST['ra_pettype_co'];
$field_cur_phone_co = $_POST['ra_cur_phone_co'];
$field_cur_email_co = $_POST['ra_cur_email_co']; 
$field_dob_co = $_POST['ra_dob_co'];    
$field_sin_co = $_POST['ra_sin_co'];
$field_dl_num_co = $_POST['ra_dl_num_co'];
$field_dl_issued_prov_co= $_POST['ra_dl_issued_prov_co'];
$field_dl_issued_date_co = $_POST['ra_dl_issued_date_co'];
$field_dl_expires_co = $_POST['ra_dl_expires_co'];
$field_car_one_year_co =$_POST['ra_car_one_year_co'];
$field_car_one_make_co =$_POST['ra_car_one_make_co'];
$field_car_one_color_co =$_POST['ra_car_one_color_co'];
$field_car_one_plate_co =$_POST['ra_car_one_plate_co'];
$field_car_one_province_co =$_POST['ra_car_one_province_co'];
$field_car_two_year_co =$_POST['ra_car_two_year_co'];
$field_car_two_make_co =$_POST['ra_car_two_make_co'];
$field_car_two_color_co =$_POST['ra_car_two_color_co'];
$field_car_two_plate_co =$_POST['ra_car_two_plate_co'];
$field_car_two_province_co =$_POST['ra_car_two_province_co'];
$field_ref_one_co =$_POST['ra_ref_one_co'];
$field_ref_two_co =$_POST['ra_ref_two_co'];
$field_cur_address_co = $_POST['ra_cur_address_co'];    
$field_cur_city_co = $_POST['ra_cur_city_co']; 
$field_cur_province_co = $_POST['ra_cur_province_co'];
$field_cur_postal_co = $_POST['ra_cur_postal_co'];
$field_cur_rent_co = $_POST['ra_cur_rent_co'];
$field_residing_length_co = $_POST['ra_cur_residing_length_co'];    
$field_cur_reason_leaving_co = $_POST['ra_cur_reason_leaving_co'];
$field_cur_landlord_co =$_POST['ra_cur_landlord_co'];
$field_cur_landlords_phone_co = $_POST['ra_cur_landlords_phone_co'];
$field_prev_address_co = $_POST['ra_prev_address_co'];
$field_prev_city_co = $_POST['ra_prev_city_co'];
$field_prev_province_co = $_POST['ra_prev_province_co'];
$field_prev_postal_co = $_POST['ra_prev_postal_co'];
$field_prev_length_co = $_POST['ra_prev_length_co'];
$field_prev_rent_co= $_POST['ra_prev_rent_co'];
$field_prev_reason_leaving_co = $_POST['ra_prev_reason_leaving_co'];
$field_prev_landlord_co = $_POST['ra_prev_landlord_co'];
$field_prev_landlord_phone_co = $_POST['ra_prev_landlord_phone_co'];
$field_cur_employer_co = $_POST['ra_cur_employer_co'];
$field_cur_employer_phone_co = $_POST['ra_cur_employer_phone_co'];
$field_cur_employer_address_co = $_POST['ra_cur_employer_address_co'];
$field_cur_position_co = $_POST['ra_cur_position_co'];
$field_cur_job_years_co = $_POST['ra_cur_job_years_co'];
$field_cur_salary_co = $_POST['ra_cur_salary_co'];
$field_other_income_co = $_POST['ra_other_income_co'];
$field_bank_location_co = $_POST['ra_bank_location_co'];
$field_prev_employer_co = $_POST['ra_prev_employer_co'];
$field_prev_employer_phone_co = $_POST['ra_prev_employer_phone_co'];
$field_prev_position_co = $_POST['ra_prev_position_co'];
$field_prev_job_years_co = $_POST['ra_prev_job_years_co'];
$field_emer_one_co =$_POST['ra_emer_one_co'];
$field_em,er_one_phone_co =$_POST['ra_emer_one_phone_co'];
$field_emer_one_relation_co =$_POST['ra_emer_one_relation_co'];
$field_emer_one_address_co =$_POST['ra_emer_one_address_co'];
$field_emer_two_co =$_POST['ra_emer_two_co'];
$field_emer_two_phone_co =$_POST['ra_emer_two_phone_co'];
$field_emer_two_relation_co =$_POST['ra_emer_two_relation_co'];
$field_emer_two_address_co =$_POST['ra_emer_two_address_co'];
foreach($_POST['check_co'] as $value) {
    $check_boxes .= $value." ";
}
$drop_down_item_co = $_POST['cf_drop_down_co'];
$mail_to = '[email protected]';
$subject = 'Rental Application '.$field_first_name;
$body_message = 'Rental Address: '.$field_rental_address."\r\n";
$body_message .= 'Date Required: '.$field_date_required."\r\n";
$body_message .= 'First Name: '.$field_first_name."\r\n";
$body_message .= 'Middle Name: '.$field_middle_name."\r\n";
$body_message .= 'Last Name: '.$field_last_name."\r\n";
$body_message .= 'List All occupants: '.$field_all_occupants."\r\n";
$body_message .= 'Number of Pets: '.$field_num_pets."\r\n";
$body_message .= 'Type of Pets : '.$field_type_pets."\r\n";
$body_message .= 'Phone: '.$field_cur_phone."\r\n";
$body_message .= 'E-mail: '.$field_cur_email."\r\n";
$body_message .= 'Date of Birth: '.$field_dob."\r\n";
$body_message .= 'SIN: '.$field_sin."\r\n";
$body_message .= 'Drivers License Number: '.$field_dl_num."\r\n";
$body_message .= 'Date Issued : '.$field_dl_issued_date."\r\n";
$body_message .= 'Drives License Issued: '.$field_dl_issued_prov."\r\n";
$body_message .= 'Drives License Expires: '.$field_dl_expires."\r\n";
$body_message .= 'Vehicle #1 Year: '.$field_car_one_year."\r\n";
$body_message .= 'Vehicle #1 Make: '.$field_car_one_make."\r\n";
$body_message .= 'Vehicle #1 Color: '.$field_car_one_color."\r\n";
$body_message .= 'Vehicle #1 Plate: '.$field_car_one_plate."\r\n";
$body_message .= 'Vehicle #1 Province Issued: '.$field_car_one_province."\r\n";
$body_message .= 'Vehicle #2 Year: '.$field_car_two_year."\r\n";
$body_message .= 'Vehicle #2 Make: '.$field_car_two_make."\r\n";
$body_message .= 'Vehicle #2 Color: '.$field_car_two_color."\r\n";
$body_message .= 'Vehicle #2 Plate: '.$field_car_two_plate."\r\n";
$body_message .= 'Vehicle #2 Province Issued: '.$field_car_two_province."\r\n";
$body_message .= 'Credit Reference 1: '.$field_ref_one."\r\n";
$body_message .= 'Credit Reference 2: '.$field_ref_two."\r\n";
$body_message .= 'Current Address: '.$field_cur_address."\r\n";
$body_message .= 'City: '.$field_cur_city."\r\n";
$body_message .= 'Province: '.$field_cur_province."\r\n";
$body_message .= 'Postal Code: '.$field_cur_postal."\r\n";
$body_message .= 'residing at this address: '.$field_residing_length."\r\n";
$body_message .= 'Rent Amount   : '.$field_cur_rent."\r\n";
$body_message .= 'Reason for Leaving: '.$field_cur_reason_leaving."\r\n";
$body_message .= 'Current Landlords Name: '.$field_cur_landlord."\r\n";
$body_message .= 'Current Landlords Phone: '.$field_cur_landlords_phone."\r\n";
$body_message .= 'Previous Address: '.$field_prev_address."\r\n";
$body_message .= 'City: '.$field_prev_city."\r\n";
$body_message .= 'Province: '.$field_prev_province."\r\n";
$body_message .= 'Postal Code: '.$field_prev_postal."\r\n";
$body_message .= 'residing at this address: '.$field_prev_length."\r\n";
$body_message .= 'Rent Amount   : '.$field_prev_rent."\r\n";
$body_message .= 'Reason for Leaving: '.$field_prev_reason_leaving."\r\n";
$body_message .= 'Previous Landlords Name: '.$field_prev_landlord."\r\n";
$body_message .= 'Previous Landlords Phone: '.$field_prev_landlord_phone."\r\n";
$body_message .= 'Current Employer: '.$field_cur_employer."\r\n";
$body_message .= 'Current Employers Phone: '.$field_cur_employer_phone."\r\n";
$body_message .= 'Current Employers Address: '.$field_cur_employer_address."\r\n";
$body_message .= 'Job Position: '.$field_cur_position."\r\n";
$body_message .= 'Years Employed: '.$field_cur_job_years."\r\n";
$body_message .= 'Salary: '.$field_cur_salary."\r\n";
$body_message .= 'Other Income: '.$field_other_income."\r\n";
$body_message .= 'Bank(Branch Location): '.$field_bank_location."\r\n";
$body_message .= 'Previous Employer: '.$field_prev_employer."\r\n";
$body_message .= 'Previous Employers Phone: '.$field_prev_employer_phone."\r\n";
$body_message .= 'Job Position: '.$field_prev_position."\r\n";
$body_message .= 'Years Employed: '.$field_prev_job_years."\r\n";
$body_message .= 'Emergency Contact #1: '.$field_emer_one."\r\n";
$body_message .= 'Phone Number: '.$field_emer_one_phone."\r\n";
$body_message .= 'Relationship: '.$field_emer_one_relation."\r\n";
$body_message .= 'Address: '.$field_emer_one_address."\r\n";
$body_message .= 'Emergency Contact #2: '.$field_emer_two."\r\n";
$body_message .= 'Phone Number: '.$field_emer_two_phone."\r\n";
$body_message .= 'Relationship: '.$field_emer_two_relation."\r\n";
$body_message .= 'Address: '.$field_emer_two_address."\r\n";
$body_message .= "How did you hear about us?: ".$drop_down_item."\r\n";
$body_message .= 'I allow Sunden Management to use the information within this form to preform a credit check, employment reference check, landlord reference check and any other inquiries deemed necessary to secure a rental property.: '.$check_boxes."\r\n";
$body_message .= 'First Name: '.$field_first_name_co."\r\n";
$body_message .= 'Last Name: '.$field_last_name_co."\r\n";
$body_message .= 'First Name: '.$field_first_name_co."\r\n";
$body_message .= 'Middle Name: '.$field_middle_name_co."\r\n";
$body_message .= 'Last Name: '.$field_last_name_co."\r\n";
$body_message .= 'List All occupants: '.$field_all_occupants_co."\r\n";
$body_message .= 'Number of Pets: '.$field_num_pets_co."\r\n";
$body_message .= 'Type of Pets : '.$field_type_pets_co."\r\n";
$body_message .= 'Phone: '.$field_cur_phone_co."\r\n";
$body_message .= 'E-mail: '.$field_cur_email_co."\r\n";
$body_message .= 'Date of Birth: '.$field_dob_co."\r\n";
$body_message .= 'SIN: '.$field_sin_co."\r\n";
$body_message .= 'Drivers License Number: '.$field_dl_num_co."\r\n";
$body_message .= 'Date Issued : '.$field_dl_issued_date_co."\r\n";
$body_message .= 'Drives License Issued: '.$field_dl_issued_prov_co."\r\n";
$body_message .= 'Drives License Expires: '.$field_dl_expires_co."\r\n";
$body_message .= 'Vehicle #1 Year: '.$field_car_one_year_co."\r\n";
$body_message .= 'Vehicle #1 Make: '.$field_car_one_make_co."\r\n";
$body_message .= 'Vehicle #1 Color: '.$field_car_one_color_co."\r\n";
$body_message .= 'Vehicle #1 Plate: '.$field_car_one_plate_co."\r\n";
$body_message .= 'Vehicle #1 Province Issued: '.$field_car_one_province_co."\r\n";
$body_message .= 'Vehicle #2 Year: '.$field_car_two_year_co."\r\n";
$body_message .= 'Vehicle #2 Make: '.$field_car_two_make_co."\r\n";
$body_message .= 'Vehicle #2 Color: '.$field_car_two_color_co."\r\n";
$body_message .= 'Vehicle #2 Plate: '.$field_car_two_plate_co."\r\n";
$body_message .= 'Vehicle #2 Province Issued: '.$field_car_two_province_co."\r\n";
$body_message .= 'Credit Reference 1: '.$field_ref_one_co."\r\n";
$body_message .= 'Credit Reference 2: '.$field_ref_two_co."\r\n";
$body_message .= 'Current Address: '.$field_cur_address_co."\r\n";
$body_message .= 'City: '.$field_cur_city_co."\r\n";
$body_message .= 'Province: '.$field_cur_province_co."\r\n";
$body_message .= 'Postal Code: '.$field_cur_postal_co."\r\n";
$body_message .= 'residing at this address: '.$field_residing_length_co."\r\n";
$body_message .= 'Rent Amount   : '.$field_cur_rent_co."\r\n";
$body_message .= 'Reason for Leaving: '.$field_cur_reason_leaving_co."\r\n";
$body_message .= 'Current Landlords Name: '.$field_cur_landlord_co."\r\n";
$body_message .= 'Current Landlords Phone: '.$field_cur_landlords_phone_co."\r\n";
$body_message .= 'Previous Address: '.$field_prev_address_co."\r\n";
$body_message .= 'City: '.$field_prev_city_co."\r\n";
$body_message .= 'Province: '.$field_prev_province_co."\r\n";
$body_message .= 'Postal Code: '.$field_prev_postal_co."\r\n";
$body_message .= 'residing at this address: '.$field_prev_length_co."\r\n";
$body_message .= 'Rent Amount   : '.$field_prev_rent_co."\r\n";
$body_message .= 'Reason for Leaving: '.$field_prev_reason_leaving_co."\r\n";
$body_message .= 'Previous Landlords Name: '.$field_prev_landlord_co."\r\n";
$body_message .= 'Previous Landlords Phone: '.$field_prev_landlord_phone_co."\r\n";
$body_message .= 'Current Employer: '.$field_cur_employer_co."\r\n";
$body_message .= 'Current Employers Phone: '.$field_cur_employer_phone_co."\r\n";
$body_message .= 'Current Employers Address: '.$field_cur_employer_address_co."\r\n";
$body_message .= 'Job Position: '.$field_cur_position_co."\r\n";
$body_message .= 'Years Employed: '.$field_cur_job_years_co."\r\n";
$body_message .= 'Salary: '.$field_cur_salary_co."\r\n";
$body_message .= 'Other Income: '.$field_other_income_co."\r\n";
$body_message .= 'Bank(Branch Location): '.$field_bank_location_co."\r\n";
$body_message .= 'Previous Employer: '.$field_prev_employer_co."\r\n";
$body_message .= 'Previous Employers Phone: '.$field_prev_employer_phone_co."\r\n";
$body_message .= 'Job Position: '.$field_prev_position_co."\r\n";
$body_message .= 'Years Employed: '.$field_prev_job_years_co."\r\n";
$body_message .= 'Emergency Contact #1: '.$field_emer_one_co."\r\n";
$body_message .= 'Phone Number: '.$field_emer_one_phone_co."\r\n";
$body_message .= 'Relationship: '.$field_emer_one_relation_co."\r\n";
$body_message .= 'Address: '.$field_emer_one_address_co."\r\n";
$body_message .= 'Emergency Contact #2: '.$field_emer_two_co."\r\n";
$body_message .= 'Phone Number: '.$field_emer_two_phone_co."\r\n";
$body_message .= 'Relationship: '.$field_emer_two_relation_co."\r\n";
$body_message .= 'Address: '.$field_emer_two_address_co."\r\n";
$body_message .= "How did you hear about us?: ".$drop_down_item_co."\r\n";
$body_message .= 'I allow Sunden Management to use the information within this form to preform a credit check, employment reference check, landlord reference check and any other inquiries deemed necessary to secure a rental property.: '.$check_boxes."\r\n";
$body_message .= 'First Name: '.$field_first_name_co."\r\n";
$body_message .= 'Last Name: '.$field_last_name_co."\r\n";
$headers = 'From: '.$field_cur_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Thank you for your application. We will contact you shortly.');
        window.location = 'home1/index.php';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email to [email protected]');
        window.location = 'home1/index.php';
    </script>
<?php
}

Respuestas a la pregunta(1)

Su respuesta a la pregunta