Forums

Radio box linked to database

FloB 25 Mar, 2013
Hello!

What I want to do is to have a radio box group linked to some photos in a database, see below:
[attachment=0]radio_box_photo.PNG[/attachment]

To do that, I have a multi DB loader in the On Load event (model id = phoca), and a custom element on Preview.

There is the code of the custom element :
<div class="ccms_form_element cfdiv_radio radios_over" id="radio_load_container_div" style="">
	<label for="radio_load">Vos photos</label><input type="hidden" name="radio_load" value="" alt="ghost" />
	<div style="float:left; clear:none;">
		<?php
		$options_data = $form->get_array_value($form->data, explode(".", "phoca"));
		if(!is_null($options_data) && is_array($options_data)){
			$f_id = 0;
			foreach($options_data as $option_data){
				if(isset($option_data["id"]) && isset($option_data["filename"])){
					$form->data['chemin']="images".DS."phocagallery".DS.$option_data["filename"];
					echo '<input type="radio" name="radio_load" id="radio_load_'.$f_id.'" title="" value="'.$option_data["id"].'"'.(($option_data["id"] == NULL) ? ' checked="checked"' : '').' class="" />'."\n";
					echo '<label for="radio_load_'.$f_id.'">'."<img src="{chemin}" alt="image" width="200"/>".'</label>'."\n";
					$f_id++;
				}
			}
		}
		?>
	</div>
</div>


It's nearly working, as you can see on the screen view, but it seems that the value {chemin} is static and the same for each loop in the code (same photo on the result).
I was thinking that $option_data["filename"] was different so I would have different {chemin}.
The problem is maybe in the way to pass the value, perharps $form->data is not the right way, but I couldn't think of any other way...

How should I modify my code to make it "refresh" at each loop?

Thanks
Flo

Edit : I need the {} in the <img scr...> because it's the only way to make <img scr...> works. It doesn't accept $value. Is there a way to have a {value} without having $form->data['value']?
Or am I completly out with this way of thinking?
FloB 26 Mar, 2013
Hello!
I found it, I just needed to cut the string, integrate the value $chemin and continue the string (see below).
<div class="ccms_form_element cfdiv_radio radios_over" id="radio_load_container_div" style="">
	<label for="radio_load">Vos photos</label><input type="hidden" name="radio_load" value="" alt="ghost" />
	<div style="float:left; clear:none;">
		<?php
		$options_data = $form->get_array_value($form->data, explode(".", "phoca"));
		if(!is_null($options_data) && is_array($options_data)){
			$f_id = 0;
			foreach($options_data as $option_data){
				if(isset($option_data["id"]) && isset($option_data["filename"])){
					$chemin="images".DS."phocagallery".DS.$option_data["filename"];
					echo '<input type="radio" name="radio_load" id="radio_load_'.$f_id.'" title="" value="'.$option_data["id"].'"'.(($option_data["id"] == NULL) ? ' checked="checked"' : '').' class="" />'."\n";
					echo '<label for="radio_load_'.$f_id.'">'.'<img src="'.$chemin.'" alt="image" width="200"/>'.'</label>'."\n";
					$f_id++;
				}
			}
		}
		?>
	</div>
</div>


Hope this would help some people one day🙂
Flo
This topic is locked and no more replies can be posted.