: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Class NF_Database_Models_Submission
class NF_Database_Models_Submission
protected $_user_id = '';
protected $_form_id = '';
protected $_seq_num = '';
protected $_sub_date = '';
protected $_mod_date = '';
protected $_field_values = array();
protected $_extra_values = array();
* Delimiter that uniquely identifies a field as type 'repeater'
* Requests for a field can be made by either an (int) field id or a
* (string) field reference, which prior to fieldset repeaters had been
* for the field key only. For disambiguation, a fieldset repeater field
* request for a specific field within the fieldset is in the form of:
* {fieldsetFieldId}{delimiter}{fieldIdOfFieldWithinFieldset}
protected $_fieldsetDelimiter='.';
* Delimiter that uniquely identifies multiple fieldset repeater submissions
* Fieldset Repeaters can have multiple values submitted on any given
* submission. Each repeated value for a field in the fieldset is
* delimited in the submission data with an incremented index value
protected $_fieldsetRepetitionDelimiter='_';
public function __construct( $id = '', $form_id = '' )
$this->_form_id = $form_id;
$sub = $this->retrieveSub($this->_id);
$this->_status = $sub->post_status;
$this->_user_id = $sub->post_author;
$this->_sub_date = $sub->post_date;
$this->_mod_date = $sub->post_modified;
if( $this->_id && ! $this->_form_id ){
$this->_form_id = $this->retrieveFormId($this->_id);
if( $this->_id && $this->_form_id ){
$this->_seq_num = $this->retrieveSeqNum($this->_id);
protected function retrieveSub($id)
$return = get_post( $id );
protected function retrieveFormId( $id)
$return = $this->getPostMeta( $id, '_form_id', TRUE );
* Get the sequence number
protected function retrieveSeqNum($id)
$return = $this->getPostMeta( $id, '_seq_num', TRUE );
* Get post meta value for given post Id and key
protected function getPostMeta($id, $key, $bool = TRUE)
$return = get_post_meta( $id, $key, $bool );
return intval( $this->_id );
public function get_status()
public function get_user()
return get_user_by( 'id', $this->_user_id );
public function get_form_id()
return intval( $this->_form_id );
public function get_form_title()
$form = Ninja_Forms()->form( $this->_form_id )->get();
return $form->get_setting( 'title' );
public function get_seq_num()
return intval( $this->_seq_num );
public function get_sub_date( $format = 'm/d/Y' )
return date( $format, strtotime( $this->_sub_date ) );
public function get_mod_date( $format = 'm/d/Y' )
return date( $format, strtotime( $this->_mod_date ) );
* Returns a single submission value by field ID or field key.
* @param int|string $field_ref
public function get_field_value( $field_ref )
// Bypass existing method if fieldset repeater
if(Ninja_Forms()->fieldsetRepeater->isRepeaterFieldByFieldReference($field_ref) ){
$parsedField = Ninja_Forms()->fieldsetRepeater
->parseFieldsetFieldReference($field_ref);
$return = $this->get_field_value_for_fieldset_child($parsedField['fieldId'], $parsedField['fieldsetFieldId']);
$field_id = ( is_numeric( $field_ref ) ) ? $field_ref : $this->get_field_id_by_key( $field_ref );
$field = '_field_' . $field_id;
if( isset( $this->_field_values[ $field ] ) ) return $this->_field_values[ $field ];
$this->_field_values[ $field ] = get_post_meta($this->_id, $field, TRUE);
$this->_field_values[ $field_ref ] = get_post_meta($this->_id, $field, TRUE);
return WPN_Helper::htmlspecialchars( $this->_field_values[ $field ] );
* Get field values of a single child field within a fieldset repeater field
* get_field_value(), which calls this method, is expected to return a
* string. Fieldset Repeater child fields have a unique field reference,
* differentiated by their delimiter that ensures that the requesting
* external caller knows that it is requesting a fieldset repeater field.
* This this method returns a serialized string of values, honoring the
* get_field_value() method with the expectation that the external
* caller will unserialize this value.
* @param int $childFieldId
protected function get_field_value_for_fieldset_child($fieldsetId, $childFieldId) {
if (!isset($this->_field_values[$fieldsetId])) {
$this->_field_values[$fieldsetId] = get_post_meta($this->_id, '_field_' . $fieldsetId, true);
if(!empty($this->_field_values[$fieldsetId] )){
foreach ($this->_field_values[$fieldsetId] as $submissionKey => $value) {
$explodedFieldset = explode($this->_fieldsetDelimiter, $submissionKey);
if (!isset($explodedFieldset[1])) {
// data is corrupted as we cannot determine field id construct
$explodedChildField = explode($this->_fieldsetRepetitionDelimiter, $explodedFieldset[1]);
if (!isset($explodedChildField[1])) {
// data is corrupted as we cannote determine child field id construct
$submissionChildFieldId = $explodedChildField[0];
$submissionIndex = $explodedChildField[1];
if ($submissionChildFieldId === $childFieldId) {
$valueCollection[$submissionIndex] = WPN_Helper::htmlspecialchars($value);
$return = serialize($valueCollection);
public function get_field_values()
if( ! empty( $this->_field_values ) ) return $this->_field_values;
$field_values = $this->getPostMeta( $this->_id, '' );
foreach( $field_values as $field_id => $field_value ){
$this->_field_values[ $field_id ] = implode( ', ', $field_value );
if( 0 === strpos( $field_id, '_field_' ) ){
$field_id = substr( $field_id, 7 );
if( ! is_numeric( $field_id ) ) continue;
$field = Ninja_Forms()->form($this->_form_id)->get_field( $field_id );
$field = Ninja_Forms()->form()->get_field( $field_id );
$key = $field->get_setting( 'key' );
$this->_field_values[ $key ] = implode(', ', $field_value);
return $this->_field_values;
public function update_field_value( $field_ref, $value )
$field_id = ( is_numeric( $field_ref ) ) ? $field_ref : $this->get_field_id_by_key( $field_ref );
$this->_field_values[ $field_id ] = WPN_Helper::kses_post( $value );
public function update_field_values( $data )
foreach( $data as $field_ref => $value )
$this->update_field_value( $field_ref, $value );
public function get_extra_value( $key )
if( ! isset( $this->_extra_values[ $key ] ) || ! $this->_extra_values[ $key ] ){
$id = ( $this->_id ) ? $this->_id : 0;
$this->_extra_values[ $key ] = get_post_meta( $id, $key, TRUE );
return $this->_extra_values[ $key ];
public function get_extra_values( $keys )
foreach( $keys as $key ) {
$values[ $key ] = $this->get_extra_value( $key );
public function update_extra_value( $key, $value )
if( property_exists( $this, $key ) ) return FALSE;
return $this->_extra_values[ $key ] = $value;
public function update_extra_values( $values )
foreach( $values as $key => $value ){
$this->update_extra_value( $key, $value );
public function find( $form_id, array $where = array(), array $ids = array() )
$this->_form_id = $form_id;
'meta_query' => $this->format_meta_query( $where )
if ( ! empty ( $ids ) ) {
$args[ 'post__in' ] = $ids;
$subs = get_posts( $args );
$class = get_class( $this );
foreach( $subs as $sub ){
$return[] = new $class( $sub->ID, $this->_form_id );
if( ! $this->_id ) return;
wp_delete_post( $this->_id );
if( ! $this->_id ) return;
wp_trash_post( $this->_id );
* @return $this|NF_Database_Models_Submission|void
'post_status' => 'publish'
$this->_id = wp_insert_post( $sub );
if( ! $this->_id ) return;
if( ! $this->_seq_num && $this->_form_id ){
$this->_seq_num = NF_Database_Models_Form::get_next_sub_seq( $this->_form_id );
$this->_save_extra_values();
return $this->_save_field_values();
public static function export( $form_id, array $sub_ids = array(), $return = FALSE )
$date_format = Ninja_Forms()->get_setting( 'date_format' );
'_date_submitted' => esc_html__( 'Date Submitted', 'ninja-forms' )
$fields = Ninja_Forms()->form( $form_id )->get_fields();
* If we are using an add-on that filters our field order, we don't want to call sort again.
* TODO: This is probably not the most effecient way to handle this. It should be re-thought.
if ( ! has_filter( 'ninja_forms_get_fields_sorted' ) ) {
uasort( $fields, array( 'NF_Database_Models_Submission', 'sort_fields' ) );
$hidden_field_types = apply_filters( 'nf_sub_hidden_field_types', array() );
$subs = Ninja_Forms()->form( $form_id )->get_subs( array(), FALSE, $sub_ids );
foreach( $subs as $sub ){
$value[ '_seq_num' ] = $sub->get_seq_num();
$value[ '_date_submitted' ] = $sub->get_sub_date( $date_format );
// boolean - does this submission use a repeater
// How many repeater submissions does this submission have
// Ids of fields in the repeater
foreach ($fields as $field_id => $field) {
// Bypass existing method if fieldset repeater
if('repeater'===$field->get_setting('type')){