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 6212573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:32:26+00:00 2026-05-24T06:32:26+00:00

How do I prevent my user from submitting an empty form? When I do

  • 0

How do I prevent my user from submitting an empty form?
When I do that, I’m getting a HTTP 404 not found error in IE and a blank page in Firefox.
None of the validation errors are showing up.

I even tried putting an else stmt in the StudentsController’s add function and that too is not firing. Nothing shows up for die(debug($this->Student->validationErrors)) either

I also have a beforeFilter in StudentsController. But I don’t think that is causing any prob coz’ i have already tried running this website by commenting the beforeFilter.

students_controller.php

 <?php
  class StudentsController extends AppController{
  var $name='Students';
  var $helpers = array('Html','Form','Ajax','Javascript');
  var $components=array('Security','RequestHandler');

 function beforeFilter()//executed before any controller action logic
{   
        //parent::beforeFilter();
    if(isset($this->Security) && $this->RequestHandler->isAjax() && $this->action = 'getcities'){
        $this->Security->enabled = false;
        } 

}


  function add(){

    if (!empty($this->data)){

            //$student=$this->Student->saveAll($this->data,array('validate'=>'first'));
            //var_dump($student);
                  if ($this->Student->saveAll($this->data)){
                     $this->Session->setFlash('Your child\'s admission has been received. 
                     We will send you an email shortly.');
                     $this->redirect(array('controller'=>'pages', 'action'=>'home'));
                  }else{
                     $this->Session->setFlash(__('Your admission could not be saved. Please, try again.', true));  
                  }

    } //for if (!empty....

    $states=$this->Student->MerryParent->State->find('list');
    $this->set('states',$states);

    $cities=array();    
}//end function
  }
  ?>

Following are my models with validation:
student.php

  <?php
   class Student extends AppModel{
var $name='Student';
var $belongsTo=array('MerryParent','MerryClass','State','City');

var $validate=array(
        'name'=>array(
                'rule'=>array('minLength',3),
                'required'=>true,
                'allowEmpty'=>false,
                'message'=>'Name is required!'
                ),
        'dob'=>array(
                'rule'=>'date',
                'required'=>true,
                'allowEmpty'=>false,
                'message'=>'Enter a valid birth date!'
                ),
        'class_id'=>array(
                'rule'=>'notEmpty', 
                'message'=>'Which class are you enquiring about?'
                )
        //'city_id'=>array('rule'=>'notEmpty','message'=>'Please select your city','required'=>true, 'allowEmpty'=>false)
        );

}
?>

merry_parent.php

  <?php
    class MerryParent extends AppModel{
var $name='MerryParent';
var $hasMany=array(
    'Student'=>array(
        'className'=>'Student',
        'foreignKey'=>'merry_parent_id'
                )
            );
var $belongsTo=array('State','City','MerryClass');

var $validate=array(
            'initial'=>array(
                'rule'=>'notEmpty',
                'message'=>'Please select your initial'
                ),
            'name'=>array(
                'rule'=>array('minLength',3),
                'required'=>true,
                'allowEmpty'=>false,
                'message'=>'Name is required!'
                ),
            'email'=>array(
                'rule'=>'email',
                'required'=>true, 
                'allowEmpty'=>false,
                'message'=>'Valid email address required!'
                ),
            'landline'=>array(
                   'rule'=>array('custom','/(0[0-9]{2,4}-[2-9][0-9]{5,7})/'), 
                   'required'=>false, 
                   'allowEmpty'=>true, 
                   'message'=>'Invalid phone number! phone number format: eg 020-22345678 OR 0544-7573758 OR 02345-874567'
                   ),
            'mobile'=>array(
                 'rule'=>array('custom','/([89]{1}[0-9]{9})/'), 
                 'required'=>true, 
                 'allowEmpty'=>false, 
                 'message'=>'Invalid mobile number! mobile number format: eg 9876543211'
                 ),
            'address'=>array(
                 'rule'=>array('alphaNumeric',array('minLength',1)),
                 'required'=>true, 
                 'allowEmpty'=>false, 
                 'message'=>'Please enter your address.'
                 ),
        'state_id'=>array(
                'rule'=>'notEmpty',
                //'required'=>true,
                'message'=>'Please select your state'
                ),
            /*'city_id'=>array('rule'=>'notEmpty','message'=>'Please select your city','required'=>true, 'allowEmpty'=>false),
            'state_id'=>array('rule'=>'notEmpty','message'=>'Please select your state','required'=>true, 'allowEmpty'=>false),*/
            'postal_code'=>array(
                     'rule'=>array('numeric',6),
                     'required'=>true, 
                     'allowEmpty'=>false,
                     'message'=>'valid postal code required!'
                     )
            );//closing bracket for $validate array
   }
  ?>    

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-05-24T06:32:29+00:00Added an answer on May 24, 2026 at 6:32 am
    if (!empty($this->data)){
      if ($this->Student->saveAll($this->data)){
         $this->Session->setFlash('Your child\'s admission has been received. We will send you an email shortly.');
         $this->redirect(array('controller'=>'pages', 'action'=>'home'));
      }else{
         $this->Session->setFlash(__('Your admission could not be saved. Please, try again.', true));  
      }
    }
    

    Edit: What’s the url when you get the 404? Because in default cake config, you’ll only get missing controller or missing action, but not 404. You don’t need to post the model, but do post the routes you have.

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

Sidebar

Related Questions

How can I prevent a user from accessing a page when they are not
After processing form from POST I should redirect, to prevent user from hitting back.
I want to prevent the user from maximizing the Windows Form to full screen
Suppose I have a form and I wanna prevent the user from submiting the
How do I prevent the user from resizing form dialogues in VB6? The dialogues
I need to prevent user from selecting text (select all or select a portion
Is it possible to prevent user from writing letters to a textbox (i.e. force
In wpf how can i prevent user from moving the windows by dragging the
How can I prevent a user from resizing GridViewColumns withing a ListView control?
How can I prevent the user from being able to resize an image in

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.