input validation question

Discussion in 'Subrion Open Source CMS Core' started by Andrew_C, Feb 5, 2015.

  1. Andrew_C

    Andrew_C New Member

    I'm trying to validate a few input items and need a bit of help to start.

    As an example, a user inputs a number field in the member registration form (field name = yeargraduated). I want to check that this is an integer and check whether it is between a reasonable range (1920 and 2015). I tried adding the code at the bottom of this post in the Extra Actions but since I don't know php, it fails as I expected it might. Could someone point me in the right direction?

    I saw the URL validation post but didn't know if there were other similar functions built in along the lines of if (!iaValidate::isUrl($_POST['url_field']['url']))

    $input = 'yeargraduated';
    $input2 = (int)$input;
    if($input2<1920 || $input2>2015)
    $error = true;
    $msg[] = "bad date1";
    else if($input2 != $input)
    $error = true;
    $msg[] = "bad date2";
  2. Vasily_B.

    Vasily_B. Project Manager

    First of all you need to make sure you create a Number Input field type. It will prevent adding letters on front end.

    Now regarding the code, it should be as follows:

    if ($_POST[$fieldName])
        if ($_POST[$fieldName] < 1920 || $_POST[$fieldName] > date('Y'))
            $error = true;
            $messages[] = iaLanguage::get('error_dob_year');
            $invalidFields[] = $fieldName;
    And you need to add a new phrase in your language with the following key error_dob_year and set its type to common.

    That's it.
  3. Andrew_C

    Andrew_C New Member

    Thanks! Got it working.
  4. Vasily_B.

    Vasily_B. Project Manager

    I'm glad to advise.
  5. Anees

    Anees New Member

    Dear Vasily_B Please Advice:

    1. Unique field Validation for both Registration form and Edit Profile e.g. Identification Number (Unique) of a Member.
    2. Numeric Field validation with length limit and without length limit
    3. Alternative Email field validation checks
    4. Only characters field validation e.g. Father Name validation check
  6. rihaankhan

    rihaankhan Banned

    So, I'm taking this program design class and we are using flowgorithm (which i think is garbage). I made a program that plays a game of rock, paper, scissors. What I need to do now is create a case-insensitive validation for each of the words. Problem is there is no tolower conversion or anything of the sort. So, what I'm asking is if anyone has an idea of what I could do without having to type every possible variation of the string? I'm sure many pe

    ople don't know much about this program but any kind of ideas would be appreciated.
    Last edited: Oct 11, 2018

Share This Page