Forums

How to create a price list

pierpari 18 Feb, 2014
Hi,
I have this problem:
I want create a form for insert price lists of services. I need to read services from database.services and print all services and near every service an input text box for insert the relative service price and register into database.price the price with service.id.
I hope you understand me… sorry for my english🙂

Thanks
GreyHead 19 Feb, 2014
Hi pierpari,

In ChronoForms v4 I would do this using a DB Record Loader action (DB Read in CFv5) to get the data, then use a Custom Element element with PHP to create a set of inputs in the form of a table.

Bob
pierpari 20 Feb, 2014
Thanks Bob,
it's ok with your method but when i submit form it save only latest field.

I have database.price with id, service_id and price. In the custom form i have created a cycle when the field name is ever "price" and so it save only latest value.

what I must make?

Thanks
GreyHead 20 Feb, 2014
Hi pierpari,

It sounds as though all your input elements have the same name. You either need to make them different e.g. price_1, price_2, or use an array name price[] to get them all submitted.

In this case a good solution might be price[service_id] so that you can associate the services and prices with a little code after the form submits.

Bob

Bob
pierpari 20 Feb, 2014
Hi Bob,
I have tried to rename fields in "price$service.id" (price1, price2, etc…) but if field name is not the same of the database field it not save
GreyHead 20 Feb, 2014
Hi pierpari,

Yes, you may need to add some PHP in a Custom Code action to match them up. I also assume that you may need to hand-code the MySQL query as you probably need to update many records.

Bob
pierpari 21 Feb, 2014
Thanks Bob,
I'll try
pierpari 03 Mar, 2014
Hi Bob,
i tried to add some PHP
<?php
$bb=$form->data['SERVIZI'];
foreach ($bb as $a)
{
$db =& JFactory::getDBO();
$query = "INSERT INTO `PeF_chronoengine_chronoforms_datatable_Listino1`(`id`, `uniq_id`, `user_id`, `created`, `modified`, `servizio_id`, `prezzo`) VALUES ('','','','','','$a['id']','3')";
$db->setQuery($query);
$db->query();  
}
?>

but don't work.
if i write this
<?php
$bb=$form->data['SERVIZI'];
foreach ($bb as $a)
{
echo $a['id'];
}
?>

it's ok.
If i write this
<?php
$db =& JFactory::getDBO();
$query = "INSERT INTO `PeF_chronoengine_chronoforms_datatable_Listino1`(`id`, `uniq_id`, `user_id`, `created`, `modified`, `servizio_id`, `prezzo`) VALUES ('','','','','','2','3')";
$db->setQuery($query);
$db->query();  
?>

it's ok too.
But if i add "foreach cycle" and "INSERT query" it don't work.

Why?😟(((((
This topic is locked and no more replies can be posted.