Page 1 of 1

Using array elements in a form

Posted: Thu Aug 19, 2004 9:09 am
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

Posted: Thu Aug 19, 2004 9:14 am
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;

Posted: Thu Aug 19, 2004 9:35 am
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.

Posted: Thu Aug 19, 2004 9:42 am
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>
			");
			}

Posted: Thu Aug 19, 2004 9:55 am
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"); 

?>

Posted: Thu Aug 19, 2004 9:58 am
by kholloi
Thanks draco.
I can work with his

Posted: Thu Aug 19, 2004 10:00 am
by kholloi
and thanks lordsauron too