Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange output from variable to hidden form field
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <pre><code> public function ShowUsers($userArray) { $userIdArray = $userArray[0]; $userNameArray = $userArray[1]; $users = implode(",", $userNameArray); echo $users; // username1,username2... $nrOfUsers = count($userIdArray); for ($i = 0; $i &lt; $nrOfUsers; $i++) { $users .= "&lt;label for='$userIdArray[$i]'&gt; $userNameArray[$i] &lt;input type='checkbox' name='$this-&gt;_checkBox' value='$userIdArray[$i]' /&gt;&lt;br/&gt; &lt;/label&gt;"; } $userList = "&lt;div class='userList'&gt; &lt;form id='form3' method='post' action=''&gt; &lt;fieldset&gt; &lt;p&gt;Existing users&lt;/p&gt; $users &lt;input type='hidden' value='$users' /&gt; &lt;input type='submit' id='$this-&gt;_submitRemove' name='$this-&gt;_submitRemove' Value='Ta bort' /&gt; &lt;/fieldset&gt; &lt;/form&gt; &lt;/div&gt;"; return $userList; } </code></pre> <p>The output is the following:</p> <pre><code>&lt;input type='hidden' value='username1,username2&lt;label for='47'&gt; username1 &lt;input type='checkbox' name='check[]' value='47' /&gt;&lt;br/&gt; &lt;/label&gt;&lt;label for='50'&gt; username2 &lt;input type='checkbox' name='check[]' value='50' /&gt;&lt;br/&gt; &lt;/label&gt;' /&gt; </code></pre> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload