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

  • SEARCH
  • Home
  • 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 7856955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:52:34+00:00 2026-06-02T20:52:34+00:00

public function registration() { $this->load->library(‘form_validation’); // field name, error message, validation rules $this->form_validation->set_rules(‘user_name’, ‘User

  • 0
public function registration()
    {
    $this->load->library('form_validation');
    // field name, error message, validation rules
    $this->form_validation->set_rules('user_name', 'User Name', 'trim|required|min_length[4]|xss_clean');
    $this->form_validation->set_rules('email_address', 'Your Email', 'trim|required|valid_email');`enter code here`
    $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[4]|max_length[32]');
    $this->form_validation->set_rules('con_password', 'Password Confirmation', 'trim|required|matches[password]');
        }

i have done this in codeigniter performing validation. how can i do similar work in php native ? i mean validation

  • 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-02T20:52:36+00:00Added an answer on June 2, 2026 at 8:52 pm

    The way I’ve done it in the past is to build objects for it… a form object, a form field object and a form field validator object.

    So you’d create all your field objects and, if required, attach validators to them, then attach the whole lot to the form – so you sort of end up with something like:

    $oFieldUsername = new FormField('username', new Validator(Validator::TYPE_EMAIL));
    $oFieldPassword = new FormField('password', new Validator(Validator::TYPE_PASSWORD));
    
    $oForm = new Form(Form::METHOD_POST, '/path/to/action.php');
    $oForm->attachField($oFieldUsername);
    $oForm->attachField($oFieldPassword);
    
    //form has not been posted
    if(!$oForm->isReceived()) {
      $oForm->render('/path/to/view.tpl.php');
    }
    
    //the form HAS been posted but IS NOT VALID
    elseif(!$oForm->isValid()) {
      $oForm->render('/path/to/view.tpl.php');
    }
    
    //the form HAS been posted and the data LOOKS valid
    else {
      //do processing and hand-off
    }
    

    The validators deal with things like determining if the field data is required, if the data matches an empty string (RegExp) then it’s not required for instance.

    But they can also deal with email validation (with or without getmxrr() lookup) or anything else, you just build Validator types for specific cases… or you have generic Validators:

    new Validator(Validator::TYPE_EMAIL); //basic email validator
    new Validator(Validator::TYPE_EMAIL_WITH_MX); //email validator with getmxrr()
    new Validator(Validator::TYPE_REGEXP, '/^[\w]+$/'); //generic regular expression with the pattern to match as the second parameter
    new Validator(Validator::TYPE_INT_MIN, 10); //integer with a minimum value of 10
    new Validator(Validator::TYPE_REGEXP, '/^[\w\s]*$/', true); //the third parameter could be an override so that the validation is optional - if the field has a value it MUST validate, if it doesn't have a value, it's fine
    

    This gives you as much flexibility as you need with validation. All the Form::isValid() method does is loops through all the attached fields, checks to see if they have Validators and if so whether the Validator::isValid() method returns true.

    You could also attach multiple Validators to Fields with something like:

    //the field value must be an integer between 5 and 10 (inclusive)
    $oField->addValidator(new Validator(Validator::TYPE_INT_MIN, 5));
    $oField->addValidator(new Validator(Validator::TYPE_INT_MAX, 10));
    

    … that’s how I’ve done it anyway.

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

Sidebar

Related Questions

public function configure() { $this->widgetSchema['start_date'] = new sfWidgetFormInput(); $this->widgetSchema['end_date'] = new sfWidgetFormInput(); $this->validatorSchema->setPostValidator( new
public function index() { $this->redirect('/'); } I will just go insane soon... How can
public function process(Zend_Controller_Request_Abstract $request) { $this->first_name = $this->sanitize($request->getPost('first_name')); .... } My question is $request
Consider: public function & get($name, $default = null) Why & ?
I have this method: public function activation_code() { //activation code sent into db $activation_code
i'm trying to define a User registration class and this is the function i
public function __construct($input = null) { if (empty($input)){ return false; } and then there's
public function test(){ $data = ORM::factory('testdata')->find_all(); Table::factory() ->set_body_data($data) ->set_row_titles('id') ->set_column_titles(Table::AUTO) ->set_callback('format_row', 'row') ->render(true); $this->template->title
public function bmdToStr(bmd:BitmapData,width:int,height:int):String { var encoder:JPEGEncoder = new JPEGEncoder(); var encBytes:ByteArray = encoder.encode(bmd); return
Public Function CastToT(Of T)(ByVal GenericType(Of Object) data) As GenericType(Of T) Return DirectCast(data, GenericType(Of T))

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.