Commit 5e38ff38 authored by Iain Poulson's avatar Iain Poulson

Merge branch 'issue#3070' into 'develop'

Added pre-flight check for submission limit to submit process.

Closes #3070

See merge request !3831
parents 8cbf0919 42f178ca
Pipeline #2482 passed with stages
in 5 minutes and 6 seconds
......@@ -278,6 +278,7 @@ class NF_AJAX_Controllers_Submission extends NF_Abstracts_Controller
*/
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 ) {
......@@ -286,6 +287,19 @@ class NF_AJAX_Controllers_Submission extends NF_Abstracts_Controller
}
}
/*
|--------------------------------------------------------------------------
| Verify the submission limit.
|--------------------------------------------------------------------------
*/
if ( isset( $this->_data[ 'settings' ][ 'sub_limit_number' ] ) && ! empty( $this->_data[ 'settings' ][ 'sub_limit_number' ] ) ) {
$subs = Ninja_Forms()->form( $this->_form_id )->get_subs();
if ( count( $subs ) >= intval( $this->_data[ 'settings' ][ 'sub_limit_number' ] ) ) {
$this->_errors[ 'form' ][] = $this->_data[ 'settings' ][ 'sub_limit_msg' ];
$this->_respond();
}
}
/*
|--------------------------------------------------------------------------
| Calculations
......
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