SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2001
    Location
    Ottawa
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Is there a PHP HTML module available?

    It would be nice to be able to build dynamic HTML
    the Perl way.

    For example:
    Rather than:
    echo "<table>";
    echo...
    It would be nice to say:
    $tbl = new Table($rows, $columns, etc...)

    This is simplified, but that's the general idea.

    Thanks for suggestions,

    Zenon


  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use my handy dandy html class:

    PHP Code:
    <?

    class HTML {

            function form_start($action, $method = "POST", $extrahtml = "") {
                return sprintf('<form action="%s" method="%s" %s>', $action, $method, $extrahtml);
                }

            function form_end() {
                return "</form>";
                }

            function file($name) {
                return sprintf('<input type="file" name="%s">%s', $name, "\n");    
                }
            
            function table_start($width, $spacing = 0, $padding = 0, $border = 0) {
                return sprintf('<table width="%s" cellspacing="%s" cellpadding="%s" border="%s">%s', $width, $spacing, $padding, $border, "\n");
                }    
        
            function table_end() {
                return "</table>";
                }
                
            function text_box($name, $value = "", $size, $max, $error = "", $extrahtml = "") {
                return sprintf('%s<input type="text" name="%s" value="%s" size="%s" maxlength="%s" %s>%s', ($error != "") ? "<span class=error>".$error."</span><br>" : "", $name, stripslashes($value), $size, $max, $extrahtml, "\n");    
                }

            function check_box($name, $value, $key, $val) {
                return sprintf('<input type="checkbox" name="%s" value="%s" %s>%s', $name, $value, ($val == $key) ? " checked " : "", "\n");
                }
                
            function radio_button($name, $val, $value, $extrahtml = "") {
                return sprintf('<input type="radio" name="%s" %s value="%s" %s>%s', $name, $extrahtml, $val, ($val == $value) ? " checked " : "", "\n");
                }

            function hidden_input($name, $value) {
                return sprintf('<input type="hidden" name="%s" value="%s">%s', $name, $value, "\n");    
                }

            function text_area($name, $value = "", $cols, $rows, $error = "", $extrahtml = "") {
                return sprintf('%s<textarea name="%s" rows="%s" cols="%s" wrap="virtual" %s>%s</textarea>%s', ($error != "") ? "<span class=error>".$error."</span><br>" : "", $name, $rows, $cols, $extrahtml, stripslashes($value), "\n");    
                }
            
            function make_button($name, $value, $type, $extrahtml = "") {
                return sprintf('<input type="%s" name="%s" value="%s" %s>%s', $type, $name, $value, $extrahtml, "\n");    
                }

            function create_dd($data, $name, $value = "", $keys = "", $extrahtml = "", $error = "") {
                $tmp = explode(",", $data);
                $return .= sprintf('%s<select name="%s"%s>%s', ($error != "") ? "<span class=error>".$error."</span><br>" : "", $name, $extrahtml, "\n");
                if ($keys != "") {
                    $tmpk = explode(",", $keys);        
                    for($i=0;$i<count($tmp);$i++) {
                        if ($value == "") {
                            $return .= sprintf('<option value="%s">%s%s', $tmpk[$i], $tmp[$i], "\n");
                            }
                        else {
                            if ($value == $tmpk[$i]) { 
                                $return .= sprintf('<option value="%s" selected>%s%s', $tmpk[$i], $tmp[$i], "\n");
                                }
                            else {
                                $return .= sprintf('<option value="%s">%s%s', $tmpk[$i], $tmp[$i], "\n");
                                }
                            }
                        }
                    }
                else {
                    for($i=0;$i<count($tmp);$i++) {
                        if ($value == "") {
                            $return .= sprintf('<option value="%s">%s%s', $tmp[$i], $tmp[$i], "\n");
                            }
                        else {
                            if ($value == $tmp[$i]) { 
                                $return .= sprintf('<option value="%s" selected>%s%s', $tmp[$i], $tmp[$i], "\n");
                                }
                            else {
                                $return .= sprintf('<option value="%s">%s%s', $tmp[$i], $tmp[$i], "\n");
                                }
                            }
                        }
                    }
                $return .= sprintf('</select>%s', "\n");
                return $return;
                }


            
            
            
        }

    //Sample Usage:

    include("html.class");
    $html = new HTML;
    print $html->form_start($PHP_SELF);
    print $html->table_start(600,0,0,0);
    print "<tr><td>Hello World</td></tr>";
    print "<tr><td>". $html->text_box("name", $name, 20, 40) ."</td></tr>";
    print $html->table_end();
    print $html->form_end();






    ?>
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •