Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Multiselect field

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Mr Kirby
Smarty n00b


Joined: 06 Aug 2018
Posts: 2

PostPosted: Mon Aug 06, 2018 8:36 am    Post subject: Multiselect field Reply with quote

Hi
I purchased a script built by someone who used smarty, it's a social network platform.

I have an issue with making the dropdown select field mulitiselect , and I didn't find a solution.

In the admin area, there's an option to add custom fields in the registration form, there are only three options : Textbox, text area, selectbox (screenshot: https://imgur.com/d7DuQZc

Once an option of that custom field is selected during the registration process, it will be seen in the profile page.

I can't seem to figure out how to make that field a multiselect one.

here's the code of the custom-field .tpl file

Code:
{if $_registration}
   {foreach $_custom_fields as $custom_field}
        <div class="form-group">
            <label>{__($custom_field['label'])}</label>
            {if $custom_field['type'] == "textbox"}
                <input name="fld_{$custom_field['field_id']}" type="text" class="form-control" placeholder="{__($custom_field['label'])}">
            {elseif $custom_field['type'] == "textarea"}
                <textarea name="fld_{$custom_field['field_id']}" class="form-control" placeholder="{__($custom_field['label'])}"></textarea>
            {elseif $custom_field['type'] == "selectbox"}
                <select name="fld_{$custom_field['field_id']}" class="form-control">
                   <option selected value="none">{__("Select")} {__($custom_field['label'])}</option>
                    {foreach $custom_field['options'] as $id => $value}
                        <option {if $custom_field['value'] == $value}selected{/if} value="{$id}">{$value}</option>
                    {/foreach}
                </select>
            {/if}
            <span class="help-block">
                {$custom_field['description']}
            </span>
        </div>
    {/foreach}
{else}
   {foreach $_custom_fields as $custom_field}
       <div class="form-group">
           <label class="col-sm-3 control-label">
               {__($custom_field['label'])}
           </label>
           <div class="col-sm-9">
               {if $custom_field['type'] == "textbox"}
                   <input type="text" name="fld_{$custom_field['field_id']}" class="form-control" value="{$custom_field['value']}">
               {elseif $custom_field['type'] == "textarea"}
                   <textarea name="fld_{$custom_field['field_id']}" class="form-control">{$custom_field['value']}</textarea>
               {elseif $custom_field['type'] == "selectbox"}
                   <select name="fld_{$custom_field['field_id']}" multiple="multiple" size="5">
                       <option {if $custom_field['value'] == ""}selected{/if} value="none">{__("Select")} {__($custom_field['label'])} </option>
                       {foreach $custom_field['options'] as $id => $value}
                           <option {if $custom_field['value'] == $value}selected{/if} value="{$id}">{$value}</option>
                       {/foreach}
                   </select>
               {/if}
               <span class="help-block">
                    {$custom_field['description']}
                </span>
           </div>
       </div>
   {/foreach}
{/if}




I added : multiple="multiple", the field change and i can select multiple options but holding ctrl , but i don't i don't know if it's working or not knowing that i only see one selected option in the profile page.

here's the code to show the selected option :

Code:
 {foreach $custom_fields['other'] as $custom_field}
                                            {if $custom_field['value']}
                                                <li>
                                                    <strong>{$custom_field['label']}</strong><br>
                                                    {$custom_field['value']}
                                                </li>
                                            {/if}
                                        {/foreach}


Do you please have an idea how to be able to select more than one option and display the selected ones correctly?

Thank you for your help
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Aug 06, 2018 10:09 am    Post subject: Reply with quote

You should brand the input with array construct ("fieldname[]") to receive multiple values in PHP, or parse the input manually.
Back to top
View user's profile Send private message
Mr Kirby
Smarty n00b


Joined: 06 Aug 2018
Posts: 2

PostPosted: Mon Aug 06, 2018 10:14 am    Post subject: Reply with quote

AnrDaemon wrote:
You should brand the input with array construct ("fieldname[]") to receive multiple values in PHP, or parse the input manually.


Thank you for your reply, how do I do that? I'm new to smarty, do you have an example please?

I also contacted the developer of the script and this is his reply :

"There is no such type of custom field in Sngine with multiple select

Sngine only support one select option in db and will render it with one option too

Maybe in future releases will take your feedback in our consideration"
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Aug 06, 2018 6:37 pm    Post subject: Reply with quote

This is not a Smarty question per se, this is a HTML/PHP question.
And I already answered it.
For details, see http://php.net/_POST
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP