Basically, on the part that says " array('couponPrice,main', 'safe'), I would like the number in the form to be either $0 or at least equal to $10 or greater. In the array just before that one, I figured out how to make the entered number equal to or greater than $0, but what if I want the number to either be equal to 0 or greater than or equal to another number? Does this make sense what I'm asking? <?php class MDealPriceForm extends MDealPrice { public $name; public static function model($className=__CLASS__) { return parent::model($className); } public function rules() { return array( array('name,price,value', 'required'), array('value', 'numerical', 'min' => 0.00), array('couponPrice,main', 'safe'), ); } public function attributeLabels() { return array( 'name' => $this->t('Name'), 'price' => $this->t('Site Pre-Registration Fee (Coupon Cost)'), 'value' => $this->t('Normal Registration Fee / Offer Value'), 'couponPrice' => $this->t('Registration Due w/Coupon'), ); } public function beforeValidate() { if(is_array($this->name)) foreach($this->name as $k=>$v) if(!$v) unset($this->name[$k]); return parent::beforeValidate(); } }
Anybody??? Here is the line in questions: array('price', 'numerical', 'min' => 0.00), Basically, what I want is for the value to be equal to 0 OR to be greater than 5.
I think you are referring to a type casting a property. correct me if im wrong, you want the value of "safe" inside the array('couponPrice,main', 'safe') Code (markup): to this format '$0'?
I don't think so, but thank you. Currently, I have a form in which a number must be entered. Right now, the number that people enter must simply be equal to or greater than 0. But I want to change this slightly. I want the number that's entered to be either equal to 0 or greater than 5. What I don't want is for people to be able to insert a number between .01 and 4.99.
Write a custom function in your model ie: public function checkNumber() { if (($this->price == 0) || ($this->price >= 10)){ $this->addError('price','Incorrect Price!') } } PHP: Then in your model rules add array('price', 'checkNumber') PHP:
I know this is an extremely delayed reply, but I just wanted to thank you for you answer. It didn't work out exactly as you wrote it, but it gave me a starting point. What I ended up doing was using the function you created, but I had to make a slight alteration by changing the fourth line to an else statement. public function checkNumber() { if (($this->price == 0) || ($this->price >= 10)); else $this->addError('price', 'Coupon costs must either be free or at least $10!'); } Code (markup):
That code doesn't make sense at all - how does that even pass without errors? You're closing the if without anything happening, and... how is that else not triggering an "no starting if-clause"? *confused*
Honestly not sure. I tried as it was originally stated, but then when I typed a number in it'd just give me an error no matter what number I typed in. I worked with it for days, took a break for weeks bbecause i didn't understand, and then tried as i wrote it and guarantee it works for my case. I'm trying to think of a way to prove its now working as necessary. The only numbers that work are 0 and 10 or greater, else you get an error. Could it just be Yii Framework thing because I saw ssimilarly written code elsewhere, which gave me the idea. I don't know much abot yiI frame work, but i agree it seems to be incomplete (if this, then...uh what...else this) but I aassure yo its working as i need it.
I'll try to do a screen capture video of me using the original code, then the rresults once uploaded, and then show the results as needed per the "oddly written" code.
Oh, I don't doubt it works, I'm just wondering HOW it works Not being familiar with the Yii framework, but I'm thinking they have some sort of extra parsing involved. If it works for you, great