Small fix needed... please help

Discussion in 'PHP' started by oo7ml, Oct 19, 2007.

  1. #1
    Hi, i hHi have some form validation on a small page i have. It checks that the fields A, B, C & D are are not empty. However i want to have validation on the D field to make sure that only the values 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 are allowed only and not 11, 12... or not 01, 02... - only the scores 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

    Here is the code i have now:

    set_flashIf( empty($_POST['everyhit']), 'Ooops... Please fill in the everyhit field');
    set_flashIf( empty($_POST['birthday']), 'Ooops... Please fill in the birthday field');
    set_flashIf( empty($_POST['youtube']), 'Ooops... Please fill in the youtube field');
    set_flashIf( empty($_POST['rate']), 'Ooops... Please fill in the rate field');
    redirectIf(flash_exists(), 'moderator/index.php?'. $_SERVER['QUERY_STRING']);
    PHP:
    Can someone please add on the code needed for this please as i need to fix it urgently, thanks for your help
     
    oo7ml, Oct 19, 2007 IP
  2. piniyini

    piniyini Well-Known Member

    Messages:
    514
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    170
    #2
    How about somthing like

    $field = (int) $_POST['rate'];

    if ($field < 1 || $field > 10 )
    {
    echo("error");
    }
     
    piniyini, Oct 19, 2007 IP