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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:16:38+00:00 2026-05-13T17:16:38+00:00

Sorry i could not find a proper title to this question. I have generated

  • 0

Sorry i could not find a proper title to this question.
I have generated the following using a for loop and I have concatenated the names of the submits buttons using the pattern below:
submit_edit_category_1
submit_edit_category_2
submit_edit_category_3

echo "<input type='submit' value = 'Edit' name='submit_edit_category_" . 
$obj_categories_admin->categories[$i]['category_id'] . "'/>";

I want to loop through these values so that I can the button action whichis edit_category and the category id which is 1,2 or 3. I want to so something like:

if(isset($_POST) == 'edit_category'))
{
    //code here
}

Someone suggested me to do it this way:

name="submit[which_action][which_category]"  
a1 = $_POST['submit']; 
$which_action = reset(array_keys($a1)); 
$which_category = reset(array_keys($a1[$which_action])); 

This does not seem to work..Can anyone give me a different way to do it?
Thanks!

  • 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-13T17:16:39+00:00Added an answer on May 13, 2026 at 5:16 pm

    here what I’d do:

    for the actual form, I’d use array keys to communicate action and relevant id info.

    $cat_id =  $obj_categories_admin->categories[$i]['category_id'];
    
    echo "<input type='submit' value = 'Edit' name='submit[edit_category][" . $cat_id . "]'/>";
    

    then when posted, I can do:

    <?php
    
    list($action, $action_params) = each($_POST['submit']);
    list($cat_id, $button_label) = each($action_params);
    
    print_r($_POST['submit']); // prints array('edit_category' => array('1' => 'Edit'))
    echo($action); //prints "edit_category"
    print_r($action_params); //prints array('1' => 'Edit')
    echo($cat_id); //prints "1"
    echo($button_label); //prints "Edit"
    

    edit: for more info on each(), go here: https://www.php.net/each . I’ve personally always felt that ‘s lack of differentation between the button label and the it’s value to be frustrating. Using an array key to stuff info into the button has always been my favorite hack.

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

Sidebar

Related Questions

Sorry for the slightly rubbish title. I could not think how to describe this
Sorry I couldn't find the best heading for this question. Following is my requirement.
sorry if dumb but could not find an answer. #include <iostream> using namespace std;
I'm sorry I could not think of a better title. The problem is the
Sorry for this not being a real question, but Sometime back i remember seeing
Sorry for the second newbie question, I'm a developer not a sysadmin so this
Sorry for the basic question - I'm a .NET developer and don't have much
Sorry the title isn't more help. I have a database of media-file URLs that
Sorry if you feel like this has been asked but I have read the
Sorry, if this is a duplicate. Please point me to the appropriate question if

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.