Commit 62b06c38 authored by KR Moorhouse's avatar KR Moorhouse

Added an additional check to ensure that unique field restrictions don't honor null values.

parent e9786bfb
Pipeline #2829 passed with stages
in 5 minutes and 55 seconds
...@@ -273,17 +273,19 @@ class NF_AJAX_Controllers_Submission extends NF_Abstracts_Controller ...@@ -273,17 +273,19 @@ class NF_AJAX_Controllers_Submission extends NF_Abstracts_Controller
$unique_field_value = serialize( $unique_field_value ); $unique_field_value = serialize( $unique_field_value );
} }
/* if ( ! empty($unique_field_value) ) {
* Check our db for the value submitted. /*
*/ * Check our db for the value submitted.
*/
global $wpdb;
// @TODO: Rewrite this to use our submissions API. global $wpdb;
$sql = $wpdb->prepare( "SELECT COUNT(m.meta_id) FROM `" . $wpdb->prefix . "postmeta` AS m LEFT JOIN `" . $wpdb->prefix . "posts` AS p ON p.id = m.post_id WHERE m.meta_key = '_field_%d' AND m.meta_value = '%s' AND p.post_status = 'publish'", $unique_field_id, $unique_field_value ); // @TODO: Rewrite this to use our submissions API.
$result = $wpdb->get_results( $sql, 'ARRAY_N' ); $sql = $wpdb->prepare( "SELECT COUNT(m.meta_id) FROM `" . $wpdb->prefix . "postmeta` AS m LEFT JOIN `" . $wpdb->prefix . "posts` AS p ON p.id = m.post_id WHERE m.meta_key = '_field_%d' AND m.meta_value = '%s' AND p.post_status = 'publish'", $unique_field_id, $unique_field_value );
if ( intval( $result[ 0 ][ 0 ] ) > 0 ) { $result = $wpdb->get_results( $sql, 'ARRAY_N' );
$this->_errors['fields'][ $unique_field_id ] = array( 'slug' => 'unique_field', 'message' => $unique_field_error ); if ( intval( $result[ 0 ][ 0 ] ) > 0 ) {
$this->_respond(); $this->_errors['fields'][ $unique_field_id ] = array( 'slug' => 'unique_field', 'message' => $unique_field_error );
$this->_respond();
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment