Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9188273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:58:00+00:00 2026-06-17T19:58:00+00:00

I have a several fields like for person’s profile and for each field there

  • 0

I have a several fields like for person’s profile and for each field there are several options.

For e.g.

Age (10-15, 15-20, 20-25) 
Category (X, Y, Z)

and several other fields.

I have search page with all these fields along with their option values as check-boxes.
So I am currently printing these values using below for-each loop

{foreach from=$field.options item=options}
<input name="{$field.field_search_name}[]" type="checkbox" value="{$options.url}" />
{$options.caption}
{/foreach}

Now issue is in making all the fields which are selected before submit, I need to show as
selected from POST array.

I know that if we had static check-box name like “category[]” I could have done like below

{if in_array($options.url, $smarty.post.category)} checked {/if}

but in my case the check-box name is also dynamic and it is defined in smarty template only so I am not sure how to get work around for this.
Something like below has to be worked on , please let me know if it is possible to do this in smarty.

{if in_array($options.url, $smarty.post.$field.field_search_name)} checked {/if}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:58:01+00:00Added an answer on June 17, 2026 at 7:58 pm

    If you want to have the check-boxes checked as per the POST fields set in the request you can access them through:

    {if array_key_exists({$smarty.request, $field.field_search_name)}
        checked
    {/if}
    

    However that would depend on the input names being unique. If you’re using field names with [] to make them be an array when the form is submitted, you should check on whether the value is in the array.

    This requires a little hack to access the array:

    {assign var=tempFieldName value=`$field.field_search_name`}
    
    {if in_array({$smarty.request.$tempFieldName, $options.url)}
        checked
    {/if}
    

    To be honest though, I’d recommend generating a unique name for each input rather than putting several in the same name, and separating them using fieldName[] to push the values into the array anonymously. Doing that would reduce the issues you’re seeing with not being able to access the POSTed variable directly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several fields, each one is like this: field1 field2 field3 ... Using
In a DB table I have several fields with datetime as field type. So
I'd like to have several fields in my form being rendered as ChoiceFields which
I have a table with several account fields like this: MAIN_ACCT GROUP_ACCT SUB_ACCT I
Suppose I have a method that combines several address fields like so: def address
I have a MySQL table containing several fields; like this: id name ton dyr
I have several text fields that are dynamically populated based on user choice from
I have several 'lookup' fields in my models where I don't want nulls, but
So I have this game database, where I have several users with fields, id,
I have several datepickers tied to input fields. They are created in the usual

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.