本文整理汇总了PHP中CRM_Core_Form::addRule方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_Form::addRule方法的具体用法?PHP CRM_Core_Form::addRule怎么用?PHP CRM_Core_Form::addRule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_Form
的用法示例。
在下文中一共展示了CRM_Core_Form::addRule方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildForm
/**
* @param CRM_Core_Form $form
*/
public function buildForm(&$form)
{
/**
* You can define a custom title for the search form
*/
$this->setTitle('Find Contributors by Aggregate Totals');
/**
* Define the search form fields here
*/
$form->add('text', 'min_amount', ts('Aggregate Total Between $'));
$form->addRule('min_amount', ts('Please enter a valid amount (numbers and decimal point only).'), 'money');
$form->add('text', 'max_amount', ts('...and $'));
$form->addRule('max_amount', ts('Please enter a valid amount (numbers and decimal point only).'), 'money');
$form->addDate('start_date', ts('Contribution Date From'), FALSE, array('formatType' => 'custom'));
$form->addDate('end_date', ts('...through'), FALSE, array('formatType' => 'custom'));
$financial_types = CRM_Contribute_PseudoConstant::financialType();
foreach ($financial_types as $financial_type_id => $financial_type) {
$form->addElement('checkbox', "financial_type_id[{$financial_type_id}]", 'Financial Type', $financial_type);
}
/**
* If you are using the sample template, this array tells the template fields to render
* for the search form.
*/
$form->assign('elements', array('min_amount', 'max_amount', 'start_date', 'end_date', 'financial_type_id'));
}
示例2: buildQuickForm
/**
* This is function is called by the form object to get the DataSource's
* form snippet. It should add all fields necesarry to get the data
* uploaded to the temporary table in the DB.
*
* @param CRM_Core_Form $form
*
* @return void
* (operates directly on form argument)
*/
public function buildQuickForm(&$form)
{
$form->add('hidden', 'hidden_dataSource', 'CRM_Import_DataSource_CSV');
$config = CRM_Core_Config::singleton();
$uploadFileSize = CRM_Utils_Number::formatUnitSize($config->maxFileSize . 'm', TRUE);
$uploadSize = round($uploadFileSize / (1024 * 1024), 2);
$form->assign('uploadSize', $uploadSize);
$form->add('File', 'uploadFile', ts('Import Data File'), 'size=30 maxlength=255', TRUE);
$form->setMaxFileSize($uploadFileSize);
$form->addRule('uploadFile', ts('File size should be less than %1 MBytes (%2 bytes)', array(1 => $uploadSize, 2 => $uploadFileSize)), 'maxfilesize', $uploadFileSize);
$form->addRule('uploadFile', ts('Input file must be in CSV format'), 'utf8File');
$form->addRule('uploadFile', ts('A valid file must be uploaded.'), 'uploadedfile');
$form->addElement('checkbox', 'skipColumnHeader', ts('First row contains column headers'));
}
示例3: buildQuickForm
/**
* build the form elements for an email object
*
* @param CRM_Core_Form $form reference to the form object
* @param array $location the location object to store all the form elements in
* @param int $locationId the locationId we are dealing with
* @param int $count the number of blocks to create
*
* @return void
* @access public
* @static
*/
static function buildQuickForm(&$form, $addressBlockCount = null)
{
// passing this via the session is AWFUL. we need to fix this
if (!$addressBlockCount) {
$blockId = $form->get('Email_Block_Count') ? $form->get('Email_Block_Count') : 1;
} else {
$blockId = $addressBlockCount;
}
$form->applyFilter('__ALL__', 'trim');
//Email box
$form->addElement('text', "email[{$blockId}][email]", ts('Email'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', 'email'));
$form->addRule("email[{$blockId}][email]", ts('Email is not valid.'), 'email');
if (isset($form->_contactType)) {
//Block type
$form->addElement('select', "email[{$blockId}][location_type_id]", '', CRM_Core_PseudoConstant::locationType());
//On-hold checkbox
$form->addElement('advcheckbox', "email[{$blockId}][on_hold]", null);
//Bulkmail checkbox
$js = array('id' => "Email_" . $blockId . "_IsBulkmail", 'onClick' => 'singleSelect( this.id );');
$form->addElement('advcheckbox', "email[{$blockId}][is_bulkmail]", null, '', $js);
//is_Primary radio
$js = array('id' => "Email_" . $blockId . "_IsPrimary", 'onClick' => 'singleSelect( this.id );');
$form->addElement('radio', "email[{$blockId}][is_primary]", '', '', '1', $js);
if (CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Contact') {
$form->add('textarea', "email[{$blockId}][signature_text]", ts('Signature (Text)'), array('rows' => 2, 'cols' => 40));
$form->addWysiwyg("email[{$blockId}][signature_html]", ts('Signature (HTML)'), array('rows' => 2, 'cols' => 40));
}
}
}
示例4: buildQuickForm
/**
* build the form elements for an Website object
*
* @param CRM_Core_Form $form reference to the form object
* @param array $location the location object to store all the form elements in
* @param int $locationId the locationId we are dealing with
* @param int $count the number of blocks to create
*
* @return void
* @access public
* @static
*/
static function buildQuickForm(&$form)
{
$blockId = $form->get('Website_Block_Count') ? $form->get('Website_Block_Count') : 1;
$form->applyFilter('__ALL__', 'trim');
//Website type select
$form->addElement('select', "website[{$blockId}][website_type_id]", '', CRM_Core_PseudoConstant::websiteType());
//Website box
$form->addElement('text', "website[{$blockId}][url]", ts('Website'), array_merge(CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), array('onfocus' => "if (!this.value) this.value='http://'; else return false", 'onblur' => "if ( this.value == 'http://') this.value=''; else return false")));
$form->addRule("website[{$blockId}][url]", ts('Enter a valid web location beginning with \'http://\' or \'https://\'. EXAMPLE: http://www.mysite.org/'), 'url');
}
示例5: buildForm
/**
* @param CRM_Core_Form $form
*/
public function buildForm(&$form)
{
/**
* You can define a custom title for the search form
*/
$this->setTitle('Find Contributors by Aggregate Totals');
/**
* Define the search form fields here
*/
$form->add('text', 'min_amount', ts('Aggregate Total Between $'));
$form->addRule('min_amount', ts('Please enter a valid amount (numbers and decimal point only).'), 'money');
$form->add('text', 'max_amount', ts('...and $'));
$form->addRule('max_amount', ts('Please enter a valid amount (numbers and decimal point only).'), 'money');
$form->addDate('start_date', ts('Contribution Date From'), FALSE, array('formatType' => 'custom'));
$form->addDate('end_date', ts('...through'), FALSE, array('formatType' => 'custom'));
$form->addSelect('financial_type_id', array('entity' => 'contribution', 'multiple' => 'multiple', 'context' => 'search'));
/**
* If you are using the sample template, this array tells the template fields to render
* for the search form.
*/
$form->assign('elements', array('min_amount', 'max_amount', 'start_date', 'end_date'));
}
示例6: buildForm
/**
* @param CRM_Core_Form $form
*/
public function buildForm(&$form)
{
/**
* You can define a custom title for the search form
*/
$this->setTitle('Recurring Contribution Aggregate');
// Get default curreny
$config = CRM_Core_Config::singleton();
$currencySymbol = $config->defaultCurrencySymbol;
/**
* Define the search form fields here
*/
$form->addDate('start_date', ts('Start Date'), FALSE, array('formatType' => 'custom'));
$form->add('text', 'min_amount', ts('Aggregate Total Between ' . $currencySymbol));
$form->addRule('min_amount', ts('Please enter a valid amount (numbers and decimal point only).'), 'money');
$form->add('text', 'max_amount', ts('...and ' . $currencySymbol));
$form->addRule('max_amount', ts('Please enter a valid amount (numbers and decimal point only).'), 'money');
/**
* If you are using the sample template, this array tells the template fields to render
* for the search form.
*/
$form->assign('elements', array('start_date', 'min_amount', 'max_amount'));
}
示例7: buildQuickForm
/**
* Build the form object elements for an Website object.
*
* @param CRM_Core_Form $form
* Reference to the form object.
* @param int $blockCount
* Block number to build.
*/
public static function buildQuickForm(&$form, $blockCount = NULL)
{
if (!$blockCount) {
$blockId = $form->get('Website_Block_Count') ? $form->get('Website_Block_Count') : 1;
} else {
$blockId = $blockCount;
}
$form->applyFilter('__ALL__', 'trim');
//Website type select
$form->addField("website[{$blockId}][website_type_id]", array('entity' => 'website', 'class' => 'eight'));
//Website box
$form->addField("website[{$blockId}][url]", array('entity' => 'website'));
$form->addRule("website[{$blockId}][url]", ts('Enter a valid web address beginning with \'http://\' or \'https://\'.'), 'url');
}
示例8: buildQuickForm
/**
* build the form elements for an Website object
*
* @param CRM_Core_Form $form reference to the form object
* @param int $blockCount block number to build
*
* @return void
* @access public
* @static
*/
static function buildQuickForm(&$form, $blockCount = NULL)
{
if (!$blockCount) {
$blockId = $form->get('Website_Block_Count') ? $form->get('Website_Block_Count') : 1;
} else {
$blockId = $blockCount;
}
$form->applyFilter('__ALL__', 'trim');
//Website type select
$form->addSelect("website[{$blockId}][website_type_id]", array('entity' => 'website', 'class' => 'eight'));
//Website box
$form->addElement('text', "website[{$blockId}][url]", ts('Website'), array_merge(CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), array('onfocus' => "if (!this.value) { this.value='http://';} else return false", 'onblur' => "if ( this.value == 'http://') { this.value='';} else return false")));
$form->addRule("website[{$blockId}][url]", ts('Enter a valid web location beginning with \'http://\' or \'https://\'. EXAMPLE: http://www.mysite.org/'), 'url');
}
示例9: buildQuickForm
/**
* Build the form object elements for an email object.
*
* @param CRM_Core_Form $form
* Reference to the form object.
* @param int $blockCount
* Block number to build.
* @param bool $blockEdit
* Is it block edit.
*/
public static function buildQuickForm(&$form, $blockCount = NULL, $blockEdit = FALSE)
{
// passing this via the session is AWFUL. we need to fix this
if (!$blockCount) {
$blockId = $form->get('Email_Block_Count') ? $form->get('Email_Block_Count') : 1;
} else {
$blockId = $blockCount;
}
$form->applyFilter('__ALL__', 'trim');
//Email box
$form->addField("email[{$blockId}][email]", array('entity' => 'email'));
$form->addRule("email[{$blockId}][email]", ts('Email is not valid.'), 'email');
if (isset($form->_contactType) || $blockEdit) {
//Block type
$form->addField("email[{$blockId}][location_type_id]", array('entity' => 'email', 'placeholder' => NULL, 'class' => 'eight'));
//TODO: Refactor on_hold field to select.
$multipleBulk = CRM_Core_BAO_Email::isMultipleBulkMail();
//On-hold select
if ($multipleBulk) {
$holdOptions = array(0 => ts('- select -'), 1 => ts('On Hold Bounce'), 2 => ts('On Hold Opt Out'));
$form->addElement('select', "email[{$blockId}][on_hold]", '', $holdOptions);
} else {
$form->addField("email[{$blockId}][on_hold]", array('entity' => 'email', 'type' => 'advcheckbox'));
}
//Bulkmail checkbox
$form->assign('multipleBulk', $multipleBulk);
if ($multipleBulk) {
$js = array('id' => "Email_" . $blockId . "_IsBulkmail");
$form->addElement('advcheckbox', "email[{$blockId}][is_bulkmail]", NULL, '', $js);
} else {
$js = array('id' => "Email_" . $blockId . "_IsBulkmail");
if (!$blockEdit) {
$js['onClick'] = 'singleSelect( this.id );';
}
$form->addElement('radio', "email[{$blockId}][is_bulkmail]", '', '', '1', $js);
}
//is_Primary radio
$js = array('id' => "Email_" . $blockId . "_IsPrimary");
if (!$blockEdit) {
$js['onClick'] = 'singleSelect( this.id );';
}
$form->addElement('radio', "email[{$blockId}][is_primary]", '', '', '1', $js);
if (CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Contact') {
$form->add('textarea', "email[{$blockId}][signature_text]", ts('Signature (Text)'), array('rows' => 2, 'cols' => 40));
$form->add('wysiwyg', "email[{$blockId}][signature_html]", ts('Signature (HTML)'), array('rows' => 2, 'cols' => 40));
}
}
}
示例10: buildQuickForm
/**
* build the form elements for an open id object
*
* @param CRM_Core_Form $form reference to the form object
* @param array $location the location object to store all the form elements in
* @param int $locationId the locationId we are dealing with
* @param int $count the number of blocks to create
*
* @return void
* @access public
* @static
*/
static function buildQuickForm(&$form)
{
$blockId = $form->get('OpenID_Block_Count') ? $form->get('OpenID_Block_Count') : 1;
$form->applyFilter('__ALL__', 'trim');
$form->addElement('text', "openid[{$blockId}][openid]", ts('OpenID'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OpenID', 'openid'));
$form->addRule("openid[{$blockId}][openid]", ts('OpenID is not a valid URL.'), 'url');
//Block type
$form->addElement('select', "openid[{$blockId}][location_type_id]", '', CRM_Core_PseudoConstant::locationType());
$config = CRM_Core_Config::singleton();
if ($config->userFramework == 'Standalone') {
$js = array('id' => "OpenID_" . $blockId . "_IsLogin", 'onClick' => 'singleSelect( this.id );');
$form->addElement('advcheckbox', "openid[{$blockId}][allowed_to_login]", null, '', $js);
}
//is_Primary radio
$js = array('id' => "OpenID_" . $blockId . "_IsPrimary", 'onClick' => 'singleSelect( this.id );');
$form->addElement('radio', "openid[{$blockId}][is_primary]", '', '', '1', $js);
}
示例11: buildQuickForm
/**
* This function provides the HTML form elements that are specific.
* to the Household Contact Type
*
* @param CRM_Core_Form $form
* Form object.
* @param int $inlineEditMode
* ( 1 for contact summary.
* top bar form and 2 for display name edit )
*
* @return void
*/
public static function buildQuickForm(&$form, $inlineEditMode = NULL)
{
$form->applyFilter('__ALL__', 'trim');
if (!$inlineEditMode || $inlineEditMode == 1) {
// household_name
$form->addField('household_name');
}
if (!$inlineEditMode || $inlineEditMode == 2) {
// nick_name
$form->addField('nick_name');
$form->addField('contact_source', array('label' => ts('Source')));
}
if (!$inlineEditMode) {
$form->addField('external_identifier', array('label' => ts('External ID')));
$form->addRule('external_identifier', ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier'));
}
}
示例12: buildQuickForm
/**
* This function provides the HTML form elements that are specific.
* to the Household Contact Type
*
* @param CRM_Core_Form $form
* Form object.
* @param int $inlineEditMode
* ( 1 for contact summary.
* top bar form and 2 for display name edit )
*
* @return void
*/
public static function buildQuickForm(&$form, $inlineEditMode = NULL)
{
$attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact');
$form->applyFilter('__ALL__', 'trim');
if (!$inlineEditMode || $inlineEditMode == 1) {
// household_name
$form->add('text', 'household_name', ts('Household Name'), $attributes['household_name']);
}
if (!$inlineEditMode || $inlineEditMode == 2) {
// nick_name
$form->addElement('text', 'nick_name', ts('Nickname'), $attributes['nick_name']);
$form->addElement('text', 'contact_source', ts('Source'), CRM_Utils_Array::value('source', $attributes));
}
if (!$inlineEditMode) {
$form->add('text', 'external_identifier', ts('External ID'), $attributes['external_identifier'], FALSE);
$form->addRule('external_identifier', ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier'));
}
}
示例13: buildQuickForm
/**
* Build the form object elements for an open id object.
*
* @param CRM_Core_Form $form
* Reference to the form object.
* @param int $blockCount
* Block number to build.
* @param bool $blockEdit
* Is it block edit.
*/
public static function buildQuickForm(&$form, $blockCount = NULL, $blockEdit = FALSE)
{
if (!$blockCount) {
$blockId = $form->get('OpenID_Block_Count') ? $form->get('OpenID_Block_Count') : 1;
} else {
$blockId = $blockCount;
}
$form->applyFilter('__ALL__', 'trim');
$form->addElement('text', "openid[{$blockId}][openid]", ts('OpenID'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OpenID', 'openid'));
$form->addRule("openid[{$blockId}][openid]", ts('OpenID is not a valid URL.'), 'url');
//Block type
$form->addElement('select', "openid[{$blockId}][location_type_id]", '', CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'));
//is_Primary radio
$js = array('id' => "OpenID_" . $blockId . "_IsPrimary");
if (!$blockEdit) {
$js['onClick'] = 'singleSelect( this.id );';
}
$form->addElement('radio', "openid[{$blockId}][is_primary]", '', '', '1', $js);
}
示例14: buildQuickForm
/**
* build the form elements for an email object
*
* @param CRM_Core_Form $form reference to the form object
* @param array $location the location object to store all the form elements in
* @param int $locationId the locationId we are dealing with
* @param int $count the number of blocks to create
*
* @return void
* @access public
* @static
*/
static function buildQuickForm(&$form)
{
$blockId = $form->get('Email_Block_Count') ? $form->get('Email_Block_Count') : 1;
$form->applyFilter('__ALL__', 'trim');
//Email box
$form->addElement('text', "email[{$blockId}][email]", ts('Email'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', 'email'));
$form->addRule("email[{$blockId}][email]", ts('Email is not valid.'), 'email');
if (isset($form->_contactType)) {
//Block type
$form->addElement('select', "email[{$blockId}][location_type_id]", '', CRM_Core_PseudoConstant::locationType());
//On-hold checkbox
$form->addElement('advcheckbox', "email[{$blockId}][on_hold]", null);
//Bulkmail checkbox
$js = array('id' => "Email_" . $blockId . "_IsBulkmail", 'onClick' => 'singleSelect( this.id );');
$form->addElement('advcheckbox', "email[{$blockId}][is_bulkmail]", null, '', $js);
//is_Primary radio
$js = array('id' => "Email_" . $blockId . "_IsPrimary", 'onClick' => 'singleSelect( this.id );');
$form->addElement('radio', "email[{$blockId}][is_primary]", '', '', '1', $js);
}
}
示例15: buildQuickForm
/**
* This function provides the HTML form elements that are specific to the Individual Contact Type.
*
* @param CRM_Core_Form $form
* Form object.
* @param int $inlineEditMode
* ( 1 for contact summary.
* top bar form and 2 for display name edit )
*/
public static function buildQuickForm(&$form, $inlineEditMode = NULL)
{
$form->applyFilter('__ALL__', 'trim');
if (!$inlineEditMode || $inlineEditMode == 1) {
$nameFields = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options', TRUE, NULL, FALSE, 'name', TRUE, 'AND v.filter = 2');
// Fixme: dear god why? these come out in a format that is NOT the name of the fields.
foreach ($nameFields as &$fix) {
$fix = str_replace(' ', '_', strtolower($fix));
if ($fix == 'prefix' || $fix == 'suffix') {
// God, why god?
$fix .= '_id';
}
}
foreach ($nameFields as $name) {
$props = array();
if ($name == 'prefix_id' || $name == 'suffix_id') {
$options = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $name);
// Skip if we have no options available
if (!CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $name)) {
//continue;
}
$props = array('class' => 'eight', 'placeholder' => ' ', 'label' => $name == 'prefix_id' ? ts('Prefix') : ts('Suffix'));
}
$form->addField($name, $props);
}
}
if (!$inlineEditMode || $inlineEditMode == 2) {
// nick_name
$form->addField('nick_name');
// job title
// override the size for UI to look better
$form->addField('job_title', array('size' => '30'));
//Current Employer Element
$props = array('api' => array('params' => array('contact_type' => 'Organization')), 'create' => TRUE);
$form->addField('employer_id', $props);
$form->addField('contact_source', array('class' => 'big'));
}
if (!$inlineEditMode) {
$checkSimilar = Civi::settings()->get('contact_ajax_check_similar');
if ($checkSimilar == NULL) {
$checkSimilar = 0;
}
$form->assign('checkSimilar', $checkSimilar);
//External Identifier Element
$form->addField('external_identifier', array('label' => 'External ID'));
$form->addRule('external_identifier', ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier'));
CRM_Core_ShowHideBlocks::links($form, 'demographics', '', '');
}
}