Created
October 4, 2011 22:58
-
-
Save thefrosty/1263104 to your computer and use it in GitHub Desktop.
ajax response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function send2() { | |
/* Verify the nonce */ | |
//check_ajax_referer( 'sms-nonce' ); | |
/* Get post data */ | |
if ( !isset( $_POST['ajax_form_data'] ) ) die("-1"); | |
parse_str( $_POST['ajax_form_data'], $form_data ); | |
/* Get the form fields */ | |
$to = sanitize_text_field( $form_data['smsTo'] ); | |
$from = sanitize_text_field( $form_data['smsFrom'] ); | |
$subject = sanitize_text_field( $form_data['smsSubject'] ); | |
$message = sanitize_text_field( $form_data['smsMessage'] ); | |
$error_response = $success_response = new WP_Ajax_Response(); | |
$errors = new WP_Error(); | |
/* Check required fields */ | |
if ( empty( $to ) ) | |
$errors->add( 'smsTto', 'Please enter a user(s) email.' ); | |
if ( empty( $from ) ) | |
$errors->add( 'smsFrom', 'You must enter a from address.' ); | |
if ( empty( $subject ) ) | |
$errors->add( 'smsSubject', 'Please enter a subject line.' ); | |
if ( empty( $message ) ) | |
$errors->add( 'smsMessage', 'Please enter a message.' ); | |
/* If required fields aren't filled out, send response */ | |
if ( count ( $errors->get_error_codes() ) > 0 ) { | |
$error_response->add(array( | |
'what' => 'errors', | |
'id' => $errors | |
)); | |
$error_response->send(); | |
exit; | |
} | |
/* Do e-mail address validation */ | |
if ( !is_email( $from ) ) { | |
$errors->add( 'smsFrom', 'E-mail address is invalid.' ); | |
} | |
/* If any further errors, send response */ | |
if ( count ( $errors->get_error_codes() ) > 0 ) { | |
$error_response->add(array( | |
'what' => 'errors', | |
'id' => $errors | |
)); | |
$error_response->send(); | |
exit; | |
} | |
$message = wordwrap( $message, 150 ); | |
$headers = 'From: ' . $_POST['from'] . "\r\n" . | |
'Reply-To: ' . $_POST['from'] . "\r\n" . | |
'X-Mailer: PHP/'; | |
wp_mail( sanitize_email( $to ), $subject, $message, $headers ); | |
//Send back a response | |
$success_response->add(array( | |
'what' => 'object', | |
'data' => 'Message send successful.' | |
)); | |
$success_response->send(); | |
exit; | |
} |
this.data[0] is undefined
[Break On This Error] if ( this.data[0].firstChild == t...deType != 1 ) { // scalar error data
edit.p...age=sms (line 80)
which is now a wpAjax.parseAjaxResponse issues..
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The entire
res
object is undefined, orres.responses
? If it'sres
itself, I'd double check thewpAjax.parseAjaxResponse
function that's creating it. I usually work with data sent directly back and forth, so I can't help you with that method ...