Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[WordPress Ajax Form Submission] #WordPress
//AJAX CALL FUNCTION
function getCandidate_Func(){
$nonce = $_POST['feedBackNonceField'];
if ( ! wp_verify_nonce( $nonce, 'getCandidateFunc' ) )
die ( 'Busted!');
die();
}
add_action('wp_ajax_getCandidate', 'getCandidate_Func');
add_action('wp_ajax_nopriv_getCandidate', 'getCandidate_Func'); // not really needed
function candidateFeedback_func( $atts ) {
$return = '<form id="feedbackFormCandidate">';
$return .= wp_nonce_field('getCandidateFunc', 'feedBackNonceField');
// INPUTS
$return .= '</form>';
return $return;
}
add_shortcode( 'candidateFeedback', 'candidateFeedback_func' );
function getCandidate() {
var fData = $('form#feedbackFormEmployer').serialize();
console.log(fData);
$.ajax({
type: "POST",
url: formJs.ajax_url,
data: {
'action':'getCandidate',
'fData' : fData,
'feedBackNonceField' : $('#feedBackNonceField').val(),
},
success:function(data){
console.log(data);
data = JSON.parse(data);
switch(data[0]) {
case 1:
$('#scheduleInterview').html('Sent');
break;
case 2:
$('#empbtn_savefeedback').html('Saved');
break;
case 3:
$('#scheduleInterview2').html('Sent');
break;
case 4:
$('#empbtn_savefeedback2').html('Saved');
break;
case 5:
$('#cancelInterview').html('Cancelled');
break;
case 5:
$('#cancelInterview2').html('Cancelled');
break;
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment