From 008278c7ecb7e12eb50f28b9cd66b10f547b2eb2 Mon Sep 17 00:00:00 2001 From: Yuchen Wang Date: Wed, 23 Nov 2011 16:15:51 -0500 Subject: [PATCH 1/3] CC-3093: SoundCloud preferences do not have email or password as required fields + firefox auto-fills the password field Fixing bug introduced by last commit...Should test more thoroughly next time... Fixed by creating and adding a custom validator that checks if the field is empty only when some other fields have specific values, in this case, when 'UploadToSoundcloudOption' has a value of '1'. --- .../forms/SoundcloudPreferences.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/forms/SoundcloudPreferences.php b/airtime_mvc/application/forms/SoundcloudPreferences.php index 1597bbe19..8fe460c15 100644 --- a/airtime_mvc/application/forms/SoundcloudPreferences.php +++ b/airtime_mvc/application/forms/SoundcloudPreferences.php @@ -1,4 +1,5 @@ addElement('text', 'SoundCloudUser', array( 'class' => 'input_text', 'label' => 'SoundCloud Email', - 'required' => true, 'filters' => array('StringTrim'), 'autocomplete' => 'off', 'value' => Application_Model_Preference::GetSoundCloudUser(), 'decorators' => array( 'ViewHelper' + ), + + // By default, 'allowEmpty' is true. This means that our custom + // validators are going to be skipped if this field is empty, + // which is something we don't want + 'allowEmpty' => false, + 'validators' => array( + new ConditionalNotEmpty(array('UploadToSoundcloudOption'=>'1')) ) )); @@ -56,12 +64,19 @@ class Application_Form_SoundcloudPreferences extends Zend_Form_SubForm $this->addElement('password', 'SoundCloudPassword', array( 'class' => 'input_text', 'label' => 'SoundCloud Password', - 'required' => true, 'filters' => array('StringTrim'), 'autocomplete' => 'off', 'value' => Application_Model_Preference::GetSoundCloudPassword(), 'decorators' => array( 'ViewHelper' + ), + + // By default, 'allowEmpty' is true. This means that our custom + // validators are going to be skipped if this field is empty, + // which is something we don't want + 'allowEmpty' => false, + 'validators' => array( + new ConditionalNotEmpty(array('UploadToSoundcloudOption'=>'1')) ) )); From ef9a4cd8503905c7a1a189e72e6c883aafc2d0ad Mon Sep 17 00:00:00 2001 From: Yuchen Wang Date: Wed, 23 Nov 2011 16:17:21 -0500 Subject: [PATCH 2/3] CC-3093: SoundCloud preferences do not have email or password as required fields + firefox auto-fills the password field Forgot to stage this file in last commit... --- .../customvalidators/ConditionalNotEmpty.php | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 airtime_mvc/application/forms/customvalidators/ConditionalNotEmpty.php diff --git a/airtime_mvc/application/forms/customvalidators/ConditionalNotEmpty.php b/airtime_mvc/application/forms/customvalidators/ConditionalNotEmpty.php new file mode 100644 index 000000000..2f89fe667 --- /dev/null +++ b/airtime_mvc/application/forms/customvalidators/ConditionalNotEmpty.php @@ -0,0 +1,62 @@ + 'Value is required and can\'t be empty' + ); + + protected $_fieldValues; + + /** + * Constructs a new ConditionalNotEmpty validator. + * + * @param array $fieldValues - the names and expected values of the fields we're depending on; + * E.g., if we have a field that should only be validated when two other + * fields PARENT_1 and PARENT_2 have values of '1' and '0' respectively, then + * $fieldValues should contain ('PARENT_1'=>'1', 'PARENT_2'=>'0') + */ + public function __construct($fieldValues) + { + $this->_fieldValues = $fieldValues; + } + + /** + * Implements Zend_Validate_Abstract. + * Given names and expected values of the fields we're depending on ($_fieldValues), + * this function returns true if the expected values doesn't match the actual user input, + * or if $value is not empty. Returns false otherwise. + * + * @param String $value - this field's value + * @param array $context - names and values of the rest of the fields in this form + * @return boolean - true if valid; false otherwise + */ + public function isValid($value, $context = null) + { + if ($value != "") { + return true; + } + + if (is_array($context)) { + foreach($this->_fieldValues as $fieldName=>$fieldValue) { + if (!isset($context[$fieldName]) || $context[$fieldName] != $fieldValue) { + return true; + } + } + } elseif (is_string($context)) { + if (!isset($context) || $context != $fieldValue) { + return true; + } + } + + $this->_error(self::KEY_IS_EMPTY); + return false; + } +} + +?> From 288fa8678257a50cf37096b1e6648d8657f5c5bb Mon Sep 17 00:00:00 2001 From: Yuchen Wang Date: Wed, 23 Nov 2011 16:58:21 -0500 Subject: [PATCH 3/3] CC-3100: Remove "development" env variable from default .htaccess file Removed the line "SetEnv APPLICATION_ENV development" --- airtime_mvc/public/.htaccess | 2 -- 1 file changed, 2 deletions(-) diff --git a/airtime_mvc/public/.htaccess b/airtime_mvc/public/.htaccess index 3dfbebfef..48c40b1dd 100644 --- a/airtime_mvc/public/.htaccess +++ b/airtime_mvc/public/.htaccess @@ -11,5 +11,3 @@ RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L] RewriteBase / - -SetEnv APPLICATION_ENV development