Display a link for each checkbox label

Friendly bump.. how can i get the value for each checkbox in the second CDD element in order to use it in link?
 
I believe that would be in $this->form->data[], which is an array keyed by full element name. The value for the CDD entry in the array would itself be an array, of selected values.

-- hugh
 
this is the actual code, but i can't make it work.. i understand wrong your message? If you'd like to test, use the login data for the first site (btw, i can't delete a site from that list)

Code:
$serviciu = $data['test_cdd___serviciu_raw'];
$clasa = $data['test_cdd___clasa_raw'];
$cks = $this->form->data['test_cdd___abonament_raw'];
foreach ($cks as $ck) {
$value = $ck;
}
$opt->text .= ' | <a target="_blank" href="http://www.google.com/?serviciu='. $serviciu .'&clasa='.$clasa.'&abonament='.$value.'">Modifica</a>';
 
Have you tried dumping out the data, see what you get?

Put this ...

var_dump($cks);exit;

... after you grab it from the data array. See if it actually contains anything. If not, try dumping $form->data, see what that has in it.

We are talking about the eval'ed opts for a CCD, right?

-- hugh
 
Yes, i'm using the eval'ed options for this ccd (it's CCD or CDD?, just to know for future :) ) . Using var_dump($cks);exit; doesn't return anything, the checkboxes disappeared. Same for var_dump($form->data).
 
In that screencast I just imploded the array back in to a comma separated string, which isn't what you need to do. And I'm actually using the values for the same CDD I have that code on, not a different one. But it's just illustrating the point that a checkbox CDD in the data array is an array of selected values, which you can bust up with explode() and do what you need to with.

BTW, seems like single select joins / CDDs (rendered as dropdown) are not arrays when we are building the form, they are simple strings. Slightly different to submission time, when all joins / CDD's, whether multiselect or not, are arrays. But those rendered as checkboxes are arrays.

-- hugh
 
sorry for wrong typing, i've tested with $this->form->data, the result is the same.
Here is the code that i have tested now, i tried your code, nothing is displayed in the page.

Code:
var_dump($this->form->data);exit;
$serviciu = $data['test_cdd___serviciu_raw'];
$clasa = $data['test_cdd___clasa_raw'];
$cks = implode(',',$this->form->data['test_cdd___abonament_raw']);
$opt->text .= ' | <a target="_blank" href="http://www.google.com/?serviciu='. $serviciu .'&clasa='.$clasa.'&abonament='.$cks.'">Modifica</a>';

Please note that this is the second CDD in the form, and the values are loaded based on a previous CDD selection from a dropdown.

As usual, "My Site" is available for testing.
 
Have you tried just $data?

Code:
$city_auto_raw = is_array($data['fab_cdd_test___city_auto_raw']) ? $data['fab_cdd_test___city_auto_raw'] : array($data['fab_cdd_test___city_auto_raw']);
$qs = implode(',', $city_auto_raw);
$opt->text .= ' <a target="_blank" href="http://example.com/' . strtolower($opt->text) . '/' . $qs . '">Go There</a>';

My 'city_auto' is another CDD in the same group. I tried it on form load, and when updating the CDD the code is on, and that seems to work.

The $data array is passed in to _getOptionVals(), and should be the current form state, regardless of where it is called from. I haven't tested what happens on a new form, so you ay want to throw in an array_key_exists() test for it before doing anything, to avoid warnings.

-- hugh
 
I tried with $data, with $this->form->data, as placeholder..can't make it work, i can't get the value for each checkbox displayed in the CDD element. Please, if you have some free time, please take a look here using the logn data from "My Sites";
 
Well, your loop isn't right ...

Code:
$subs = $data['test_cdd___abonament_raw'];
foreach($subs as $sub){
$value = $sub;
}
$link[] = 'abonament='.$value;

So each time round the loop, you just overwrite the current $value ... so then you just wind up setting 'abonament=' to whatever the last $subs value was.

I don't know what format you want that abonament= query string arg in, but if you wanted it as a comma separated list, I've re-written it as.

Code:
$link = array();
$link[] = 'serviciu='.$data['test_cdd___serviciu_raw'][0];
$link[] = 'clasa='.$data['test_cdd___clasa_raw'];
$link[] = 'abonament='.implode(',', (array)$data['test_cdd___abonament_raw']);
$qs = implode('&', $link);
$opt->text .= ' <a target="_blank" href="http://example.com/' . $qs . '">Go There</a>';

However ... this is only going to happen when the CDD is rendered. I didn't realize you are trying to use the selection from the same CDD. So when you select another checkbox in that CDD, it isn't going to re-create all those link "on the fly" in the page. You'd have to do that with JavaScript.

But it should work for rendering a newly saved form in details view. But it's not going to work in list view, as the list rendering doesn't run through the _getOptionVals() method, although perhaps it should.

-- hugh
 
Ok, i quit to use the CDD element and move to a calc element that do the same thing but is more easy to be used.

However, i wonder how can i periodically refresh the calculation element (just this element) in order to get the values from a query. To be more explicit, i want to change the text of a link from "Add" to "Modify" if the value in database has been changed, without reloading the entire page, just this element.

This is the code i use now for the calc element, i've added a comment here to show you what i need to be changed based on the query interogation:

Code:
$nr = '{contracte_campuri___camp_firma}';
$serviciu = '{contracte_campuri___camp_serviciu_raw}';
$abonament = '{contracte_campuri___camp_abonament_raw}';
$clasa = '{contracte_campuri___camp_clasa_raw}';
$link = JURI::root(); 
$db =& JFactory::getDBO();
$db->setQuery("select a.id as IDEXTRA, a.extraoptiune from contracte_extraoptiuni a left join contracte_extraoptiuni_repeat_clase_extraoptiune b on a.id = b.parent_id where b.clase_extraoptiune = $clasa");
$extras = $db->loadObjectList();
$list = array();
$list[] = '<ul>';
foreach($extras as $extra) {
$idextra = $extra->IDEXTRA;

//the query that check if there is a new value in the database table. Based on this result, the "$text" string below should change

$db->setQuery("select id_ctr from contracte_extraoptiuni_disponibile where id_ctr = $nr and extraoptiune=$idextra and abonament=$abonament and serviciu = $serviciu and clasa =$clasa");
$idctr = $db->loadResult();

//how to update "on the fly" this value based on the query result?

if ($idctr > 0) {
$text = 'Modifica';
} else {
$text = 'Adauga';
}


$list[] = '<li>'.$extra->extraoptiune.' | <a href="'.$link.'extraoptiuni.php?serviciu='.$serviciu.'&clasa='.$clasa.'&abonament='.$abonament.'&nr='.$nr.'&extraoptiune='.$idextra.'" target="new">'.$text.'</a></li>';
}
$list[] = '</ul>';
return implode($list);

Thank you
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top