www.webdeveloper.com
Results 1 to 2 of 2

Thread: Form handling

  1. #1
    Join Date
    Aug 2007
    Location
    Washington
    Posts
    219

    Form handling

    Since there are a lot of questions on forms, I figured I'd add my own. What is the best method of handling forms in your opinion? Everything by classes? Using a framework like CodeIgniter?

    I ask because the forms I've been making are what I would consider rudimentary and time consuming. I'm looking for a better way of doing them. I've attached an example of what my forms look like (don't feel the need to read through it all, its kinda hellish).

    I do use a couple classes, but still theres a lot of things I have to change for every new form I make.

    scragar, if you read this, you mentioned you had a class for handling forms, and I was wondering how that worked?
    Attached Files Attached Files
    Last edited by bejitto101; 01-08-2009 at 07:39 AM.

  2. #2
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    My form handler is made for writing forms, with a bit of work into taking the input, it's hard to explain, but it runs a bit like this:
    PHP Code:
    $form = new Form(Array('name'=>'login''action'=>'?''method'=>'post''submit'=>'log in'));

    $username $form->addInput(Array('type'=>'text''name'=>'username',
                   
    'label'=>'Username: ''saveDefault'=>true,
                   
    'validate'=>'[0-9a-zA-Z]''required'=>''));
    $password $form->addInput(Array('type'=>'password''name'=>'password',
                   
    'label'=>'Password: ''saveDefault'=>false,
                   
    'validate'=>'[0-9a-zA-Z]''required'=>'You must enter a password'));

    $remember $form->addInput(Array('type'=>'checkbox''name'=>'username',
                   
    'label'=>'Remember Me? ''value'=>'Y'));

    if(
    $form->IsSubmitted()){
      if(
    $form->IsValid())
        echo 
    "<p>You entered: {$username->display} and {$password->display}.</p>";
      else
        echo 
    "Your input failed, the errors are: {$form->errors}";
    }else{
      echo 
    $form;

    But I will warn you that the class works only on PHP5.1+, and the code in it is far from pretty(it also uses 4 classes: Form, InputBox, SelectBox and Button).

    It's also not exactly efficient, I can think of lot's of ways to make it more efficient if I wanted, but for now I'm happy to let it slide.
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles