Forums

Dynamic options for select from file xls

zeus07 23 Aug, 2018
Hi!
Link: http://terra.artcolorit.com/schools-en/spanish-en/enforex-marbella-camp-albergue-en
Site using Zoo + JBZoo.
I have a calculator on Chronoforms V5 and want to migrate it on Chronoforms V6. For me, it's a little hard and I need your advice.
I need to fill options of all selects with values from xls file. I have PHP code which was written for Chronoforms V5, I did some changes for it:
$zoo = App::getInstance('zoo');
$itemId = JRequest::getInt('item_id');
$item = $zoo->table->item->get($itemId);
$this->data['itemname'] = $item->name;
$this->data['itemalias'] = $item->alias;

include_once('prices/classes/PHPExcel/IOFactory.php');

try {
$objPHPExcel = PHPExcel_IOFactory::load('prices/'.$item->alias.'.xlsx');

$allSheets = $objPHPExcel->getAllSheets();

$courses = $allSheets[0]->toArray(null,false,false,true);
$accomodations = $allSheets[1]->toArray(null,false,false,true);
$sbor = $allSheets[2]->toArray(null,false,false,true);

//Registration Fee
if ($sbor[1]['A']) {
$this->data['registration']=$sbor[1]['A'];
} else {
$this->data['registration']=0;
}

//Weeks
foreach($courses[1] as $col => $week)
$this->data['weeks'][]=array('week'=>$week);


//Accomodation
foreach($accomodations as $row => $type){
if (trim($type['A']) != '') {
$this->data['accomodations'][]=array('value'=>$row,'text'=>$type['A']);
}
}

//Course Prices
$this->data['prices_c'] = 'var p=new Array();';
foreach($courses as $row => $course){
if (trim($course['A']) != '') {
$this->data['courses'][]=array('value'=>$row,'text'=>$course['A']);
}
if($course['A']){
$this->data['prices_c'] .= "p[$row]=new Array();";
foreach($courses[1] as $col => $week){
if($week && $courses[$row][$col])
$this->data['prices_c'].= "p[$row][$week]={$courses[$row][$col]};";
}
}
}

unset($accomodations[1]['A'],$accomodations[1]['B']);
$this->data['prices_a'] = 'var a=new Array();';
foreach($accomodations as $row => $accomodation){
if($accomodation['A'] && $row > 2){
$this->data['prices_a'] .= "a[$row]=new Array();";
foreach($accomodations[1] as $col => $week){
if($week && $accomodations[$row][$col])
$this->data['prices_a'] .= "a[$row][$week]={$accomodations[$row][$col]};";
}
}
}
//Extra night
unset($accomodations[1],$accomodations[2]);

//currency symbol
$this->data['curr_symbol'] = $sbor[1]['C'];
} catch(Exception $e) {
echo $e->getMessage();
}
For the first select, I did another PHP action with courses and I can't to get options from it.
Look on the image please: https://prnt.sc/km5jxn - How I can get this values in first select?
I'd try writing this:
{var:courses.row}
But it doesn't work. Maybe I did a mistake. Help please to fill this select
GreyHead 24 Aug, 2018
Hi zeus07,

The one thing I can see immediately is that the PHP is using $this->data - that is no longer supported in CFv6. PLease check the CFv6 manual for the correct syntax to save to the form data.

Bob
GreyHead 28 Aug, 2018
Hi zeus07,

Apologies, it's summer holiday time here and I got it backwards.

I can only suggest that you add a Debugger action to see what is being added to the form data.

Bob
This topic is locked and no more replies can be posted.