Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8181339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:29:20+00:00 2026-06-07T00:29:20+00:00

Hie guys i need help with my code. I have a form where a

  • 0

Hie guys i need help with my code. I have a form where a student selects subjects, marks and grades they obtained. Subjects and grades are a dropdown menu and they are in a loop. I want a student to enter at least five subjects including english language. each subject is referenced by a subject code. An array of the students details is saved. Can you help me do this?

My controller function is as follows

public function add($app_id = null) {
        if($app_id != null){

            if ($this->request->is('post')) {

        //saving the data in variables
                $applicant_id = $this->data    ['ApplicantOlevelQualification']['applicants_detail_id'];
            $centre_number = $this->data['ApplicantOlevelQualification']['centre_number'];
            $candidate_number = $this->data['ApplicantOlevelQualification']['candidate_number'];
            $exam_body_code = $this->data['ApplicantOlevelQualification']['exam_body_code'];
            $year_written = $this->data['ApplicantOlevelQualification']['year_written'];
        $sittings=$this->request->data['ApplicantOlevelQualification']['number_of_sittings'];
    //  debug($sittings);die();

        for ($i = 1; $i < sizeof($this->data['ApplicantOlevelQualification']['olevel_subject_code']); $i++) {

                if ($this->data['ApplicantOlevelQualification']['olevel_subject_code'][$i] != "") {
                    $this->ApplicantOlevelQualification->create();
                    $this->ApplicantOlevelQualification->id = null;
                    $this->ApplicantOlevelQualification->set(array(
                            'applicants_detail_id' => $app_id,
                            'olevel_subject_code' => $this->data['ApplicantOlevelQualification']['olevel_subject_code'][$i],
                            'grade' => $this->data['ApplicantOlevelQualification']['grade'][$i],
                            'centre_number'=> $centre_number, 
                            'candidate_number'=> $candidate_number, 
                            'exam_body_code'=> $exam_body_code,
                            'year_written'=> $year_written,

                        )
                    );

                    //$appeng = $this->ApplicantOlevelQualification->find('list',array('fields'=> array('olevel_subject_code','grade'), 'conditions'=>array('ApplicantOlevelQualification.olevel_subject_code'=>'8900',)));
                 //debug(($this->data->ApplicantOlevelQualification);die();
                 /*    if($appeng !="8900"){
                   $this->Session->setFlash(__('English is a prerequisite for application to procceed'));
                   $this->redirect(array('action' => 'add',$app_id));

                     }  */                   

                    if ($this->ApplicantOlevelQualification->save()) {      
                        $this->Session->setFlash(__('Your O\'level Qualifications have been saved'));
                    }   else {
                        $this->Session->setFlash(__('Your O\'level Qualifications failed to save.'));
                    }
                }
            }

My model is as follows

public $validate = array(
'grade' => array(
        'notempty ddd' => array(
            'rule' => array('notempty'),
            //'rule' => '/^[A-Z]{1}$/i',
            'message' => 'Enter a valid grade, in capital letters!',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
        ),
    ),
'olevel_subject_code' => array(
        'numeric' => array(
            'rule' => array('numeric'),
            //'message' => 'Your custom message here',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
        ),
    ),
);

Currently this code captures subjects and grades together with the details without checking if a student has entered the required minimum of 5 sujects and their grades. Please help me if you can. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:29:21+00:00Added an answer on June 7, 2026 at 12:29 am

    You should write your own custom validation rule(s). To do that add it to $validate:

    public $validate = array(
    'grade' => array(
            'notempty' => array(
                'rule' => array('notempty'),
                'message' => 'Enter a valid grade, in capital letters!',
            ),
            'mycustomrule' => array(
                'rule' => array('mycustomgraderule'),
                'message' => 'One or more of your subjects do not have grades'
            )
        ),
    'olevel_subject_code' => array(
            'numeric' => array(
                'rule' => array('numeric'),
            ),
        ),
    );
    

    Where mycustomgraderule is actually another method in the same Model:

    public function mycustomgraderule($check) {
    //   Your logic here    
    }
    

    This method should return TRUE when the check validates and FALSE when it does not.
    You can do the same for olevel_subject_code, but if you’re looking to validate both at least 5 subjects entered so that every subject has a grade entered I propose you create one
    method for both and put it as a custom validation rule in 'olevel_subject_code' in $validate. The $check parameter holds the data for the field being validated. In this (and every) custom rule you can use the Model’s $this->data property, which holds all of the current Model data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hie i have a html form and while posting a request to a url
hie guys. I have ParentPage which contains 4 user controls and i have user
Hie frnds, I have two tables say Orders and OrdersXML now I wish to
Hie Everyone I have 1st time developed SSRS in my WPF application.. but there
Hie all, I indeed underline to points. I have been trying jboss 7 +
hie i have all my web application contents inside a directory ui/page of WEB
Hie! I have a JTable. Columns of this JTable are rendered by JComboBox. I
Hie ! I have nor words neither skills to find answer so i ask
hie all, my query is this select * from [order] where createdon<getdate()-7 and orderid
Hie I use the GET method for navigation on one of my websites. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.