field select elements - How to get value for an index

More
13 years 3 days ago #20533 by Myl
Hi,

Maybe someone can help me..
I need to call the value from a "select field" in an item template.

I have created a select field with this field element:
1::name1%% 2::name2%% 3::name3%% 4::name4

I have selected in item element name2.

Now I need to stamp his value: 2.

I try this:
<?php echo $this->fields->value ?>

and the result is "Array".

How I can find the selected value? (In this case "2")

[I use Joomla 1.7 and the last beta release of Flexicontent (v2.0 beta5 r960)]

Thank you

Please Log in or Create an account to join the conversation.

More
13 years 3 days ago #20536 by ggppdk
You can use this:
it will give you the values of the field in an indexed array e.g.
echo $field_elements_arr[2];

put the name (not the label) of the field in the first row, the last line prints the values,
Code:
<?php $field_name = 'selsimple1'; $field_elements = $this->fields[$field_name]->parameters->get( 'field_elements' ) ; $field_elements_strings = explode("%% ", $field_elements); $field_elements_arr = array(); foreach ($field_elements_strings as $field_element_str) { list ($f_index, $f_value) = explode("::", $field_element_str); $field_elements_arr[$f_index] = $f_value; } echo "<pre>"; print_r($field_elements_arr); echo "</pre>"; ?>


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
13 years 3 days ago #20540 by Myl
Thankyou for your answer.
This is what I have after using you're code:

Array
(
[1] => name1
[2] => name2
[3] => name3
[4] => name4
[5] => name5
)

If I use:
echo $field_elements_arr[2]

I have:
name2

And is correct but I need that:
When in backend someone select "name2" in frontend I need only the number 2 because I need to use it for other thing..

How I can do this?

Another thankyou and sorry for my bad english :)

Myl

Please Log in or Create an account to join the conversation.

More
13 years 3 days ago #20543 by ggppdk
Code:
<?php $field_name = 'selsimple1'; //$field_name = $field->name; // IF you use a position $field_value0 = $this->fields[$field_name]->value[0]; //... the previous code i gave you echo $field_elements_arr[$field_value0]."<br>"; //... for many values: foreach($this->fields[$field_name]->value as $val) { echo $field_elements_arr[$val]."<br>"; } ?>

Regards


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
13 years 3 days ago #20545 by Myl
Thankyou, now I've the correct value :D

regards

Myl

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.340 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline