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 6059683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:44:21+00:00 2026-05-23T08:44:21+00:00

I’m building a Drupal module to tie an icon to a particular page using

  • 0

I’m building a Drupal module to tie an icon to a particular page using an administration form. Each image placed within a certain directory needs to be output with a select box next to it showing all the primary link titles.

I’ve built the form using a foreach loop but when I check the output using dpm($form); in the _submit function the #value for each images page element is always equal to what ever is set for the last image.

Here’s my code:

function titleicon_admin_settings() {


  $settings = variable_get('titleicon_settings', $default);

  //build an array of primary link titles
  $primary_links_items = menu_primary_links();
  foreach ($primary_links_items as $item) {
    $title = $item['attributes']['title'];
    $href = $item['href'];
    $titles[$href] = $title;
  }

  //build array of icons
  $directory = file_directory_path() . '/icons';
  $mask = '(jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG)';
  $icons = file_scan_directory($directory, $mask);



  foreach ($icons as $icon) {
    $name = $icon->name;
    $path = base_path() . $icon->filename;
    $html = '<img src="' . $path . '" width="50" height="50" />';
    $default_value = $settings[$name]['page'];

    $form[$name] = array(
      '#type' => 'fieldset',
      '#title' => $name,
    );

    $form[$name]['path_to_icon'] = array(
      '#type' => 'value',
      '#value' => $path, 
    );

    $form[$name]['icon'] = array(
      '#type' => 'markup',
      '#value' => $html, 
    );

    $form[$name]['page'] = array(
      '#type' => 'select',
      '#title' => t('Show icon on page'),
      '#default_value' => $default_value,
      '#description' => t('Choose which page to show icon on.'),
      '#options' => $titles,
    );
  }

  $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Save'), 
    );

  return $form;
}   
  • 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-05-23T08:44:21+00:00Added an answer on May 23, 2026 at 8:44 am

    Which makes perfect sense. If your fields are declared like this:

    $form[$name]['path_to_icon'] = array(
      '#type' => 'value',
      '#value' => $path, 
    );
    

    then for each file you are updating the same variable – ‘path_to_icon’. Fieldset key “$name” does not matter here, as it is used only for grouping form fields together.

    You would need to use something more like:

    $form[$name]['path_to_icon_'.$name] = array(
      '#type' => 'value',
      '#value' => $path, 
    );
    

    then you will get multiple values after posting the form.

    However, to tell the truth, I wouldn’t use $name as element of variable name, you should rather have something like auto-incrementing $fid (file id from files table) or any other unique and SAFE identifier for each file…

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.