Support Forum
All validations Rules not working I tried more than rule text and textarea only working others not working
Can you please post your code?
<?php
/**
* Registering meta boxes
*
* All the definitions of meta boxes are listed below with comments.
* Please read them CAREFULLY.
*
* You also should read the changelog to know what has been changed before updating.
*
* For more information, please visit:
* @link http://metabox.io/docs/registering-meta-boxes/
*/
add_filter('rwmb_meta_boxes', 'venue_meta_boxes');
/**
* Register meta boxes
*
* Remember to change "your_prefix" to actual prefix in your project
*
* @param array $meta_boxes List of meta boxes
*
* @return array
*/
function venue_meta_boxes($meta_boxes) {
/**
* prefix of meta keys (optional)
* Use underscore (_) at the beginning to make keys hidden
* Alt.: You also can make prefix empty to disable it
*/
// Better has an underscore as last sign
$prefix = 'venue_';
// 1st meta box
$meta_boxes[] = array(
// Meta box id, UNIQUE per meta box. Optional since 4.1.5
'id' => 'venue-sections',
// Meta box title - Will appear at the drag and drop handle bar. Required.
'title' => __('Fields', 'metabox_venue'),
// Post types, accept custom post types as well - DEFAULT is 'post'. Can be array (multiple post types) or string (1 post type). Optional.
'post_types' => array('venue'),
// Where the meta box appear: normal (default), advanced, side. Optional.
'context' => 'normal',
// Order of meta box: high (default), low. Optional.
'priority' => 'high',
// Auto save: true, false (default). Optional.
'autosave' => true,
// List of meta fields
'fields' => array(
// TEXT
array(
// Field name - Will be used as label
'name' => __('Address Line ', 'metabox_venue'),
// Field ID, i.e. the meta key
'id' => "{$prefix}addressline",
// Field description (optional)
'desc' => '',
'type' => 'text',
// CLONES: Add to make the field cloneable (i.e. have multiple value)
'clone' => true,
),
// Map requires at least one address field (with type = text)
array(
'id' => "{$prefix}address",
'name' => __('Address', 'metabox_venue'),
'type' => 'text',
'std' => __('Cairo', 'metabox_venue'),
),
array(
'id' => 'map',
'name' => __('Location', 'metabox_venue'),
'type' => 'map',
// Default location: 'latitude,longitude[,zoom]' (zoom is optional)
'std' => '30.044420,31.235712',
// Name of text field where address is entered. Can be list of text fields, separated by commas (for ex. city, state)
'address_field' => "{$prefix}address",
),
array(
// Field name - Will be used as label
'name' => __('Telephone Numbers ', 'metabox_venue'),
// Field ID, i.e. the meta key
'id' => "{$prefix}phone",
// Field description (optional)
'desc' => __('Telephone Numbers', 'metabox_venue'),
'type' => 'number',
// CLONES: Add to make the field cloneable (i.e. have multiple value)
'clone' => true,
),
// URL
array(
'name' => __('Website', 'metabox_venue'),
'id' => "{$prefix}url",
'desc' => __('URL description', 'metabox_venue'),
'type' => 'url',
),
array(
// Field name - Will be used as label
'name' => __('Opening Time ', 'metabox_venue'),
// Field ID, i.e. the meta key
'id' => "{$prefix}opentime",
// Field description (optional)
'desc' => '',
'type' => 'text',
// Default value (optional)
// CLONES: Add to make the field cloneable (i.e. have multiple value)
'clone' => false,
),
// is closed
array(
'name' => __('This venue is closed', 'metabox_venue'),
'id' => "{$prefix}is_closed",
'type' => 'checkbox',
// Value can be 0 or 1
'std' => 0,
),
// visa
array(
'name' => __('Visa', 'metabox_venue'),
'id' => "{$prefix}is_visa",
'type' => 'checkbox',
// Value can be 0 or 1
'std' => 0,
),
// is winner
array(
'name' => __('Winner', 'metabox_venue'),
'id' => "{$prefix}winner",
'type' => 'checkbox',
// Value can be 0 or 1
'std' => 0,
),
array(
'name' => __('Discount ', 'metabox_venue'),
// Field ID, i.e. the meta key
'id' => "{$prefix}discount",
// Field description (optional)
'desc' => '',
'type' => 'text',
// Default value (optional)
),
// Gellery images (WP 3.3+)
array(
'name' => __('Upload Images', 'metabox_venue'),
'id' => "{$prefix}plupload",
'type' => 'plupload_image',
'max_file_uploads' => 8,
),
),
'validation' => array(
'rules' => array(
"post_title" => array(
'required' => true,
),
"{$prefix}phone" => array(
'required' => true,
'number' => true,
),
),
// optional override of default jquery.validate messages
'messages' => array(
"post_title" => array(
'required' => __('Venue Name is Required', 'metabox_venue'),
),
"{$prefix}phone" => array(
'required' => __('Phone Number is Required', 'metabox_venue'),
'number' => __('It should be numbers only', 'metabox_venue'),
),
),
),
);
return $meta_boxes;
}
>>> Phone Field
I see. The reason is phone field is cloneable and each cloned field will have different ID (the HTML ID attribute that outputed). When click Add more button, we will get inputs with ID phone
, phone_1
, phone_2
, ... While the validation module uses input's ID to validate, it actually works with only the first field.
no it doesn't work man I tried it with select field and not working and messages not appear !
I mean in previous reply the validation works only with non-cloneable fields :(. I think in this case you can use custom attributes for phone fields ("pattern" to be exact). For more info, please read this docs:
https://metabox.io/docs/custom-attributes-for-inputs/
Here is the info for HTML pattern attribute:
http://webdesign.tutsplus.com/tutorials/html5-form-validation-with-the-pattern-attribute--cms-25145