Option with unlimited entries

Cyb3r

Well-known member
I have followed this tutorial and it's working fine but I don't know how to add more fields to that option dynamically, here's my template:

HTML:
<xen:controlunit label="{$preparedOption.title}">
<ul class="FieldChoices">
    <xen:foreach loop="$preparedOption.option_value" key="$choice" value="$badge">
        <xen:if is="{$badge}">
            <li>
                <input type="text" name="{$fieldPrefix}[{$preparedOption.option_id}][$choice][id]" value="{$badge.id}" class="textCtrl" placeholder="Badge Unique Identifier" size="15" />
                <input type="text" name="{$fieldPrefix}[{$preparedOption.option_id}][$choice][title]" value="{$badge.title}" class="textCtrl" placeholder="Badge Title" size="15" />
                <input type="text" name="{$fieldPrefix}[{$preparedOption.option_id}][$choice][img]" value="{$badge.img}" class="textCtrl" placeholder="Icon Path" size="15" />
                <input type="text" name="{$fieldPrefix}[{$preparedOption.option_id}][$choice][user]" value="{$badge.user}" class="textCtrl" placeholder="UserId" size="15" />
                <input type="text" name="{$fieldPrefix}[{$preparedOption.option_id}][$choice][group]" value="{$badge.group}" class="textCtrl" placeholder="Or GroupId" size="15" />
            </li>
            <xen:set var="$cur_key">{$choice}</xen:set>
        </xen:if>
    </xen:foreach>
    <li>
        <input type="text" name="{$fieldPrefix}[{$preparedOption.option_id}][{xen:calc '{$cur_key} + 1'}][id]" value="{$badge.id}" class="textCtrl" placeholder="Badge Unique Identifier" size="15" />
        <input type="text" name="{$fieldPrefix}[{$preparedOption.option_id}][{xen:calc '{$cur_key} + 1'}][title]" value="{$badge.title}" class="textCtrl" placeholder="Badge Title" size="15" />
        <input type="text" name="{$fieldPrefix}[{$preparedOption.option_id}][{xen:calc '{$cur_key} + 1'}][img]" value="{$badge.img}" class="textCtrl" placeholder="Icon Path" size="15" />
        <input type="text" name="{$fieldPrefix}[{$preparedOption.option_id}][{xen:calc '{$cur_key} + 1'}][user]" value="{$badge.user}" class="textCtrl" placeholder="UserId" size="15" />
        <input type="text" name="{$fieldPrefix}[{$preparedOption.option_id}][{xen:calc '{$cur_key} + 1'}][group]" value="{$badge.group}" class="textCtrl" placeholder="Or GroupId" size="15" />
    </li>
</ul>
<input type="button" value="{xen:phrase add_additional_choice}" class="button smallButton FieldAdder" data-source="ul.FieldChoices li" />

<p class="explain">{xen:raw $preparedOption.explain}</p>
{xen:raw $editLink}
</xen:controlunit>

<script>
$(document).ready(function() {
    $('#{$preparedOption.title}Adder').click(function() {
        $('#{$preparedOption.title}Container').children().last().children().each(function() {
            $(this).attr('name',$(this).attr('name').replace( /(\d+)/, function(){return arguments[1]*1+1}));
        });
    });
});
</script>

And this is the option array:

Code:
Edit Format: Named Template
Format Parameters: my_template
Data Type: Array
Default Value: a:5:{s:2:"id";s:5:"none";s:5:"title";s:5:"none";s:3:"img";s:5:"none";s:4:"user";s:5:"none";s:5:"group";s:5:"none";}
Array Sub-Options:
id
title
img
user
group

When clicking save I get this big error:

Code:
Illegal string offset 'id' in C:\xampp\htdocs\rg\library\XenForo\Template\Abstract.php(265) : eval()'d code, line 31:
30:     <li>
31:         <input type="text" name="' . htmlspecialchars($fieldPrefix, ENT_QUOTES, 'UTF-8') . '[' . htmlspecialchars($preparedOption['option_id'], ENT_QUOTES, 'UTF-8') . '][' . ($cur_key + 1) . '][id]" value="' . htmlspecialchars($badge['id'], ENT_QUOTES, 'UTF-8') . '" class="textCtrl" placeholder="Badge Unique Identifier" size="15" />
32:         <input type="text" name="' . htmlspecialchars($fieldPrefix, ENT_QUOTES, 'UTF-8') . '[' . htmlspecialchars($preparedOption['option_id'], ENT_QUOTES, 'UTF-8') . '][' . ($cur_key + 1) . '][title]" value="' . htmlspecialchars($badge['title'], ENT_QUOTES, 'UTF-8') . '" class="textCtrl" placeholder="Badge Title" size="15" />
Illegal string offset 'title' in C:\xampp\htdocs\rg\library\XenForo\Template\Abstract.php(265) : eval()'d code, line 32:
31:         <input type="text" name="' . htmlspecialchars($fieldPrefix, ENT_QUOTES, 'UTF-8') . '[' . htmlspecialchars($preparedOption['option_id'], ENT_QUOTES, 'UTF-8') . '][' . ($cur_key + 1) . '][id]" value="' . htmlspecialchars($badge['id'], ENT_QUOTES, 'UTF-8') . '" class="textCtrl" placeholder="Badge Unique Identifier" size="15" />
32:         <input type="text" name="' . htmlspecialchars($fieldPrefix, ENT_QUOTES, 'UTF-8') . '[' . htmlspecialchars($preparedOption['option_id'], ENT_QUOTES, 'UTF-8') . '][' . ($cur_key + 1) . '][title]" value="' . htmlspecialchars($badge['title'], ENT_QUOTES, 'UTF-8') . '" class="textCtrl" placeholder="Badge Title" size="15" />
33:         <input type="text" name="' . htmlspecialchars($fieldPrefix, ENT_QUOTES, 'UTF-8') . '[' . htmlspecialchars($preparedOption['option_id'], ENT_QUOTES, 'UTF-8') . '][' . ($cur_key + 1) . '][img]" value="' . htmlspecialchars($badge['img'], ENT_QUOTES, 'UTF-8') . '" class="textCtrl" placeholder="Icon Path" size="15" />
Illegal string offset 'img' in C:\xampp\htdocs\rg\library\XenForo\Template\Abstract.php(265) : eval()'d code, line 33:
32:         <input type="text" name="' . htmlspecialchars($fieldPrefix, ENT_QUOTES, 'UTF-8') . '[' . htmlspecialchars($preparedOption['option_id'], ENT_QUOTES, 'UTF-8') . '][' . ($cur_key + 1) . '][title]" value="' . htmlspecialchars($badge['title'], ENT_QUOTES, 'UTF-8') . '" class="textCtrl" placeholder="Badge Title" size="15" />
33:         <input type="text" name="' . htmlspecialchars($fieldPrefix, ENT_QUOTES, 'UTF-8') . '[' . htmlspecialchars($preparedOption['option_id'], ENT_QUOTES, 'UTF-8') . '][' . ($cur_key + 1) . '][img]" value="' . htmlspecialchars($badge['img'], ENT_QUOTES, 'UTF-8') . '" class="textCtrl" placeholder="Icon Path" size="15" />
34:         <input type="text" name="' . htmlspecialchars($fieldPrefix, ENT_QUOTES, 'UTF-8') . '[' . htmlspecialchars($preparedOption['option_id'], ENT_QUOTES, 'UTF-8') . '][' . ($cur_key + 1) . '][user]" value="' . htmlspecialchars($badge['user'], ENT_QUOTES, 'UTF-8') . '" class="textCtrl" placeholder="UserId" size="15" />
Illegal string offset 'user' in C:\xampp\htdocs\rg\library\XenForo\Template\Abstract.php(265) : eval()'d code, line 34:
33:         <input type="text" name="' . htmlspecialchars($fieldPrefix, ENT_QUOTES, 'UTF-8') . '[' . htmlspecialchars($preparedOption['option_id'], ENT_QUOTES, 'UTF-8') . '][' . ($cur_key + 1) . '][img]" value="' . htmlspecialchars($badge['img'], ENT_QUOTES, 'UTF-8') . '" class="textCtrl" placeholder="Icon Path" size="15" />
34:         <input type="text" name="' . htmlspecialchars($fieldPrefix, ENT_QUOTES, 'UTF-8') . '[' . htmlspecialchars($preparedOption['option_id'], ENT_QUOTES, 'UTF-8') . '][' . ($cur_key + 1) . '][user]" value="' . htmlspecialchars($badge['user'], ENT_QUOTES, 'UTF-8') . '" class="textCtrl" placeholder="UserId" size="15" />
35:         <input type="text" name="' . htmlspecialchars($fieldPrefix, ENT_QUOTES, 'UTF-8') . '[' . htmlspecialchars($preparedOption['option_id'], ENT_QUOTES, 'UTF-8') . '][' . ($cur_key + 1) . '][group]" value="' . htmlspecialchars($badge['group'], ENT_QUOTES, 'UTF-8') . '" class="textCtrl" placeholder="Or GroupId" size="15" />
Illegal string offset 'group' in C:\xampp\htdocs\rg\library\XenForo\Template\Abstract.php(265) : eval()'d code, line 35:
34:         <input type="text" name="' . htmlspecialchars($fieldPrefix, ENT_QUOTES, 'UTF-8') . '[' . htmlspecialchars($preparedOption['option_id'], ENT_QUOTES, 'UTF-8') . '][' . ($cur_key + 1) . '][user]" value="' . htmlspecialchars($badge['user'], ENT_QUOTES, 'UTF-8') . '" class="textCtrl" placeholder="UserId" size="15" />
35:         <input type="text" name="' . htmlspecialchars($fieldPrefix, ENT_QUOTES, 'UTF-8') . '[' . htmlspecialchars($preparedOption['option_id'], ENT_QUOTES, 'UTF-8') . '][' . ($cur_key + 1) . '][group]" value="' . htmlspecialchars($badge['group'], ENT_QUOTES, 'UTF-8') . '" class="textCtrl" placeholder="Or GroupId" size="15" />
36:     </li>


Though the fields shows and everything but when I add text to them and save I get this error:

Code:
The following sub-option(s) are unknown: 1.

Any ideas?

Thanks in advance. :)
 
"The following sub-option(s) are unknown: 1."

Ok, I think I figured this out, and I'll share my working example!

Apparently the "1" in the error that is unknown is actually the index (1-based) of the array of values you're trying to save. What this means in English, is that you're trying to tell the system that each of those values will be the "Array Sub-Options" or child values of the main array. The problem is that you're saving an Array with another Array in it, not an Array with child-values!!

This is the crux of the whole matter: just put * in the Array Sub-Option field!

Here's a link to the example, which I believe I've fixed:
https://xenforo.com/community/threads/format-parameters-in-xenforo-options.103488/#post-1009969


For Googlers:
Xenforo Admin error: The following sub-option(s) are unknown
Array Sub-Options
 
Last edited:
Ok, I think I figured this out, and I'll share my working example!

Apparently the "1" in the error that is unknown is actually the index (1-based) of the array of values you're trying to save. What this means in English, is that you're trying to tell the system that each of those values will be the "Array Sub-Options" or child values of the main array. The problem is that you're saving an Array with another Array in it, not an Array with child-values!!

This is the crux of the whole matter: just put * in the Array Sub-Option field!

Here's a link to the example, which I believe I've fixed:
https://xenforo.com/community/threads/format-parameters-in-xenforo-options.103488/#post-1009969


For Googlers:
Xenforo Admin error: The following sub-option(s) are unknown
Array Sub-Options

Yes my first message was all working good except I was using option name that already been used that's why it throws an error.
 
Yes my first message was all working good except I was using option name that already been used that's why it throws an error.

Definitely why it threw the first error, and I just came across this thread, or I'd have pointed that out ("ID" is probably reserved across the whole system - as most people use that as a primary key for database tables).

What I meant was the second error "The following sub-option(s) are unknown: 1."
 
Back
Top Bottom