SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2005
    Location
    UK
    Posts
    539
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    form class with validation

    I am attempting my first ever class to simplify my already created php form. So far i have used:

    PHP Code:
    class form_format

        function 
    form_input($style$labelclass$label$fieldclass$name$id$type$value$extra$endinghtml)
        {
            
            
    $output $output 
            
    "    <div class=\"row\">
                <span class=\"
    $labelclass\">$label</span>        
                <span class=\"formw\">
                <input type=\"
    $type\" style=\"$style\" $fieldclass name=\"$name\" id=\"$id\" value=\"$value\" $extra>$endinghtml"
            return 
    $output;
        }

    }

    //this function (outside class) decides the css styling class:

    function css_output1($field,$num=false){
           if(isset(
    $_POST['add'])&&empty($_POST[$field])){
              echo 
    " class=\"label2\"";
           }
              elseif(isset(
    $_POST['add'])&&!empty($_POST[$field])&&$num&&!is_numeric($_POST[$field])){
              echo 
    " class=\"labelerror\"";
           }
        elseif(empty(
    $_POST[$field])){
              echo 
    " class=\"label\"";
           }
           else{
              echo 
    " class=\"labelpass\"";
           }


    //here my form is created:

    $myclass = &New form_format
    echo 
    $myclass->form_input("",css_output1('first_name'), "First Name *"css_output2('first_name'), "first_name""test""text"stripslashes($_POST[first_name]), """"); 
    I am trying to use the function css_output1 inside the form_input function within the class, to echo the correct css styling, set according to the parameters in the $myclass->form_input.

    This is in fact printing the styling outside of the actual form html code (heres the html output):

    HTML Code:
    class="label" class="normal"	<div class="row">
    			<span >First Name *</span>		
    			<span class="formw">
    
    			<input type="text" style=""  name="first_name" id="test" value="" >
    What am i doing wrong?

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    dont use echo inside the function.


Bookmarks

Posting Permissions

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