Re: Oputting Forms Within a Class

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Your suggestion borders the MVC design pattern, which I've used within flash, groovy. Also, the following document illustrated an interesting solution, what are your thoughts?

7. Print form elements' defaults with helper functions.
<http://www.onlamp.com/pub/a/php/2004/08/26/PHPformhandling.html>

CK



On Apr 10, 2007, at 1:49 PM, Richard Davey wrote:

CK wrote:

private function buildInt(){
<!--Script 10.1- calculator.php-->
<form action="calculator.php" method="post">
    //Form elements omitted for brevity....
    </form>
 }
}
?>
This is returned to the browser:
"Parse error: syntax error, unexpected '<' in /Users/chris/Sites/ php/oop/class.calculator.php on line 20"

Your buildInt() function jumps directly from PHP into HTML output, without first closing the currently open PHP tag. It needs to be:

private function buildInt()
{
?>
<!--Script 10.1- calculator.php-->
.. blah blah ..
<?php
}

The approach you are taking for this is going to cause you headaches in the future. I would strongly recommend that you make your class file do one of two things:

1) ECHO out the HTML, rather than dropping in and out of PHP. It gets real messy, real quick, especially when embedded in class files.

2) Build-up the HTML into a string and return it back to the calling PHP script, which can then echo it as required. I.e capture the output of your class, don't let the class itself ever output anything. (i.e. start to separate the presentation from the logic, if only mildly in this case)

Cheers,

Rich
--
Zend Certified Engineer
http://www.corephp.co.uk

"Never trust a computer you can't throw out of a window"

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux