Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 131,530 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 2,092 people online right now. Registration is fast and FREE... Join Now!




form creating using oop

 
Reply to this topicStart new topic

form creating using oop

dreamincodehamza
post 5 Oct, 2008 - 11:35 PM
Post #1


D.I.C Head

Group Icon
Joined: 12 Sep, 2008
Posts: 108



Dream Kudos: 75
My Contributions


Can anyone check this code and tell me how it is
and
is it usefull or not if not then how should i make it usefull.

source code is
CODE
<?php
/**********************************/
/***** Form Create using OOP *******/
/**********************************/
/**********************************/
class form {

    //Input Attributes
    public    $type;
    public    $name;
    public    $value;
    public  $text;
    public $opttext;
    //Select Methods                        
    public $optValues = array();
    public $starttag;
    public $action;
    public $method;
    /* form tag */
    function formtag() {
      if($this->starttag=='true') {
          echo "<form action='". $this->action ."' method='". $this->method ."'>";
      }    else {
          echo "</form>";
      }          
    }
                
     //Input Fields
     function input() {    

        if($this->type=='text') {
                echo $this->text."<input type='". $this->type ."' name='". $this->name ."' value='". $this->value ."'> ";                                                                   
        } else if ( $this->type=='select') {
                echo $this->text."<select name='". $this->name ."'> ";
                for($i=0; $i< count($this->optValues);$i++ ) {
                    echo "<option value='". $this->optValues[$i] ."'>". $this->optValues[$i] ." </option> ";
                }
                echo "</select>";                        
        } else if($this->type=='radio' || $this->type=='checkbox') {        
                echo $this->text."<input type='". $this->type ."' name='". $this->name ."' value='". $this->value ."'>".$this->opttext;                                                                   
        } else if($this->type=='button' || $this->type=='submit') {                            
                echo "<input type='". $this->type ."' name='". $this->name ."' value='". $this->value ."'> ";                                                                   
        } else {
           echo "Please enter the type";
        }                
     }//method end.  
    
    function br() {
            echo "<br />";
    }//if end                            
    
}//formFields class end.  
$formInputs = new form;
        
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>OOPs Form</title>
</head>
<body>
<?php

    $formInputs->starttag='true';
    $formInputs->action ='';
    $formInputs->method ='post';    
    $formInputs->formtag();
        
    $formInputs->text  = "Name";
    $formInputs->type  = "text";
    $formInputs->name  = "";
    $formInputs->value =    "";    
    $formInputs->input();
    $formInputs->br();
    
    $formInputs->text  = "DOB";
    $formInputs->type  = "text";
    $formInputs->name  = "";
    $formInputs->value =    "";    
    $formInputs->input();
    $formInputs->br();
    
    $formInputs->text    = "Gender";
    $formInputs->type    = "radio";
    $formInputs->name    = "gender";
    $formInputs->opttext = "Male";    
    $formInputs->input();
    
    
    $formInputs->text    = "";
    $formInputs->type    = "radio";
    $formInputs->name    = "gender";
    $formInputs->opttext = "Female";    
    $formInputs->input();    
    $formInputs->br();        
    
    $formInputs->text  = "Country";
    $formInputs->type  = "select";
    $formInputs->name  = "country";    
    $formInputs->optValues[] = 'Pakistan'; $formInputs->optValues[] = 'Afganistan'; $formInputs->optValues[] = 'usa';
    $formInputs->optValues[] = 'Srilanka'; $formInputs->optValues[] = 'Malashia';      $formInputs->optValues[] = 'Rrussia';
    $formInputs->input();
    $formInputs->br();
    
    $formInputs->type  = "submit";
    $formInputs->name  = "";
    $formInputs->value = "Submit";    
    $formInputs->input();
    $formInputs->br();
    
    $formInputs->starttag='false';
    $formInputs->formtag();
?>        
</body>
</html>



User is offlineProfile CardPM

Go to the top of the page


pemcconnell
post 6 Oct, 2008 - 12:39 AM
Post #2


D.I.C Regular

Group Icon
Joined: 5 Aug, 2008
Posts: 392



Thanked 35 times

Dream Kudos: 75
My Contributions


I'm just going to throw this out there but I'm guessing that you didn't write that code?

It's far more beneficial to learn the code and then create the functions / classes to solve the problems you are presented with.

In short that class will allow you to create an HTML form by using the PHP class. Imho, I would recommend you create your form in HTML unless you are looking to make a massive / dynamic form.
User is online!Profile CardPM

Go to the top of the page

dreamincodehamza
post 7 Oct, 2008 - 10:51 AM
Post #3


D.I.C Head

Group Icon
Joined: 12 Sep, 2008
Posts: 108



Dream Kudos: 75
My Contributions


Can you give me any example of creating for using php classes .
User is offlineProfile CardPM

Go to the top of the page

William_Wilson
post 7 Oct, 2008 - 10:58 AM
Post #4


lost in compilation

Group Icon
Joined: 23 Dec, 2005
Posts: 3,951



Thanked 13 times

Dream Kudos: 3275

Expert In: Java, C, Javascript

My Contributions


http://www.spoono.com/php/tutorials/tutorial.php?id=27
User is offlineProfile CardPM

Go to the top of the page

dreamincodehamza
post 7 Oct, 2008 - 11:25 AM
Post #5


D.I.C Head

Group Icon
Joined: 12 Sep, 2008
Posts: 108



Dream Kudos: 75
My Contributions


mr william
can you create a form using oop.
few text fields for me.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/20/08 01:34AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month