Many of our clients use RSForm to dynamically generate forms on their Joomla websites. A client who was developing a form (using RSForm) very early in the morning today called us and asked us that he has a presentation this morning and he urgently needs to make a value in a dropdown box in his custom RS Form to be selected by default. In his situation, he needed the state field to be automatically set to CA (California).
We explained to him that all he had to do was to add [c] next to CA in his dropdown field value. For example, here’s what his state form field should be in RSForm’s interface:
Our client was amazed when we explained how it’s done – he thought it was a more complicated process. “Is this magic?” – he said. We told him that it was no magic – and that the file rsform.php located under the /administrator/components/com_rsform/helpers/ directory was handling this. The aforementioned file had this code:
if ((strpos($item, '[c]') !== false && empty($value)) || (isset($value[$data['NAME']]) && in_array($val, $value[$data['NAME']]))) $additional .= 'selected="selected"';
The above code simply checks if [c] exists in the value of the list item, and if it does, then it’ll add the word “selected” by default to the <option> tag. Note that the second part in the condition above (isset…) is responsible for automatically selecting the item that the user has already selected when he submitted the form. This is useful when the user submits an erroneous form and so instead of having to re-fill all the information he already filled in – RSForm will automatically fill them based on what he already filled previously.
Note that there is another interesting trick in RSForm, which is adding [d] to the value of the list item. When you add [d] to a list item then you automatically disable it (e.g. you won’t be able to select it anymore). Try it!
PS: We’re amazed why the people who created RSForm did not make the process of automatically selecting an item in the dropdown box less technical. Although it’s very easy, we find it a bit technical especially for those who have very basic Joomla and HTML knowledge.
If you need help with your RSForm component, then feel free to contact us! We’re always there and our prices are always affordable. We also know Joomla’s ins and outs and there’s nothing that we just can’t do on this CMS! Try us!
Nope, [d] has no effect whatsoever.
Hi,
Which version of RSForm are you running?