Using array elements in a form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kholloi
Forum Newbie
Posts: 19
Joined: Tue Mar 30, 2004 1:08 am

Using array elements in a form

Post by kholloi »

Hi,

I am trying to create a form which a sysadmin can use to change users passwords.

I have used BASH scripting to create a file with a list of all valid, non system users called /tmp/finluserlist.

So next I create an array containing all the users as ellements and count the number of elements in the array like this:

Code: Select all

<?php
include('header.php');

$users= file("/tmp/finlusrlist");

$number_of_users = count($users)
Now here is where I get stuck. I need the ellements of the array to be presented in a dropdown box in an html form, but How do I get the correct number of options to the form? And can I call the ellemants directly from the html like this?


Code: Select all

?>
<form action="chnagepasswd.php" method=post>
<br>
<br>
<br>
<table border=0>
 <tr bgcolor="orange">
  <td width=250>Select Username</td>
  <td width=150>Enter new password</td>
  <td width=150>Confirm new password</td>
 </tr>
 <tr>
 <td width=250><select name="user">
 <td width=250><option vallue="$users&#1111;0]">
 
  <td>

This is all very new to me so please don't flame.

Thanks
User avatar
Lord Sauron
Forum Commoner
Posts: 85
Joined: Tue Apr 20, 2004 5:53 am
Location: Tilburg, NL

Post by Lord Sauron »

Code: Select all

&lt;?php

print("&lt;SELECT class="selectBox" name="title&#1111;]" SIZE="3" MULTIPLE&gt;\n");

    print("&lt;OPTION value="$title" SELECTED&gt;No title&lt;/OPTION&gt;\n");
    print("&lt;OPTION value="$title" SELECTED&gt;Mr&lt;/OPTION&gt;\n");
    print("&lt;OPTION value="$title" SELECTED&gt;Dr&lt;/OPTION&gt;\n");
    print("&lt;OPTION value="$title" SELECTED&gt;Prof&lt;/OPTION&gt;\n");

print("&lt;/SELECT&gt;\n");

?&gt;
kholloi
Forum Newbie
Posts: 19
Joined: Tue Mar 30, 2004 1:08 am

Post by kholloi »

OK but this still doesnt solve the issue of how many options to present. If there are 5 users on the system, I need 5 options and if there are 100, need 100 options.
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Post by Draco_03 »

I'm just gonna give an example with links (sorry don't have time to get more specific)
but it basically loops...
Look at the for function

Code: Select all

for ($i=0; $i<$count; $i++){
			echo("
                        <tr>
			<td><a href="xxxxx">$whatever</a></td>
			<td><a href="xxxxx">$whatever</a></td>
			</tr>
			");
			}
User avatar
Lord Sauron
Forum Commoner
Posts: 85
Joined: Tue Apr 20, 2004 5:53 am
Location: Tilburg, NL

Post by Lord Sauron »

Code: Select all

<?php

print("<SELECT class="selectBox" name="title[]" SIZE="3" MULTIPLE>\n"); 

    for ($i = 0; $i < count($users); $i++) {

        print("<OPTION value="$title" SELECTED>".$user[$i]."</OPTION>\n");

    }

print("</SELECT>\n"); 

?>
kholloi
Forum Newbie
Posts: 19
Joined: Tue Mar 30, 2004 1:08 am

Post by kholloi »

Thanks draco.
I can work with his
kholloi
Forum Newbie
Posts: 19
Joined: Tue Mar 30, 2004 1:08 am

Post by kholloi »

and thanks lordsauron too
Post Reply