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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:12:15+00:00 2026-06-12T12:12:15+00:00

Below is a function that outputs a form with existing users from a database,

  • 0

Below is a function that outputs a form with existing users from a database, with checkboxes and a submit button. The user choose one or several users to be removed and submits the form. What i’m working on right now is to implement a confirmation box in js (“Are you sure you want to remove…”), which shall contain the users that the user wants to remove.

By that reason I’m putting in the usernames in a hidden field that the js function will retrieve the username(s) from. The problem is that not only the usernames are put into the hidden input fields value attribute, but also several input fields as well (!?). If I hard code in for example ‘username1,username2’ in the attribute it works as it should, but not if I use the variable $users.

    public function ShowUsers($userArray) {

        $userIdArray = $userArray[0];
        $userNameArray = $userArray[1];
        $users = implode(",", $userNameArray);

        echo $users;        // username1,username2...

        $nrOfUsers = count($userIdArray);

        for ($i = 0; $i < $nrOfUsers; $i++) {
            $users .= "<label for='$userIdArray[$i]'>
                        $userNameArray[$i]
                        <input type='checkbox' name='$this->_checkBox' value='$userIdArray[$i]' /><br/>
                        </label>";
        }

        $userList = "<div class='userList'>
                    <form id='form3' method='post' action=''>
                        <fieldset>
                            <p>Existing users</p>
                            $users
                            <input type='hidden' value='$users' />
                            <input type='submit' id='$this->_submitRemove' name='$this->_submitRemove' Value='Ta bort' />
                        </fieldset>
                    </form>
                    </div>";

        return $userList;
    }

The output is the following:

<input type='hidden' value='username1,username2<label for='47'>
                        username1
                        <input type='checkbox' name='check[]' value='47' /><br/>
                        </label><label for='50'>
                        username2
                        <input type='checkbox' name='check[]' value='50' /><br/>
                        </label>' />

I just don’t get it why this happens? The content of $users (in this case ‘username1’ and ‘username2’) is there as expected, but why is the input and label tags put into the value attribute?

  • 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-12T12:12:16+00:00Added an answer on June 12, 2026 at 12:12 pm

    The problem is in your for loop. There you’re appending all that HTML to the variable $users which already is $users == username1,username2. If you do echo $users; or even var_dump($users); just after you’ve finished the for loop, you’ll see.
    What are you trying to achieve in the for loop indeed? Did you rather mean

    for ($i = 0; $i < $nrOfUsers; $i++) {
        echo "<label for='$userIdArray[$i]'>
                    $userNameArray[$i]
                    <input type='checkbox' name='$this->_checkBox' value='$userIdArray[$i]' /><br/>
              </label>";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a button that calls a javascript function named submit(). In that function
Below is my function that will take a timestamp and tell you the time
I have an example function below that reads in a date as a string
Below I have a function that animates a div ( container ) either to
I need a function that can return the difference between the below two dates
I Send Iqueryable to a function that is below void Method<T>(ref IQueryable<T> qu) {
How is this possible that the str_replace() function below returns biWeekly and not Every
I'm appending to a list then throwing that list into a function below: List<ItemBean>
somebody mentioned that the function (in this case a method) below is no good
is there a function in PHP that could parse the html data below to

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.