how to use objects in forms

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpIsKillingMe
Forum Newbie
Posts: 5
Joined: Wed Oct 22, 2003 7:02 pm

how to use objects in forms

Post 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
&#123;
var $name, $price;&#125;

$product1 = new product
$product1 -> name = 'hat';
$product1 -> price = 5;
?>
User avatar
Fredix
Forum Contributor
Posts: 101
Joined: Fri Jul 18, 2003 2:16 pm
Location: Wehr (Eifel) Germany
Contact:

Post 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?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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(); ?>">
?>
User avatar
gite_ashish
Forum Contributor
Posts: 118
Joined: Sat Aug 31, 2002 11:38 am
Location: India

Post 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;

?>
phpIsKillingMe
Forum Newbie
Posts: 5
Joined: Wed Oct 22, 2003 7:02 pm

Post by phpIsKillingMe »

yea, gite has the idea of what i want to do..thanks ..ima go try that out..
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

also try looking up ther heredoc syntax of echo over at good ol http://www.php.net
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

You really don't want html in php scripts - use templates.
Post Reply