I'm trying to have a client's existing WordPress site post a form to a web service, but it needs to do it through PHP because the web service isn't public and only the server we have the WordPress site on has access to it.
I've found out that I can add an action to the functions.php file and hook it to when a Contact Form 7 form is submitted. The only issue I'm having now is figuring out how to access the forms fields when it gets to that point.
Here is the form code:
<p>[text* firstname class:fstext "First Name"]</p>
<p>[text* lastname class:fstext "Last Name"]</p>
<p>[email* email class:fstext "Email Address"] </p>
<p>[text* phone class:fstext "Phone Number"]</p>
<p>[text* zipcode2 id:zipcode2 class:fstext "Zip Code"]</p>
[text* addy2 id:addy2]
<p>Submit Your Resume (.pdf or .doc)</p>
<p>[file* resume class:resume_upload filetypes:pdf|doc|docx]</p>
And here is the hook I'm trying to create:
add_action( 'wpcf7_before_send_mail', 'upload_to_resume_application' );
function upload_to_resume_application( $contact_form ) {
$title = $contact_form->title;
$firstName = $contact_form->firstname;
if('Career Inquiry' == $title) {
// Get the form information and call the web service
error_log("Title: " . $title . " First Name: " . $firstName);
}
}
Right now, I'm just logging it to an error log so I can see what's coming in. It says it can't find the form's 'firstname' property though. Am I missing something I need to be setting in the form, or am I trying to read it in incorrectly? Any help would be greatly appreciated!