-
-
Save thefrosty/1263104 to your computer and use it in GitHub Desktop.
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; | |
} |
If you can, switch to the unminified version of jQuery for development ... that will give you better error messages.
I have SCRIPT_DEBUG defined.. Is there an unminifed definition?
object is undefined
[Break On This Error] length = object.length,
jquery.js?ver=1 (line 632)
I don't think WP comes with an unminified jQuery ... you might need to enqueue your own: http://code.jquery.com/jquery-1.6.4.js
OK, I see that error hold on ...
In your JavaScript, you use $.each
a couple of times. When you use .each()
, jQuery passes a reference to the collection you're iterating over into the function as the variable object
. But $.each()
isn't defining a collection ... so object
won't be defined.
OK, scratch that ... just haven't see $.each()
before ... but that's likely where your problem is.
If you can, set a breakpoint there in Firebug so you can step through and see what value the AJAX call is returning. I suspect that res.responses
or res.errors
are undefined and that's where your error's coming from.
Yeah, looks it's not defined. So I am assuming the function isn;t working proper..
The entire res
object is undefined, or res.responses
? If it's res
itself, I'd double check the wpAjax.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 ...
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..
a is undefined
[Break On This Error] (function(a,b){function cu(a){return f...oveEvent(a,h,s.handle),g=null,delete
jquery...r=1.6.4 (line 2)