Commit 7fc8a9b4 authored by Iain Poulson's avatar Iain Poulson

Merge branch 'issue#4041' into 'develop'

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

Closes #4041

See merge request !3853
parents e9786bfb 62b06c38
Pipeline #2832 passed with stages
in 5 minutes and 43 seconds
......@@ -273,17 +273,19 @@ class NF_AJAX_Controllers_Submission extends NF_Abstracts_Controller
$unique_field_value = serialize( $unique_field_value );
}
/*
* Check our db for the value submitted.
*/
global $wpdb;
// @TODO: Rewrite this to use our submissions API.
$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 );
$result = $wpdb->get_results( $sql, 'ARRAY_N' );
if ( intval( $result[ 0 ][ 0 ] ) > 0 ) {
$this->_errors['fields'][ $unique_field_id ] = array( 'slug' => 'unique_field', 'message' => $unique_field_error );
$this->_respond();
if ( ! empty($unique_field_value) ) {
/*
* Check our db for the value submitted.
*/
global $wpdb;
// @TODO: Rewrite this to use our submissions API.
$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 );
$result = $wpdb->get_results( $sql, 'ARRAY_N' );
if ( intval( $result[ 0 ][ 0 ] ) > 0 ) {
$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