Code Duplication    Length = 23-23 lines in 3 locations

classes/fields/website.php 1 location

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

classes/fields/email.php 1 location

@@ 196-218 (lines=23) @@
193
	 * @return array|bool
194
	 * @since 2.0
195
	 */
196
	public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
197
198
		$errors = array();
199
200
		$check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params );
201
202
		if ( is_array( $check ) ) {
203
			$errors = $check;
204
		} else {
205
			if ( 0 < strlen( $value ) && strlen( $check ) < 1 ) {
206
				$label = pods_var( 'label', $options, ucwords( str_replace( '_', ' ', $name ) ) );
207
208
				if ( 1 == pods_var( 'required', $options ) ) {
209
					$errors[] = sprintf( __( '%s is required', 'pods' ), $label );
210
				} else {
211
					$errors[] = sprintf( __( 'Invalid e-mail provided for %s', 'pods' ), $label );
212
				}
213
			}
214
		}
215
216
		if ( ! empty( $errors ) ) {
217
			return $errors;
218
		}
219
220
		return true;
221
	}

classes/fields/phone.php 1 location

@@ 206-228 (lines=23) @@
203
	 * @return array|bool|mixed|string
204
	 * @since 2.0
205
	 */
206
	public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
207
208
		$errors = array();
209
210
		$label = strip_tags( pods_var_raw( 'label', $options, ucwords( str_replace( '_', ' ', $name ) ) ) );
211
212
		$check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params );
213
214
		if ( is_array( $check ) ) {
215
			$errors = $check;
216
		} else {
217
			if ( 0 < strlen( $value ) && strlen( $check ) < 1 ) {
218
				if ( 1 == pods_var( 'required', $options ) ) {
219
					$errors[] = sprintf( __( 'The %s field is required.', 'pods' ), $label );
220
				} else {
221
					$errors[] = sprintf( __( 'Invalid phone number provided for the field %s.', 'pods' ), $label );
222
				}
223
			}
224
		}
225
226
		if ( ! empty( $errors ) ) {
227
			return $errors;
228
		}
229
230
		return true;
231
	}