php-general Digest 29 Dec 2003 10:32:57 -0000 Issue 2500

Topics (messages 173403 through 173417):

Re: Simple question
        173403 by: Andy Higgins

Re: Can't upload file greater than 11kb
        173404 by: Chris

need a little help all
        173405 by: webmaster.multiwebmastertools.com
        173406 by: Richard Davey
        173416 by: Binay

mcrypt and PHP to encrypt values to be passed to differend server
        173407 by: Mark Wouters
        173409 by: Tom Rogers

[Newbie Guide] For the benefit of new members
        173408 by: Ma Siva Kumar
        173411 by: Raditha Dissanayake
        173414 by: Ma Siva Kumar

fopen
        173410 by: Cesar Aracena
        173413 by: Gerard Samuel

multiple select option alternative to field_name[]
        173412 by: Terence
        173415 by: Binay

Read/Write ID3v1.0 and ID3v1.1 Tags. ( PHP )
        173417 by: Fatih Hood

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [EMAIL PROTECTED]


----------------------------------------------------------------------
--- Begin Message ---
Hi Lab,

I normally use code of the following format, which I think is quite neat:

//Note that you do not need curely brackets in an "if" statement is there is
only one line
if ($_SERVER['REQUEST_METHOD'] == 'POST')
    $add  = $HTTP_POST_VARS['textbox'];

if ($add == 'Hello')
    do something

//It is however recommended that you do the following in order to ensure
that a user does not try to use malicious code in their input

if ($_SERVER['REQUEST_METHOD'] == 'POST')
    $add  = clean($HTTP_POST_VARS['textbox'], 20);;

if ($add == 'Hello')
    do something

where clean() is a function defined in an include as follows:

function clean($input, $maxlength)
{
$input = substr($input, 0, $maxlength);
$input = EscapeShellCmd($input);
return ($input);
}

Hope that helps.

Regards,
Andy



"Labunski" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello, I have only one simple question..
> I'm using this method to get the values from the text box:
>
>   if(isset($_POST["Submit"]) && $_POST["Submit"]=="Submit")
>  {
>    $add = $_POST['textbox'] ;
>  }
>
> But I don't know how to write the source for this:
>
> If the value from the textbox ($add) is "Hello" then.. do something.
> I think it could be nicely done with IF, but I dont know how to write
this..
>
> Can someone help me, please?
>
> Regards,
> Lab.

--- End Message ---
--- Begin Message ---
Unfortunately, creating/editing .htaccess is not an operational requirement.

Thanks anyway.
Chris

"Raditha Dissanayake" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi,
>
> if you are lucky LimitRequestBody could go into a .htaccess file (not
> sure though  been a couple of months since i last read the manual)
>
> Chris wrote:
>
> >It has been my experience that max_file_size does terminate the upload
> >process if you include it in the form.
> >But you are right, if it gets to the upload, your stuck.
> >
> >LimitRequestBody is beyond my control as the site is hosted by a third
> >party.
> >
> >Thanks
> >Chris
> >
> >
> >"Raditha Dissanayake" <[EMAIL PROTECTED]> wrote in message
> >news:[EMAIL PROTECTED]
> >
> >
> >>Hi,
> >>
> >>It's often said in many newsgroups and articles that the max_file_size
> >>is next to useless. It's also said that once IE starts uploading it will
> >>not stop even if you keep you foot on the stop button!
> >>
> >>If i remembers the earlier messages you have said the php.ini settings
> >>are correct. If so it could well be that you might be having
> >>misconfigured proxy server or firewall in the way.
> >>
> >>Apache also has a setting (LimitRequestBody) that could effect your
> >>
> >>
> >upload.
> >
> >
> >>all the best
> >>
> >>Chris wrote:
> >>
> >>
> >>
> >>>I don't believe that the MAX_FILE_SIZE needs to be there. It will only
> >>>terminate the upload process at the client, rather than wait for the
> >>>
> >>>
> >upload
> >
> >
> >>>to complete.
> >>>
> >>>Anyway with or without MAX_FILE_SIZE the upload process is being
> >>>
> >>>
> >terminated
> >
> >
> >>>after the file is uploaded.
> >>>
> >>>When the form is submitted, the selected file is uploaded to the
server's
> >>>temp directory then copied to the maps dir.  For some reason, when the
> >>>
> >>>
> >file
> >
> >
> >>>size exceeds 11kb (very small) the process
> >>>gets aborted (with or without MAX_FILE_SIZE). I've put in diagnostic
> >>>messages and the POST script throws an error message if it can't find
the
> >>>file
> >>>in the temp directory. I've uploaded several file sizes up to the max
of
> >>>
> >>>
> >2MB
> >
> >
> >>>and it appears the file is being uploaded. I base this assumption on
the
> >>>fact the upload time is proportional to the file size. When the file
size
> >>>
> >>>
> >is
> >
> >
> >>>greater than 11kb it appears that the file is deleted from the temp
dir.
> >>>
> >>>Still no idea what is going on.
> >>>Chris
> >>>
> >>>"Larry Brown" <[EMAIL PROTECTED]> wrote in message
> >>>news:[EMAIL PROTECTED]
> >>>
> >>>
> >>>
> >>>
> >>>>The <input type="hidden" ... is more than a convenience for the
client.
> >>>>
> >>>>
> >>>>
> >>>>
> >>>It
> >>>
> >>>
> >>>
> >>>
> >>>>must be before the ...type="file"... tag and after <form.. (at least
> >>>>
> >>>>
> >with
> >
> >
> >>>>Mozilla Firebird as the client) If you have it in there and remember
it
> >>>>
> >>>>
> >is
> >
> >
> >>>>in bytes not kb and set it to a size large enough the script accepting
> >>>>
> >>>>
> >the
> >
> >
> >>>>file will show $_FILE['name'] and it will show $_FILE['tmp_name']
having
> >>>>
> >>>>
> >>>>
> >>>>
> >>>the
> >>>
> >>>
> >>>
> >>>
> >>>>temporary file.  Then you take that hidden tag out and do the same the
> >>>>$_FILE['tmp_name'] variable will be empty since it did not recieve the
> >>>>
> >>>>
> >>>>
> >>>>
> >>>file.
> >>>
> >>>
> >>>
> >>>
> >>>>So I know at least in my case that the hidden field has to be there.
> >>>>
> >>>>Larry
> >>>>
> >>>>-----Original Message-----
> >>>>From: Chris [mailto:[EMAIL PROTECTED]
> >>>>Sent: Monday, December 22, 2003 8:55 PM
> >>>>To: [EMAIL PROTECTED]
> >>>>Subject: [PHP] Can't upload file greater than 11kb
> >>>>
> >>>>
> >>>>I've got a situation where I want to upload a file to a server then
> >>>>
> >>>>
> >enter
> >
> >
> >>>>the data in that file into mysql. I have used this well documented
> >>>>
> >>>>
> >upload
> >
> >
> >>>>form
> >>>>
> >>>><form enctype="multipart/form-data" action="_URL_" method="POST">
> >>>>Send this file: <input name="userfile" type="file">
> >>>>
> >>>><input type="submit" value="Send File">
> >>>>
> >>>></form>
> >>>>
> >>>>script on many php servers. However I am on one now which is not
> >>>>
> >>>>
> >allowing
> >
> >
> >>>>
> >>>>
> >>>me
> >>>
> >>>
> >>>
> >>>
> >>>>to upload a file greater than 12kb.
> >>>>
> >>>>I know the upload_max_filesize is 2M but something else is stopping
the
> >>>>upload and I don't have a clue what it is. I know you should include
> >>>>
> >>>>
> >>>>
> >>>>
> >>><input
> >>>
> >>>
> >>>
> >>>
> >>>>type="hidden" name="MAX_FILE_SIZE" value="30000"> in the above form
but
> >>>>
> >>>>
> >>>>
> >>>>
> >>>that
> >>>
> >>>
> >>>
> >>>
> >>>>is only a convenience for the user.
> >>>>
> >>>>This particular server is running php as a cgi module.
> >>>>
> >>>>Thanks
> >>>>
> >>>>Chris
> >>>>
> >>>>--
> >>>>PHP General Mailing List (http://www.php.net/)
> >>>>To unsubscribe, visit: http://www.php.net/unsub.php
> >>>>
> >>>>
> >>>>
> >>>>
> >>>
> >>>
> >>>
> >>-- 
> >>Raditha Dissanayake.
> >>------------------------------------------------------------------------
> >>http://www.radinks.com/sftp/         | http://www.raditha.com/megaupload
> >>Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader
> >>Graphical User Inteface. Just 150 KB | with progress bar.
> >>
> >>
> >
> >
> >
>
>
> -- 
> Raditha Dissanayake.
> ------------------------------------------------------------------------
> http://www.radinks.com/sftp/         | http://www.raditha.com/megaupload
> Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader
> Graphical User Inteface. Just 150 KB | with progress bar.

--- End Message ---
--- Begin Message ---
Here is what i have i call 2 cookies in the top of my script, now i need to
call another when another script is called but it keeps givin me the error
headers already sent,
now ive seen this done in other scripts but wont work for me so please help
me is it in my php.ini or is it just not possible and imagened seeing it
somwhere else. Thanks all.

--- End Message ---
--- Begin Message ---
Hello,

Wednesday, December 17, 2003, 11:50:52 AM, you wrote:

wmc> Here is what i have i call 2 cookies in the top of my script, now i need to
wmc> call another when another script is called but it keeps givin me the error
wmc> headers already sent,
wmc> now ive seen this done in other scripts but wont work for me so please help
wmc> me is it in my php.ini or is it just not possible and imagened seeing it
wmc> somwhere else. Thanks all.

You can access the value of cookies anywhere in your script,
regardless if the headers have been sent or not. However you cannot
SET a cookie once the headers have gone for use in the same page
session. This isn't a PHP setting, it's just not possible.

-- 
Best regards,
 Richard                            mailto:[EMAIL PROTECTED]

--- End Message ---
--- Begin Message ---

----- Original Message -----
From: "Richard Davey" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, December 29, 2003 4:52 AM
Subject: Re: [PHP] need a little help all


> Hello,
>
> Wednesday, December 17, 2003, 11:50:52 AM, you wrote:
>
> wmc> Here is what i have i call 2 cookies in the top of my script, now i
need to
> wmc> call another when another script is called but it keeps givin me the
error
> wmc> headers already sent,
> wmc> now ive seen this done in other scripts but wont work for me so
please help
> wmc> me is it in my php.ini or is it just not possible and imagened seeing
it
> wmc> somwhere else. Thanks all.
>
> You can access the value of cookies anywhere in your script,
> regardless if the headers have been sent or not. However you cannot
> SET a cookie once the headers have gone for use in the same page
> session. This isn't a PHP setting, it's just not possible.
---------------------
Output buffering might be hlepful.
read the php documentation abt output buffering.
---------------------

>
> --
> Best regards,
>  Richard                            mailto:[EMAIL PROTECTED]
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--- End Message ---
--- Begin Message ---
Hello!

I'm trying to use mcrypt to encrypt some values (login and password) I have
to pass from one website to another.
I thook this code from the php.net website as an example:

<?php
    /* Open the cipher */
    $td = mcrypt_module_open ('rijndael-256', '', 'ofb', '');

    /* Create the IV and determine the keysize length */
    $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM);
    $ks = mcrypt_enc_get_key_size ($td);

    /* Create key */
    $key = substr (md5 ('very secret key'), 0, $ks);

    /* Intialize encryption */
    mcrypt_generic_init ($td, $key, $iv);

    /* Encrypt data */
    $encrypted = mcrypt_generic ($td, 'This is very important data');

    /* Terminate encryption handler */
    mcrypt_generic_deinit ($td);

    /* Initialize encryption module for decryption */
    mcrypt_generic_init ($td, $key, $iv);

    /* Decrypt encrypted string */
    $decrypted = mdecrypt_generic ($td, $encrypted);

    /* Terminate decryption handle and close module */
    mcrypt_generic_deinit ($td);
    mcrypt_module_close ($td);

    /* Show string */
    echo trim ($decrypted)."\n";
?>

I put this in the page starting from:

<?php
    $adminlogin = $row1["adminlogin"];
    $adminpw = $row1["adminpw"];
    // both are queried from a database

    $td = mcrypt_module_open ('rijndael-256', '', 'ofb', '');
    $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM);
    $ks = mcrypt_enc_get_key_size ($td);
    $key = substr (md5 ('a key fsfqz'), 0, $ks);
    mcrypt_generic_init ($td, $key, $iv);

    /* Encrypt data */
    $encryptedlogin = mcrypt_generic ($td, $adminlogin);
    $encryptedpassw = mcrypt_generic ($td, $adminpw);

    mcrypt_generic_deinit ($td);
    mcrypt_module_close ($td);
?>
<a href="destinationpage.php?login=<?php echo("$encryptedlogin");
?>&password=<?php echo("$encryptedpassw"); ?>" target="_blank">link</a>


In the destination page (destinationpage.php, on a different server) I have
this:

      $td = mcrypt_module_open ('rijndael-256', '', 'ofb', '');
      $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td),
MCRYPT_DEV_RANDOM);
      $ks = mcrypt_enc_get_key_size ($td);
      $key = substr (md5 ('a key fsfqz'), 0, $ks);
      mcrypt_generic_init ($td, $key, $iv);

      /* Decrypt encrypted string */
      $login = mdecrypt_generic ($td, $login);
      $login = trim ($login);
      $password = mdecrypt_generic ($td, $password);
      $password = trim ($password);

      mcrypt_generic_deinit ($td);
      mcrypt_module_close ($td);

  and then an echo("$login - $password<br>"); to check if the values are
correct.

But they are not!!
What am I doing wrong?? Is it because both are on a different server?
I would very much appreciate your help. Or if someone has an other good way
of encrypting values, please let me know!

Thanks!!!

Mark.

--- End Message ---
--- Begin Message ---
Hi,

Monday, December 29, 2003, 9:30:11 AM, you wrote:
MW> Hello!

MW> I'm trying to use mcrypt to encrypt some values (login and password) I have
MW> to pass from one website to another.


You will need to pass the $iv which kinda defeats the object of it, or
use a null one. Here is a class I use for this which also corrects the
string lengths as decryption will usually have a few /0 tacked on to
make it a block size:

class encrypt_class{
        var $secret;
        function encrypt_class(){
                $this->secret = 'choose your own pass phrase here';
        }
        Function encode($id){
                $eid = $iv = 0;
                $len = strlen($id);
                $id = $len.'-'.$id;
                $td = mcrypt_module_open(MCRYPT_TripleDES, "", MCRYPT_MODE_ECB, "");
                $key = substr($this->secret, 0, mcrypt_enc_get_key_size ($td));
                $iv = pack("a".mcrypt_enc_get_iv_size($td),$iv);
                mcrypt_generic_init ($td, $key, $iv);
                $eid = base64_encode(mcrypt_generic ($td, $id));
                mcrypt_generic_deinit($td);
          return $eid;
        }
        Function decode($eid){
                $id = $iv = 0;
                $td = mcrypt_module_open (MCRYPT_TripleDES, "", MCRYPT_MODE_ECB, "");
                $key = substr($this->secret, 0, mcrypt_enc_get_key_size ($td));
                $iv = pack("a".mcrypt_enc_get_iv_size($td),$iv);
                mcrypt_generic_init ($td, $key, $iv);
                $id = mdecrypt_generic ($td, base64_decode($eid));
                $len = strtok($id,'-');
                $id = substr($id,(strlen($len)+1),$len);
                mcrypt_generic_deinit($td);
                return $id;
        }
}
 //usage
 $password = 'password';
 $name = 'me';
 
 $mesage[0] = $password;
 $message[1] = $name;

 $serial = serialize($message);
 
 $enc = new encrypt_class();
 $enc_message = $enc->encode($serial);
 //send message ....?enc_message=$enc_message

 //next page
 $enc = new encrypt_class();
 $serial = $enc->decode($_GET['enc_message']);
 $message = unserialize($serial);
 print_r($message);

-- 
regards,
Tom

--- End Message ---
--- Begin Message ---
=======================================
This message is for the benefit of new subscribers 
and those new to PHP.  Please feel free to add 
more points and send to the list.
=======================================
1. If you have any queries/problems about PHP try 
http://www.php.net/manual/en first. You can 
download a copy and use it offline also. 

Please also try http://www.php.net/manual/faq.php 
to get answers to frequently answered questions 
about PHP (added by Christophe Chisogne).

2. Try http://www.google.com next. Searching for 
"php YOUR QUERY" may fetch you relevant results 
within the first 10 results, if you are lucky.

3. There is a searchable archive of the mailing 
list discussion at 
http://phparch.com/mailinglists. Many of the 
common topics are discussed repeatedly, and you 
may get answer to your query from the earlier 
discussions. 

For example: One of the repeatedly discussed 
question in the list is "Best PHP editor". 
Everyone has his/her favourite editor. 
You can get all the opinions by going through the 
list archives. If you want a chosen list try this 
link : http://phpeditors.linuxbackup.co.uk/ 
(contributed by Christophe Chisogne).

4. Not sure if PHP is working or you want find out 
what extensions are available to you?

Just put the following code into a file with a 
.php extension and access it through your 
webserver:

<?php
        phpinfo();
?> 

If PHP is installed you will see a page with a lot 
of information on it. If PHP is not installed (or 
not working correctly) your browser will try
to download the file.

(contributed by Teren and reworded by Chris W 
Parker)

5. If you are stuck with a script and do not 
understand what is wrong, instead 
of posting the whole script, try doing some 
research yourself. One useful trick is to print 
the variable/sql query using print or echo 
command and check whether you get what you 
expected. 

After diagnosing the problem, send the details of 
your efforts (following steps 1, 2 & 3) and ask 
for help.

6. PHP is a server side scripting language. 
Whatever processing PHP does takes 
place BEFORE the output reaches the client. 
Therefore, it is not possible to access the 
users'  computer related information (OS, screen 
size etc) using PHP. You need to go for 
JavaScript and ask the question in a JavaScript 
list.

On the other hand you can access the information 
that is SENT by the user's browser when a client 
requests a page from your server. You can
find details about browser, OS etc as reported by 
this request. - contributed by Wouter van Vliet 
and reworded by Chris W Parker.

7. Provide a clear descriptive subject line. Avoid 
general subjects like "Help!!", "A Question" etc.  
Especially avoid blank subjects. 

8. When you want to start a new topic, open a new 
mail composer and enter the mailing list address 
[EMAIL PROTECTED] instead of replying to 
an existing thread and replacing the subject and 
body with your message.

9. It's always a good idea to post back to the 
list once you've solved your problem. People 
usually add [SOLVED] to the subject line of their
email when posting solutions. By posting your 
solution you're helping the next person with the 
same question. [contribued by Chris W Parker]

10. Ask smart questions  
http://catb.org/~esr/faqs/smart-questions.html
[contributed by Jay Blanchard)

Hope you have a good time programming with PHP.

Best regards,

-- 
Integrated Management Tools for leather industry
----------------------------------
http://www.leatherlink.net

Ma Siva Kumar,
BSG LeatherLink (P) Ltd,
Chennai - 600106

--- End Message ---
--- Begin Message --- Hi,

This compilation of your is really excellent. Over the last few months i have noticed that many posters are cleary sending messages without having read your newby guide. IMHO whenever that happens all of us on this list should suggest that the user should read this message in the archive first before responding to his query.

best regards



Ma Siva Kumar wrote:

=======================================
This message is for the benefit of new subscribers and those new to PHP. Please feel free to add more points and send to the list.
=======================================



-- Raditha Dissanayake. ------------------------------------------------------------------------ http://www.radinks.com/sftp/ | http://www.raditha.com/megaupload Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader Graphical User Inteface. Just 150 KB | with progress bar.

--- End Message ---
--- Begin Message ---
On Monday 29 Dec 2003 10:24 am, you wrote:
> Hi,
>
> This compilation of your is really excellent.
> Over the last few months i have noticed that
> many posters are cleary sending messages
> without having read your newby guide.  IMHO
> whenever that happens all of us on this list
> should suggest that the user should read this
> message in the archive first before responding
> to his query.
>

Thanks. The idea is to send it once a week to 
catch the new subscribers with a message into 
their inbox before they commit any of the sins 
(!).  Guess, some new users slip in the gap in 
between.

Best regards,

Ma SivaKumar



-- 
Integrated Management Tools for leather industry
----------------------------------
http://www.leatherlink.net

Ma Siva Kumar,
BSG LeatherLink (P) Ltd,
Chennai - 600106

--- End Message ---
--- Begin Message ---
Hello,

I am trying to open my first text file using PHP and my PC almost freezed...
please don't laught. Here's my script:

function welcometext()
{
 $fp = fopen("../files/welcome.txt", "a+");

 while (!feof($fp, 100))
 {
  $text = fgets($fp, 100);
  echo $text;
 }

 fclose($fp);
}

What can be wrong? Thanks in advanced,

Cesar Aracena

--- End Message ---
--- Begin Message ---
On Sunday 28 December 2003 11:17 pm, Cesar Aracena wrote:
>  $fp = fopen("../files/welcome.txt", "a+");
>

Change to
$fp = fopen("../files/welcome.txt", "r");

Use "r" to read, when you use "a" it appends (or adds) to the file
Its also suggested to use the "b" option to so it would look like
$fp = fopen("../files/welcome.txt", "rb");

That is done for portability between *nix and windows.

More info is at the manual
http://us2.php.net/manual/en/function.fopen.php

--- End Message ---
--- Begin Message ---
Dear All,

The only way I know to retrieve all the values from a multiple select field
is to use
the square brackets after the field name ie. user_id[]

The problem however is that when I use a javascript function to transfer the
items
from multiple_select_list1 to multiple_select_list2, I cannot use the square
brackets
in a field name, as this obviously conflicts with something in the script.

So I am wondering if there's any other way in PHP to get the items, or do I
have
to find an alternative way in javascript? If anyone has ideas it would be
great.

Thanks
Terence



my code:

     (This works)

   echo "<select name='select1' multiple size='7'
class='inputstyle'>....</select>\n";

<input type='button' class='buttonstyle' value=' > ' onClick=\"if
(document.images) copySelected(this.form.select1,this.form.select2)\">
<input type='button' class='buttonstyle' value=' < ' onClick=\"if
(document.images) copySelected(this.form.select2,this.form.select1)\">
<input type='button' class='buttonstyle' value='>>' onClick=\"if
(document.images) copyAll(this.form.select1,this.form.select2)\">
<input type='button' class='buttonstyle' value='<<' onClick=\"if
(document.images) copyAll(this.form.select2,this.form.select1)\">

<select name='select2' multiple size='7' class='inputstyle'>....</select>

(This is the problem - notice the square brackets behind select2)

 echo "<select name='select1' multiple size='7'
class='inputstyle'>....</select>\n";

<input type='button' class='buttonstyle' value=' > ' onClick=\"if
(document.images) copySelected(this.form.select1,this.form.select2[])\">
<input type='button' class='buttonstyle' value=' < ' onClick=\"if
(document.images) copySelected(this.form.select2[],this.form.select1)\">
<input type='button' class='buttonstyle' value='>>' onClick=\"if
(document.images) copyAll(this.form.select1,this.form.select2[])\">
<input type='button' class='buttonstyle' value='<<' onClick=\"if
(document.images) copyAll(this.form.select2[],this.form.select1)\">

<select name='select2[]' multiple size='7' class='inputstyle'>....</select>


Javascript:

echo "<script language='JavaScript'><!--\n";
 echo "function deleteOption(object,index) {\n";
    echo "object.options[index] = null;\n";
 echo "}\n";

 echo "function addOption(object,text,value) {\n";
     echo "var defaultSelected = true;\n";
     echo "var selected = true;\n";
     echo "var optionName = new Option(text, value, defaultSelected,
selected)\n";
     echo "object.options[object.length] = optionName;\n";
 echo "}\n";

 echo "function copySelected(fromObject,toObject) {\n";
     echo "for (var i=0, l=fromObject.options.length;i<l;i++) {\n";
         echo "if (fromObject.options[i].selected)\n";
             echo
"addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
\n";
     echo "}\n";
     echo "for (var i=fromObject.options.length-1;i>-1;i--) {\n";
         echo "if (fromObject.options[i].selected)\n";
             echo "deleteOption(fromObject,i);\n";
     echo "}\n";
 echo "}\n";

 echo "function copyAll(fromObject,toObject) {\n";
     echo "for (var i=0, l=fromObject.options.length;i<l;i++) {\n";
         echo
"addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
\n";
     echo "}\n";
     echo "for (var i=fromObject.options.length-1;i>-1;i--) {\n";
         echo "deleteOption(fromObject,i);\n";
     echo "}\n";
 echo "}\n";
 echo "//--></script>\n";

--- End Message ---
--- Begin Message ---
Hi Terence

Assign ids to multiple select field and then use id attribute of select tag
in JavaScript to access (copy,del etc.) instead of using the name attribute.

Hope this helps.

Cheers
Binay
----- Original Message -----
From: "Terence" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, December 29, 2003 11:46 AM
Subject: [PHP] multiple select option alternative to field_name[]


> Dear All,
>
> The only way I know to retrieve all the values from a multiple select
field
> is to use
> the square brackets after the field name ie. user_id[]
>
> The problem however is that when I use a javascript function to transfer
the
> items
> from multiple_select_list1 to multiple_select_list2, I cannot use the
square
> brackets
> in a field name, as this obviously conflicts with something in the script.
>
> So I am wondering if there's any other way in PHP to get the items, or do
I
> have
> to find an alternative way in javascript? If anyone has ideas it would be
> great.
>
> Thanks
> Terence
>
>
>
> my code:
>
>      (This works)
>
>    echo "<select name='select1' multiple size='7'
> class='inputstyle'>....</select>\n";
>
> <input type='button' class='buttonstyle' value=' > ' onClick=\"if
> (document.images) copySelected(this.form.select1,this.form.select2)\">
> <input type='button' class='buttonstyle' value=' < ' onClick=\"if
> (document.images) copySelected(this.form.select2,this.form.select1)\">
> <input type='button' class='buttonstyle' value='>>' onClick=\"if
> (document.images) copyAll(this.form.select1,this.form.select2)\">
> <input type='button' class='buttonstyle' value='<<' onClick=\"if
> (document.images) copyAll(this.form.select2,this.form.select1)\">
>
> <select name='select2' multiple size='7' class='inputstyle'>....</select>
>
> (This is the problem - notice the square brackets behind select2)
>
>  echo "<select name='select1' multiple size='7'
> class='inputstyle'>....</select>\n";
>
> <input type='button' class='buttonstyle' value=' > ' onClick=\"if
> (document.images) copySelected(this.form.select1,this.form.select2[])\">
> <input type='button' class='buttonstyle' value=' < ' onClick=\"if
> (document.images) copySelected(this.form.select2[],this.form.select1)\">
> <input type='button' class='buttonstyle' value='>>' onClick=\"if
> (document.images) copyAll(this.form.select1,this.form.select2[])\">
> <input type='button' class='buttonstyle' value='<<' onClick=\"if
> (document.images) copyAll(this.form.select2[],this.form.select1)\">
>
> <select name='select2[]' multiple size='7'
class='inputstyle'>....</select>
>
>
> Javascript:
>
> echo "<script language='JavaScript'><!--\n";
>  echo "function deleteOption(object,index) {\n";
>     echo "object.options[index] = null;\n";
>  echo "}\n";
>
>  echo "function addOption(object,text,value) {\n";
>      echo "var defaultSelected = true;\n";
>      echo "var selected = true;\n";
>      echo "var optionName = new Option(text, value, defaultSelected,
> selected)\n";
>      echo "object.options[object.length] = optionName;\n";
>  echo "}\n";
>
>  echo "function copySelected(fromObject,toObject) {\n";
>      echo "for (var i=0, l=fromObject.options.length;i<l;i++) {\n";
>          echo "if (fromObject.options[i].selected)\n";
>              echo
>
"addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
> \n";
>      echo "}\n";
>      echo "for (var i=fromObject.options.length-1;i>-1;i--) {\n";
>          echo "if (fromObject.options[i].selected)\n";
>              echo "deleteOption(fromObject,i);\n";
>      echo "}\n";
>  echo "}\n";
>
>  echo "function copyAll(fromObject,toObject) {\n";
>      echo "for (var i=0, l=fromObject.options.length;i<l;i++) {\n";
>          echo
>
"addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
> \n";
>      echo "}\n";
>      echo "for (var i=fromObject.options.length-1;i>-1;i--) {\n";
>          echo "deleteOption(fromObject,i);\n";
>      echo "}\n";
>  echo "}\n";
>  echo "//--></script>\n";
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--- End Message ---
--- Begin Message ---
Hi,

This class that represents ID3v1.0 and ID3v1.1 tags. It can read, write, and
remove tags in MP3 files.

Download : http://www.phpbuilder.com/snippet/detail.php?type=snippet&id=1107

may the FORCE be with us!

may the PHP be with us!

.)

--- End Message ---

Reply via email to