Page 1 of 1
how to use objects in forms
Posted: Tue Oct 28, 2003 10:19 pm
by phpIsKillingMe
how do i include objects into forms?
how would in put the object into a form so a customer can select it and have the program post the selected item? i can do this in an array put dont understand how id do i this with objects..
does this make sense? let me kno if u need me to clarify anything
for instance:
Code: Select all
<?php
class product
{
var $name, $price;}
$product1 = new product
$product1 -> name = 'hat';
$product1 -> price = 5;
?>
Posted: Wed Oct 29, 2003 3:32 am
by Fredix
For me it is not clear enough what you are trying to do. Your example will work but will not do anything useful. It just gives some variables of a calss some values. So what?
Posted: Wed Oct 29, 2003 6:40 am
by McGruff
You can use object properties the same way you use other vars eg echo them out in a form field in an html template.
Assuming you've got an object "$ob" (with a well-defined interface inc. getters for public object properties) an input field, for example, would go something like this:
Code: Select all
<input type="text" name="title" value="<?php echo $ob->getTitle(); ?>">
?>
Posted: Wed Oct 29, 2003 1:46 pm
by gite_ashish
in case u r talking about generating HTML form via PHP class:
Code: Select all
<?php
class product
{
var $name, $price;
function showForm() {
?>
<FORM name=frm action=next.php method=POST>
<INPUT name=name type=text>
<INPUT name=price type=text>
<INPUT type=submit>
</FORM>
<?php
}
}
$product1 = new product();
$product1->showForm();
// ... some process ...
//$product1 -> name = 'hat';
//$product1 -> price = 5;
?>
Posted: Wed Oct 29, 2003 2:24 pm
by phpIsKillingMe
yea, gite has the idea of what i want to do..thanks ..ima go try that out..
Posted: Wed Oct 29, 2003 2:36 pm
by m3rajk
also try looking up ther heredoc syntax of echo over at good ol
http://www.php.net
Posted: Wed Oct 29, 2003 6:14 pm
by JAM
m3rajk wrote:also try looking up ther heredoc syntax of echo over at good ol
http://www.php.net
Or not.
I first thought that someone made an interesting post on the topic. Upon reading it, it shows that you are trying to get phpIsKillingMe (nice nick btw) to use the heredoc syntax...
I'm now wondering what that helps, when working with objects and forms?
Posted: Wed Oct 29, 2003 6:59 pm
by McGruff
You really don't want html in php scripts - use templates.