RPeraltaJr
5/30/2017 - 6:17 PM

Form Settings for Trucking LP

Form Settings for Trucking LP

<?php 

global $wpdb;

// form submission
if(isset($_POST['submit'])) {

	// required form fields
	$post_fields_array = array(
    "first_name",
    "last_name",
    "email",
    "zipcode",
    "phone",
    "cdla_status",
    "experience",
    "hazmat"
	);

	// 'dui' check for field only found on other template
	if( isset($_POST['dui']) ) {
		$post_fields_array[] = "dui";
	}

	foreach( $post_fields_array as $post_field ) {
		$$post_field = $_POST[$post_field]; // make every post field a variable

		// validation for empty fields
		if( !isset($_POST[$post_field]) && empty($_POST[$post_field]) ) {
			$error = true;
		}
	}

	// declare table for submissions
	$table_name = "submissions";
	// additional columns to add
	$table_data = array(
		"post_status" => "pending",
    "form_url"    => $_SERVER['REQUEST_URI'],
		"ip_address"	=> $_SERVER['REMOTE_ADDR']
	);

	// insert the post fields within 'table_data'
	foreach( $post_fields_array as $post_field ) {
			$table_data[$post_field] = $$post_field;
	}

	// insert data into table
	$success = $wpdb->insert($table_name, $table_data);

	// send mail if successful
	if (!$error && $success) {
		$source = "[Company Domain].com" . $_SERVER['REQUEST_URI'];
		$subject = "Thank you for your application to [Company Name]!";
		// $subject_me = "Application from $source";
		$mail_applicant =
			"
			Hello $first_name,<br><br>
			Thank you so much for your interest in driving for [Company Name]!<br><br>
			If you would like to speak to a recruiter now, please call $phone_number.<br><br>
			If you are ready to go through our full application process, <a href='$ats_link'>click here</a>.<br><br>
			Thank you,<br>
			[Company Name] Recruiting
			";
		// $mail_me =
		// 	"
		// 	Application received from $source<br><br>
		// 	First Name: $first_name<br>
		// 	Last Name: $last_name<br>
		// 	Email: $email<br>
		// 	Phone: $phone<br>
		// 	Zipcode: $zipcode<br>
		// 	CDLA Status: $cdla_status<br>
		// 	Experience: $experience<br>
		//  Hazmat: $hazmat
		// 	";
		$to = $first_name . "<" . $email . ">";
		// $to_me = "my_email_here@mail.com";
		// message

		$message = "<html><head></head><body>$mail_applicant</body></html>";
		// $message_me = "<html><head></head><body>$mail_me</body></html>";

		$headers = 'MIME-Version: 1.0' . "\r\n";
		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
		// Additional headers
		$headers .= 'From:No-Reply <noreply@[Company Domain].com>' . "\r\n";
		wp_mail($to, $subject, $message, $headers);
		// wp_mail($to_best, $subject_me, $message_me, $headers);
		$redirect_url = $thankyou_page;
		wp_redirect($redirect_url);
		exit();
	} else {
		$error = TRUE;
	}

} ?>