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

  • SEARCH
  • Home
  • 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 7519147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:51:18+00:00 2026-05-30T01:51:18+00:00

I have a set of items that I can edit and delete with a

  • 0

I have a set of items that I can edit and delete with a form. Now, all itms are displayed in a list as fieldsets. The fieldsets are created with this method:

 $venues = db_query('SELECT vid, name, address, postcode, city FROM venues v WHERE v.uid = :uid', array(':uid' => $user->uid));
 if($venues->rowCount() != 0) {
   foreach($venues as $venue) {
     $page['venue_editing_form'][] = drupal_get_form('venue_editor_form', $venue->vid, $venue->name, $venue->address, $venue->postcode, $venue->city); 
   }
 }

Then the form is created with this function:

function venue_editor_form($form, &$form_state, $vid, $vname, $vadd, $vpostc, $vcity) {
$form['#prefix'] = '<div class="vedit">';
$form['#suffix'] = '</div>';
$form['edit_fieldset_'.$vname] = array(
  '#type' => 'fieldset',
  '#title' => t($vname),
  '#collapsible' => TRUE,
  '#collapsed' => TRUE,
  '#attributes' => array('class' => array('venue-edit')),
);
$form['edit_fieldset_'.$vname]['venue_name'] = array(
  '#type' => 'textfield',
  '#title' => t('Venue name:'),
  '#description' => t('Enter the venue name.'),
  '#default_value' => $vname,
  '#attributes' => array('onfocus' => 'this.value=""')
);
$form['edit_fieldset_'.$vname]['address'] = array(
  '#type' => 'textfield',
  '#title' => t('Address:'),
  '#description' => t('The address of this venue.'),
  '#default_value' => $vadd,
  '#attributes' => array('onfocus' => 'this.value=""')
);
$form['edit_fieldset_'.$vname]['postcode'] = array(
  '#type' => 'textfield',
  '#title' => t('Postcode'),
  '#description' => t('Enter the postcode for this event, so planB can position it on the map'),
  '#default_value' => $vpostc,
  '#attributes' => array('onfocus' => 'this.value=""', 'onblur' => 'getLatLong(this)')
);
$form['edit_fieldset_'.$vname]['city'] = array(
  '#type' => 'textfield',
  '#title' => t('City'),
  '#description' => t('The city this venue is in.'),
  '#default_value' => $vcity,
  '#attributes' => array('onfocus' => 'this.value=""')
);
$form['edit_fieldset_'.$vname]['edit_submit'] = array(
  '#type' => 'submit',
  '#value' => t('Submit changes'),
  '#validate' => array('venue_creation_form_validate')
);
$form['edit_fieldset_'.$vname]['delete_venue'] = array(
  '#type' => 'submit',
  '#value' => t('Delete venue'),
  '#submit' => array('venue_form_delete')
);
$form['edit_fieldset_'.$vname]['venueid'] = array(
  '#type' => 'value',
  '#value' => $vid
);
return $form;

}

And one of the submit handlers:

function venue_form_delete($form, &$form_state) {
  $deleted = db_delete('venues')
    ->condition('vid', $form['#venueid'], '=')
    ->execute();
    drupal_set_message('Venue deleted successfully.');
}

Now, the problem is that no matter which venue’s deletion button I press, Drupal always deletes the first one of the ones in the list. $form['#venueid'] is always set to the first venue in the list in the submit handler, for some reason, but if I print a message when the forms are being generated, each of the forms has a different ID, as it should be.

Has anyone had this problem before?

  • 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-30T01:51:19+00:00Added an answer on May 30, 2026 at 1:51 am

    One of my co-workers ran into this a few weeks ago. The reason you are having this problem is because you are trying to load the same form multiple times on one page with different data. It seems like this should work, however it doesn’t because all the forms end up with the same token / ID. When you submit each form the system doesnt know which one you really clicked on and can not take the appropriate action.

    There are 2 approaches to solve this problem:

    1) Rework your forms so that it is all handled with 1 form instead of multiple

    2) use hook_forms(…) to create a ‘base form’ and then generate unique forms for each venue that map to the ‘base form’. This will make sure each form gets a unique ID without having to write forms for each one.

    I dont have a drupal 7 example but here is a page that shows how to solve your problem for drupal 6 using hook_forms http://www.computerminds.co.uk/drupal-6-multiple-instances-same-form-one-page . You should be able to apply the same technique

    I havent tested this code, but this is the basic idea:

    Modify your get_form to use a unique id

    foreach($venues as $venue) {
         $page['venue_editing_form'][] = drupal_get_form('venue_editor_form_'. $venue->vid, $venue->vid, $venue->name, $venue->address, $venue->postcode, $venue->city); 
       }
    

    Impliment hook_forms

    function MODULENAME_forms($form_id) {
      $forms = array();
      if (preg_match('/venue_editor_form_/', $form_id) {
        $forms[$form_id] = array(
          'callback' => 'venue_editor_form',
        );
      }
      return $forms;
    }
    

    And then i think you have to modify your form’s submit parameter to make sure they all get routed to the same submit handler. Though it does look like you are adding different submits per button so you might not have to do anything there

    $form['#submit'] => array('venue_editing_form_submit');
    

    You might also have to do the same with the validate functions.

    That should do it.

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

Sidebar

Related Questions

I have a set of items that can be in various states. I want
I have a set of list items in unordered lists that I bind the
I have a simple program that lets you add, edit, list, search and delete
I have a set of three list items that I would like to automatically
In my edit action, I have @item = current_user.shop.items.find(params[:id]) So that the user can
Hey. I have a list of items that the user can search. The search
I hope the title makes sense. I have a set of items that I
I have a Stackpanel and want that the items automatically set their sizes regarding
I have a data set of item difficulties that correspond to items on a
I have a set of items. Each item in the set can be related

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.