ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Some SafeCracker validation rules not working.

March 15, 2012 9:47am

Subscribe [5]
  • #1 / Mar 15, 2012 9:47am

    LightmakerUK

    42 posts

    Hi.

    We need to use the validation in SafeCracker to check an entered number is in a certain range. It seems that all the validation rules that accept a numerical parameter are ineffective though.

    Here are the rules I’m using:

    http://ellislab.com/codeigniter/user-guide/libraries/form_validation.html#rulereference

    The other rules such as “required” and “integer” work as expected.

    Cheers,

    Jez

  • #2 / Mar 16, 2012 6:03am

    LightmakerUK

    42 posts

    Just giving this a bump - this is quite an important issue for us.

  • #3 / Mar 16, 2012 12:08pm

    Shane Eckert

    7174 posts

    Hello LightmakerUK,

    I am sorry to hear you are running into this problem.

    Can you show me the form and how you are using validation? If you would like to include the whole template that would be good as well.

    Looking forward to your reply.

    Cheers,

  • #4 / Mar 16, 2012 12:56pm

    LightmakerUK

    42 posts

    Hi Shane.

    I would prefer not to display the template here, and unfortunately when I try to PM you I get a message saying your inbox is full.

    Basically if include the line:

    rules:my_numeric_field="integer"

    and I enter a non-numeric value into the field, I get the expected message returned: “The No. of steps field must contain an integer”.

    However, if include the line:

    rules:my_numeric_field="less_than[11]"

    and I enter “20” into the field, no error message is returned and the form and value is submitted.


    Many thanks.

     

  • #5 / Mar 16, 2012 1:21pm

    glenndavisgroup

    436 posts

    Hi LightmakerUK,

    Try this:

    rules:my_numeric_field="integer|less_than[11]"

    Cheers,

    Mike

  • #6 / Mar 16, 2012 1:41pm

    LightmakerUK

    42 posts

    Hi Mike.

    Thanks for the suggestion, but unfortunately that doesn’t work.


    I’ve just found this thread:

    http://ellislab.com/forums/viewthread/211216/


    The conclusion seems to be that maybe not all the CodeIgniter validation rules are included in EE - could this be the reason I can’t get it to work?

  • #7 / Mar 16, 2012 2:24pm

    glenndavisgroup

    436 posts

    That’s interesting. I haven’t had to use the rules yet in my websites but interesting to know that certain functionality is not there.

    Shane, can you verify this when you get a chance?

    Thank you,

    Mike

  • #8 / Mar 18, 2012 1:18pm

    Dan Decker

    7338 posts

    Hi LightmakerUK,

    I can confirm that the version of Codeigniter that ExpressionEngine is built on is not the currently available version. The result of that is that the Codeigniter User Guide may include features that aren’t available in ExpressionEngine. That validation rule may very well be one of the features not yet available in EE.

    However, if you want a different way around this, AJAX Form Validator may be just the thing you are looking for.

    Cheers,

  • #9 / Mar 19, 2012 5:27am

    LightmakerUK

    42 posts

    Hi Dan.

    Thanks for the reply and suggestion.

    We’re already using the Malsup Form Plugin for client-side validation and checking a value is within the required range - however we need the added security of server-side validation. I’ll download the latest version of CI and see if I can integrate those rules into EE.

    Thanks,

    Jez

  • #10 / Mar 19, 2012 6:14pm

    Sean C. Smith

    3818 posts

    LightmakerUK,

    Glad to see that Dan has helped you out so far. Is there anything else I can assist you with?

    Sean

  • #11 / Mar 20, 2012 9:04am

    LightmakerUK

    42 posts

    Hi Sean.

    Should be OK now, thanks.

    Jez

  • #12 / Mar 21, 2012 3:33pm

    miromo

    3 posts

    I’m pulling my hair out trying to get an email address to validate as a valid email address. Can you confirm what validations are actually available in safe-cracker? It’s hard to decide when enough is enough when debugging this stuff if you don’t even know if the feature you’re trying to use exists or not.

    This is my safecracker tag

    {exp:safecracker
            channel="discussion"
            return="/discussion/newtopicthanks"
            error_handling="inline"
            include_jquery="no"
            rules:topicemailaddress="valid_email"
            rules:topicfirstname="min_length[5]"
            rules:topicemailaddress="matches[confirmtopicemail]"
    }

    Here are the fields:

    <div>
            <label for="topicemailaddress">Email:</label>
            <input type="text" name="topicemailaddress" id="topicemailaddress" value="{topicemailaddress}" maxlength="128" size="128" />
    </div>
    <div>
            <label for="confirmtopicemail">Confirm Email:</label>
            <input type="text" name="confirmtopicemail" id="confirmtopicemail" value="{confirmtopicemail}" maxlength="128" size="128" />
    </div>

    It validates that the two email addresses match, but it does not validate that the topicemailaddress is an email address.

     

  • #13 / Mar 22, 2012 6:01pm

    Dan Decker

    7338 posts

    Hi miromo,

    Indeed, SafeCracker should work on the valid_email rule. Have you tried combining the rules like so:

    {exp:safecracker
            channel="discussion"
            return="/discussion/newtopicthanks"
            error_handling="inline"
            include_jquery="no"
            rules:topicemailaddress="valid_email|matches[confirmtopicemail]"
            rules:topicfirstname="min_length[5]"
    }

    Give that a shot and see if it enforces the rules properly.

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases