Code Duplication    Length = 23-23 lines in 3 locations

classes/fields/email.php 1 location

@@ 187-209 (lines=23) @@
184
     * @return array|bool
185
     * @since 2.0
186
     */
187
    public function validate ( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
188
        $errors = array();
189
190
        $check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params );
191
192
        if ( is_array( $check ) )
193
            $errors = $check;
194
        else {
195
            if ( 0 < strlen( $value ) && strlen( $check ) < 1 ) {
196
                $label = pods_var( 'label', $options, ucwords( str_replace( '_', ' ', $name ) ) );
197
198
                if ( 1 == pods_var( 'required', $options ) )
199
                    $errors[] = sprintf( __( '%s is required', 'pods' ), $label );
200
                else
201
                    $errors[] = sprintf( __( 'Invalid e-mail provided for %s', 'pods' ), $label );
202
            }
203
        }
204
205
        if ( !empty( $errors ) )
206
            return $errors;
207
208
        return true;
209
    }
210
211
    /**
212
     * Change the value or perform actions after validation but before saving to the DB

classes/fields/phone.php 1 location

@@ 194-216 (lines=23) @@
191
     *
192
     * @since 2.0
193
     */
194
    public function validate ( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
195
        $errors = array();
196
197
        $label = strip_tags( pods_var_raw( 'label', $options, ucwords( str_replace( '_', ' ', $name ) ) ) );
198
199
        $check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params );
200
201
        if ( is_array( $check ) )
202
            $errors = $check;
203
        else {
204
            if ( 0 < strlen( $value ) && strlen( $check ) < 1 ) {
205
                if ( 1 == pods_var( 'required', $options ) )
206
                    $errors[] = sprintf( __( 'The %s field is required.', 'pods' ), $label );
207
                else
208
                    $errors[] = sprintf( __( 'Invalid phone number provided for the field %s.', 'pods' ), $label );
209
            }
210
        }
211
212
        if ( !empty( $errors ) )
213
            return $errors;
214
215
        return true;
216
    }
217
218
    /**
219
     * Change the value or perform actions after validation but before saving to the DB

classes/fields/website.php 1 location

@@ 235-257 (lines=23) @@
232
	 *
233
	 * @since 2.0
234
	 */
235
	public function validate ( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
236
		$errors = array();
237
238
		$label = strip_tags( pods_var_raw( 'label', $options, ucwords( str_replace( '_', ' ', $name ) ) ) );
239
240
		$check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params );
241
242
		if ( is_array( $check ) )
243
			$errors = $check;
244
		else {
245
			if ( 0 < strlen( $value ) && strlen( $check ) < 1 ) {
246
				if ( 1 == pods_var( 'required', $options ) )
247
					$errors[] = sprintf( __( 'The %s field is required.', 'pods' ), $label );
248
				else
249
					$errors[] = sprintf( __( 'Invalid website provided for the field %s.', 'pods' ), $label );
250
			}
251
		}
252
253
		if ( !empty( $errors ) )
254
			return $errors;
255
256
		return true;
257
	}
258
259
	/**
260
	 * Change the value or perform actions after validation but before saving to the DB