I a creating a plugin with several input/dropdown fields.
When I created the view of that page, only the number of the selection was viewed instead of the value of the array.
I fixed that with a switch, but have a strong feeling I am doing something wrong here. How should I be doing that right ?
This is example code for input:
$options = array("Simple","Regular","Complex","Very complex","Requires advice");
$defaults = array( 'name' => 'complexity', 'options_values' => $options,
);
if (isset($vars['entity'])) { $defaults['value'] = $vars['entity']->complexity; unset($vars['entity']); }
$vars = array_merge($defaults, $vars);
echo elgg_view('input/dropdown', $vars);
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by Raül Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Gerard@gkanters
Gerard - 0 likes
- Matt Beckett@Beck24
Matt Beckett - 0 likes
- Gerard@gkanters
Gerard - 0 likes
- Paweł Sroka@srokap
Paweł Sroka - 0 likes
- Gerard@gkanters
Gerard - 0 likes
- DhrupDeScoop@Dhrup2000
DhrupDeScoop - 0 likes
- Gerard@gkanters
Gerard - 0 likes
- DhrupDeScoop@Dhrup2000
DhrupDeScoop - 0 likes
You must log in to post replies.Is this question unclear or maybe posted in the wrong group ?
I'd say the question is unclear. What is the problem?
The problem is that the page that produces the output of this code is giving numbers (1,2,3,4,5) instead of the values of the array in $options ("Simple","Regular","Complex","Very complex","Requires advice")
I used pages plugin as skeleton for the plugin and that might have been a mistake.
When you use 'options_values', you should provide dropdown values as the keys of associative array and the values in array are just labels to display (you probably want to use elgg_echo there). If you want to use your $options as labels and values at the same time, just use 'options' parameter instead of 'options_values'.
@Pawel, thanks man that works. That is a lot easier than translating back option_values :-)
@GK
Not 'easier...'
But just the way Php works..;-)
@Dhrup, Thanks for dishing me :-) But you are right I am not used to coding php, but I am a very fast and accurate learner. I made more than 10 plugins in 2 months and shared 2 of them in this community which web managers seem to like. If you help me too, I will be of good value to this community.
ohh q dissing..
hehhh
look care fully thru php net's ref man for assoc arrays
but read mentally what code u want for
the pulldown...
then u wll see the elgg pulld view @ the select @ the array and see the "secret" of that code @@@@ :-