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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:59:52+00:00 2026-05-21T20:59:52+00:00

We have built custom forms and at this stage are built very well with

  • 0

We have built custom forms and at this stage are built very well with a lot of thought. Each class has its own responsibility and so far the basic principle of OOP concepts have been used i.e. inheritance, polymorphism, encapsulation, etc. Each element of the form is an object and all objects are collected and initiated on the fly.

Now weve got to the processing part of the forms we at a loss for a strategy to deal with this and would like to ask if anyone has any pointers please?

Is there an alternative, say for instance the creation of a class that could be responsible for checking if the form has been submit and methods to gather post data, validate, etc or do people still do the old way like a quick conditional in the client to check if form submit:

if(isset($_POST["var"])
{
//process form
} else {
//show form
}

And would it be best to use a separate action page to process?

Bascially what I dont want to do is have to write some awful code thats not reusable or make use of OOP concepts. We would like to achieve something WITHOUT USING ANY FRAMEWORKS.

  • 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-21T20:59:53+00:00Added an answer on May 21, 2026 at 8:59 pm

    I would try to go with structure like this :

    // public function __construct( ValidatorInterface $validator )
    $form = new Form( new Validator );
    
    
    // public function add_field( $name , array $rules = array() )
    $form->add_field( 
       'name',  
        // that would be $_POST['name'] , and in template file <?php echo $name ?>
        array(
           'required'  => 'Full Name is required' 
           // for validator to execute is_required()
        ));
    $form->add_field( 
       'email' ,
        array( 
           'required'  => 'Email Address is required', 
           'email'     => 'A valid email address is required' 
           // for validator to execute is_email()
        ));
    $form->add_field( 'country' );
    
    //name of submit button
    $for->add_submitter( 'submit' );
    // etc 
    
    $page = new Template();
    $page->use_file( 'contact.php' );
    
    if( $form->is_submitted() )
    {
       // gathers all the $_POST's from registered fields
       $form->collect();
    
       if ($form->is_valid() )
       {
          $page->use_file( 'done.html' );
          // do some stuff 
       }
       else
       {            
          // public function populate( TemplateInterface $template )
          // assigns field values and error messages to the template
          $form->populate( $page );         
       }
    
    }
    
    echo $page->render();   
    

    And the Template class based upon this code : http://codeangel.org/articles/simple-php-template-engine.html


    update

    Implementation for method that registers new fields

    public function add_field( $name , array $rules = array() )
    {       
       if ( !array_key_exists( $name , $this->_fields ))
       {
          $this->_fields[ $name ] = array();
       }
    
       $this->_fields[ $name ]['rules'] = $rules; 
    }
    

    Implementation for method that finds values of all the registered fields

    public function collect()
    {           
       $field_names = array_keys( $this->_fields );
    
       foreach ( $field_names as $name )
       {                
          $this->_fields[ $name ]['value'] = $this->_collect_value( $name );                
       }
    
    }
    
    protected function _collect_value($name)
    {
    
       $value = null;
    
       if ( isset( $_POST[ $name ] ) )
       {
          $value = $_POST[$name];       
       }
    
       $value = trim( $value );
    
       if ( empty( $value ) ){
          $value = null;    
       }
    
       return $value;
    
    }   
    

    The data collection is pretty simple process.

    And on the is_valid() method call if get the Validator instance from local variable and performs actions on each registered form field ( mostly with helpfule php filter_var() function.

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

Sidebar

Related Questions

I have a custom built ajax [div] based dynamic dropdown. I have an [input]
We have a custom-built Flash-based video player that I maintain, and it needs to
I have a custom application that was built to send opt-in newsletters and marketing
I have a mac with a custom PHP 5 install that built from about
I have a custom control: it's managed code, which subclasses System.Windows.Forms.Control. I want to
I have a Windows::Forms application and I want to add a custom control to
I'm going to have to build a custom control for a WinForms application. But
I have three custom build configurations { Dev, Qs, Prd }. So, I have
I have inherited a visual studio 2003 project which uses some custom build steps.
We have a custom navigation webpart that uses the PortalSiteMapProvider of MOSS to build

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.