SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Solved] pear Quickform - required fields

    I've been google searching and tutorial reading for a few days now, and I have a good understanding of how to use pear Quickform. But I'm having trouble figuring out how to setup the rules so that fields are required based on previous field selections.

    My form has a section where the user must answer the following:
    -------------------------------------------------------
    Type of Schooling:
    School
    Homeschool
    Daycare or at Home

    If selected "School" above, please select school name:
    AJ Elementary
    Schooner Elementary
    Bridgeview Academy
    Other

    If selected "Other" please specify: _______________
    -------------------------------------------------------

    So only if the user first selects school is the second field required, and only if in the second field they select other is the third field (input box) required.

    Any thoughts on how the rule code would be setup for such a requirement? I'm thinking maybe I need to use a Callback Function.. but not sure.
    Last edited by jeremyfoster; Jun 2, 2009 at 11:48.
    -Jeremy

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured out a solution to this problem...

    PHP Code:
    if ($form->validate()) {
     if(
    $form->process('school_check')) {
         echo 
    'validated';
     } else {
         echo 
    "not valid";
         
    $form->display(); 
     }
    } else {
        
    $form->display(); 


    function 
    school_check($data) {
      if (
    $data['school_type'] == '1') {
       if (
    ctype_digit($data['school']) && $data['school'] != 2) {
         return 
    true;
       } elseif (
    ctype_digit($data['school']) && $data['school'] == && !empty($data['other'])) {
            return 
    true;
            } else {
                return 
    false;
            }
        } else {
            return 
    true;
        }

    -Jeremy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •