0

since hours i am trying to find out what the problem could be here:

--> I have a Yii Form looks like this:

<?php $form=$this->beginWidget('CActiveForm', array(
                        'id'=>'withdrawal-request-form',
                        'enableAjaxValidation'=>true,
                    )); ?> 
...
...
...

$form->textField($model,'amount', array(
           'class' => 'form-control name-field',
           'placeholder' => $model->getAttributeLabel('Amount'),
           'type' => 'number',
           'min' => 10));

then i have my controller rules defined like this:

public function rules()
{
    return array(
        // username and password are required
        array('IBAN, BIC, amount, payment_id, email', 'required'),
        array('payment_id', 'numerical', 'integerOnly'=>true),
        array('email', 'email'),
        array('amount', 'numerical', 'min'=>10)
    );
}

My goal to disallow values less then '10'

** what i have tried already**

  • The really strange thing is all other rules, like 'required', and wrong email field without @ letter etc. works really really great, so the connection between the form and the rules are working great. This test was successfull

  • When i try to enter a letter e.g. an "A" into my amount field, i am gettin imediatley an red HTML5 error back (perfect, works also fine)

  • but when i try to enter a number less then 10 for examnple 1 --> then i am getting no error back (first strange thing) and the next big problem is, after submit, i am getting only a blank white page back :(

  • i have also added this here "enableClientValidation'=>true" to my Form Code (also no success)

  • and then I have also tried to implement some validation rules directly into the yii form element like this here:

    $form->textField($model,'amount', array( 'class' => 'form-control name-field', 'placeholder' => $model->getAttributeLabel('Amount'), 'type' => 'number', 'min' => '10'

--> also no success!

the crazy thing is when i remove my

array('amount', 'numerical', 'min'=>10)

rule out of my rules block, the submit an redirect process works great! but then i have numbers less then 10 in there becasue the "min=10 rule" was removed. BUT

when i add this line here again in to my rules

array('amount', 'numerical', 'min'=>10)

and then i am entering "1" into the amount field and then submit the form, yii is only displaying a white page!

so yii is recognizing, that i have entered a wrong value, but is only showing a white page

  • YES, I have already tried to check the log file. no new entry!!
  • YES, I have also reading the manual, but i followed exactly the steps and the way to set some new rules...

I really have no idea what the problem could be :(

Could you maybe give me any hint?!?

Thank you so much for any help!

Edit: ok I have found out, that the problem is that in my controller my $model->validate() is not true, and thats why the whole script will be skipped... i will check everything again and give a feedback here soon.

WEBGONDEL UG
  • 147
  • 1
  • 2
  • 12

1 Answers1

0

oh my god :)

I have found my bug!

the thing is, my rules / validation part was working perfectly the whole time! The white page cam only beacuse in my controller there was and if block like this defined:

if(validation){
    // do great stuff
}

but there was no !validation part defined, thats why after submit unvalid values, i only get an empty white blank page ;)

so if anybody will have a similar problem in the future!

Check Your Controller, if you have defined 2 cases

success case (validation part is ok) error case (validation part is invalid)

then you can redirect to the same page and let the user know something like

"You have entered an invalid amount. Minimum is 10.00$"

by settin some Yii errors and display them at the same page near the text fields where the user have entered the wrong amounts...

i did it now like this:

if($_POST['WithdrawalRequestForm']['amount'] < 10){
                Yii::app()->user->setFlash('error', "Please enter a wihtdraw amount with at aleast 10.00 €");
                $this->redirect('withdrawalRequest');
            }

Hope this will help other peoples also! ;)

WEBGONDEL UG
  • 147
  • 1
  • 2
  • 12