tags:

views:

484

answers:

1

Hi,

I'm constructing an ecommerce application in Symfony, and I have a page which lists the products within a specific category, eg at the URL "/categories/list/id/1":

Product 1
Product 2
...

I'd like to have something of the form:

Product 1
* Add [ 1 ] of these to your shopping cart [Go]

Product 2
* Add [ 1 ] of these to your shopping cart [Go]

on the same page, so I presume I'm going to need to derive from the sfForm class and construct my own form, as the automatically-generated forms have been. Should this be named according to the categories model? Or would it be more appropriate to be named according to the "cart" model (where my shopping cart will be stored)? and how would this link into eg my listProductsByCategorySuccess.php template?

Hope the above makes sense!

Thanks,

-rich

+1  A: 

As per 1.1 or 1.2 sfForm is a standalone library (sort of) that has no connection to your DB unless you extend from Doctrine/Propel sfForm.

Because it is standalone you can use it as you will, and you only need to create one form

class AddProductForm extends sfForm {

}

and set it up with a hidden widget that will hold your product_id and a product_count text input which should be the number of products a user wants to order.

Then just do the standard if ($form->isValid()) stuff and insert it into a database and/or into a cookie and/or a session for use in the checkout process.

Can provide a more in depth example if u need it :) But just hang in there, sfForm is difficult at the beginning.

Henrik Bjørnskov
Spot on - sfForm was the way, it was just getting my head around it after using the automatically generated admin stuff. Cheers! :-)
richsage