I have what used to be a validation of the working form, including remote verification of the username as available. we added many other javascript to the script.js file, and at some point, the recently deleted part of it broke. The check field for only one field is checked only in the new_name field. It is necessary (works) and must be available (does not work).
Here is jQuery:
$('#nickname_form').validate({ rules: { new_name: { required: true, remote: { url: '/api/screenname_unique/', type: 'post' } } }, messages: { new_name: { required: 'Please choose a Forum Username.', remote: 'That Username is already taken or contains invalid characters.' } } });
As I said, the previous one was used to work unchanged. I checked the rest of the script.js file and no errors were found. In addition, on the site we do not see JS errors anywhere. If I delete the deleted part of the above code, the required validation will be performed and the form will be submitted when the value is in the field.
With the remote in place form will not be submitted and the ajax response from the remote call will be true or false, the jQuery validation error message will not be shown. Here is the page that is being called by the remote. It works fine as far as it is responsible for the given value:
<?php header('Content-type: application/json'); //get the post value $screen_name = $_POST['new_name']; //get their member_id $member_id = $this->EE->session->userdata['member_id']; //return false if no screen_name provided if((!$screen_name) || (!$member_id)) { echo json_encode(false); exit; } else { //there is a screen_name //Regex Check for valid chars $valid = !preg_match('/[^a-z0-9_ -]/i',trim($screen_name)); if (!$valid) { echo json_encode(false); exit; } //SQL $results = $this->EE->db->query("SELECT member_id FROM exp_members WHERE screen_name = '$screen_name' and member_id <> '$member_id' limit 1"); if ($results->num_rows() > 0) { echo json_encode(false); } else { echo json_encode(true); } }
? >
I'm not sure where to go from here. Ideas?
source share