RE: [PHP] Passing HTML array index to JS?

2009-12-08 Thread Ford, Mike


 -Original Message-
 From: Skip Evans [mailto:s...@bigskypenguin.com]
 Sent: 07 December 2009 23:03
 To: php-general@lists.php.net
 Subject: [PHP] Passing HTML array index to JS?
 
 Hey all,
 
 I have an HTML field like this
 
 input type=text name=qty[] value=!!quantity!! size=4
 style=text-align: right; onblur=calculateBidUnit();
 
 ... and what I need to do is pass to the calculateBidUnit
 function the value of quantity, do a calculation on it and
 plug into this field.
 
 input type=text name=bid_unit_value[] value= size=4
 
 Which of course I know how to do for non-array values, but not
 sure how to get the values to do the calculation on the JS
 side if the fields are in an array.

H'mm, in my experience the only surefire foolproof way to make sure you pick 
the correct bid_unit_value[] input to match the corresponding qty[] is to 
actually supply specific array indexes (so qty[1], bid_unit_value[1]; 
qty[2], bid_unit_value[2]; etc.). There are other Javascript approaches 
that work in theory, but I've never been convinced of their robustness.

As to addressing these elements, I merely observe that in Javascript, by 
definition a.z is *identical* to a[z]. Application of this to the current 
situation is left as an exercise for the reader.

Cheers!

Mike
 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
Email: m.f...@leedsmet.ac.uk 
Tel: +44 113 812 4730





To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Passing HTML array index to JS?

2009-12-08 Thread Ashley Sheridan
On Tue, 2009-12-08 at 12:34 +, Ford, Mike wrote:

 
  -Original Message-
  From: Skip Evans [mailto:s...@bigskypenguin.com]
  Sent: 07 December 2009 23:03
  To: php-general@lists.php.net
  Subject: [PHP] Passing HTML array index to JS?
  
  Hey all,
  
  I have an HTML field like this
  
  input type=text name=qty[] value=!!quantity!! size=4
  style=text-align: right; onblur=calculateBidUnit();
  
  ... and what I need to do is pass to the calculateBidUnit
  function the value of quantity, do a calculation on it and
  plug into this field.
  
  input type=text name=bid_unit_value[] value= size=4
  
  Which of course I know how to do for non-array values, but not
  sure how to get the values to do the calculation on the JS
  side if the fields are in an array.
 
 H'mm, in my experience the only surefire foolproof way to make sure you pick 
 the correct bid_unit_value[] input to match the corresponding qty[] is to 
 actually supply specific array indexes (so qty[1], bid_unit_value[1]; 
 qty[2], bid_unit_value[2]; etc.). There are other Javascript approaches 
 that work in theory, but I've never been convinced of their robustness.
 
 As to addressing these elements, I merely observe that in Javascript, by 
 definition a.z is *identical* to a[z]. Application of this to the current 
 situation is left as an exercise for the reader.
 
 Cheers!
 
 Mike
  -- 
 Mike Ford,
 Electronic Information Developer, Libraries and Learning Innovation,  
 Leeds Metropolitan University, C507, Civic Quarter Campus, 
 Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
 Email: m.f...@leedsmet.ac.uk 
 Tel: +44 113 812 4730
 
 
 
 
 
 To view the terms under which this email is distributed, please go to 
 http://disclaimer.leedsmet.ac.uk/email.htm
 


What about using the DOM for getting to these elements and their
properties?

Thanks,
Ash
http://www.ashleysheridan.co.uk




Re: [PHP] Passing HTML array index to JS?

2009-12-08 Thread tedd

At 9:07 PM -0600 12/7/09, Philip Thompson wrote:


-snip-


Good stuff.

Thanks,

tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Passing HTML array index to JS?

2009-12-08 Thread Philip Thompson

On Dec 8, 2009, at 11:10 AM, tedd wrote:

 At 9:07 PM -0600 12/7/09, Philip Thompson wrote:
 
 -snip-
 
 Good stuff.
 
 Thanks,
 
 tedd

You say so much with so little...

~Philip


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Passing HTML array index to JS?

2009-12-07 Thread Philip Thompson
On Dec 7, 2009, at 5:02 PM, Skip Evans wrote:

 Hey all,
 
 I have an HTML field like this
 
 input type=text name=qty[] value=!!quantity!! size=4 
 style=text-align: right; onblur=calculateBidUnit();
 
 ... and what I need to do is pass to the calculateBidUnit function the value 
 of quantity, do a calculation on it and plug into this field.
 
 input type=text name=bid_unit_value[] value= size=4
 
 Which of course I know how to do for non-array values, but not sure how to 
 get the values to do the calculation on the JS side if the fields are in an 
 array.
 
 Any help, as always, is greatly appreciated,
 Skip

This question is probably more appropriate for a JS list... but I'm not mean, 
so I'll let you know. The easiest way would be to update the blur event qty 
input:

onblur=calculateBidUnit(this.value);

Now you have the value sent to that function. Another way would be to give your 
input and output an id each - let's say 'qty' and 'bid_unit_value', 
respectively. Then reference those ids in your function. This gives you the 
following:

input type=text name=qty[] value=!!quantity!! 
onblur=calculateBidUnit(); id=qty /
input type=text name=bid_unit_value[] value= id=bid_unit_value /

script type=text/javascript
function calculateBidUnit () {
var qty = document.getElementById('qty');
var buv = document.getElementById('bid_unit_value');
buv.value = qty.value;
}
/script

I'll give you a small warning. All browsers are not alike, so my recommendation 
would be to use a library that handles the cross-browser compatibility portion 
of javascript (I use Mootools). Nonetheless, the above *should* work. Learning 
the bare bones of javascript will help with the more complicated stuff and 
you'll be smarter for it! =P

Hope that helps,
~Philip
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Passing HTML array index to JS?

2009-12-07 Thread Skip Evans

Hey Philip,

But will that ID value identify the right member of each 
array? I thought about that but just assumed that it would not.


Skip

Philip Thompson wrote:

On Dec 7, 2009, at 5:02 PM, Skip Evans wrote:


Hey all,

I have an HTML field like this

input type=text name=qty[] value=!!quantity!! size=4 style=text-align: right; 
onblur=calculateBidUnit();

... and what I need to do is pass to the calculateBidUnit function the value of 
quantity, do a calculation on it and plug into this field.

input type=text name=bid_unit_value[] value= size=4

Which of course I know how to do for non-array values, but not sure how to get 
the values to do the calculation on the JS side if the fields are in an array.

Any help, as always, is greatly appreciated,
Skip


This question is probably more appropriate for a JS list... but I'm not mean, 
so I'll let you know. The easiest way would be to update the blur event qty 
input:

onblur=calculateBidUnit(this.value);

Now you have the value sent to that function. Another way would be to give your 
input and output an id each - let's say 'qty' and 'bid_unit_value', 
respectively. Then reference those ids in your function. This gives you the 
following:

input type=text name=qty[] value=!!quantity!! onblur=calculateBidUnit(); 
id=qty /
input type=text name=bid_unit_value[] value= id=bid_unit_value /

script type=text/javascript
function calculateBidUnit () {
var qty = document.getElementById('qty');
var buv = document.getElementById('bid_unit_value');
buv.value = qty.value;
}
/script

I'll give you a small warning. All browsers are not alike, so my recommendation 
would be to use a library that handles the cross-browser compatibility portion 
of javascript (I use Mootools). Nonetheless, the above *should* work. Learning 
the bare bones of javascript will help with the more complicated stuff and 
you'll be smarter for it! =P

Hope that helps,
~Philip


--

Skip Evans
PenguinSites.com, LLC
503 S Baldwin St, #1
Madison WI 53703
608.250.2720
http://penguinsites.com

Those of you who believe in
telekinesis, raise my hand.
 -- Kurt Vonnegut

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Passing HTML array index to JS?

2009-12-07 Thread Philip Thompson
On Dec 7, 2009, at 6:32 PM, Skip Evans wrote:

 Hey Philip,
 
 But will that ID value identify the right member of each array? I thought 
 about that but just assumed that it would not.
 
 Skip
 
 Philip Thompson wrote:
 On Dec 7, 2009, at 5:02 PM, Skip Evans wrote:
 Hey all,
 
 I have an HTML field like this
 
 input type=text name=qty[] value=!!quantity!! size=4 
 style=text-align: right; onblur=calculateBidUnit();
 
 ... and what I need to do is pass to the calculateBidUnit function the 
 value of quantity, do a calculation on it and plug into this field.
 
 input type=text name=bid_unit_value[] value= size=4
 
 Which of course I know how to do for non-array values, but not sure how to 
 get the values to do the calculation on the JS side if the fields are in an 
 array.
 
 Any help, as always, is greatly appreciated,
 Skip
 This question is probably more appropriate for a JS list... but I'm not 
 mean, so I'll let you know. The easiest way would be to update the blur 
 event qty input:
 onblur=calculateBidUnit(this.value);
 Now you have the value sent to that function. Another way would be to give 
 your input and output an id each - let's say 'qty' and 'bid_unit_value', 
 respectively. Then reference those ids in your function. This gives you the 
 following:
 input type=text name=qty[] value=!!quantity!! 
 onblur=calculateBidUnit(); id=qty /
 input type=text name=bid_unit_value[] value= id=bid_unit_value /
 script type=text/javascript
 function calculateBidUnit () {
var qty = document.getElementById('qty');
var buv = document.getElementById('bid_unit_value');
buv.value = qty.value;
 }
 /script
 I'll give you a small warning. All browsers are not alike, so my 
 recommendation would be to use a library that handles the cross-browser 
 compatibility portion of javascript (I use Mootools). Nonetheless, the above 
 *should* work. Learning the bare bones of javascript will help with the more 
 complicated stuff and you'll be smarter for it! =P
 Hope that helps,
 ~Philip

Each text input will only contain 1 value... and contain 1 unique id. So, if 
you have multiple input boxes with the same name (qty[]), only the $_POST 
output will contain an array of each value. See below...

input type=text name=qty[] value=1 id=qty1 onblur=calc(this.value); 
/
input type=text name=qty[] value=2 id=qty2 onblur=calc(this.value); 
/
input type=text name=qty[] value=3 id=qty3 onblur=calc(this.value); 
/

input type=text name=bid_unit_value[] value= id=buv /

script type=text/javascript
function calc (value) {
document.getElementById('buv').value = value;
}
/script

When you blur qty1, buv will receive the value 1; blur qty2, buv will be 2; and 
so on. The last input box that you blur on will determine buv's final value 
(unless you throw in some logic to handle this)...

script type=text/javascript
function calc (value) {
var buv = document.getElementById('buv');
if (buv.value == '') buv.value = value;
}
/script

So, let's say you blur on qty2 and then submit the form, your PHP script will 
have this in $_POST...

Array
(
[qty] = Array
(
[0] = 1
[1] = 2
[3] = 3
)
[bid_unit_value] = Array
(
[0] = 2
)
)

If this is not what you're wanting, you will need to modify the behavior above. 
If you're wanting the bid_unit_value to contain all the values of each blur, 
you may want to do something like this...

script type=text/javascript
function calc (value) {
var buv = document.getElementById('buv');
if (buv.value == '') buv.value = value;
else buv.value += '|'+value;
}
/script

Which may result from each blur in $_POST to be...

Array
(
[qty] = Array
(
[0] = 1
[1] = 2
[3] = 3
)
[bid_unit_value] = Array
(
[0] = 2|1|3
)
)

Or something along those lines. Then you can just explode() on that first index 
to get individual values. Maybe you can clarify your ultimate goal and we can 
assist you in what the best plan is.

Hope that helps,
~Philip
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Passing an array from PHP to Javascript

2008-09-16 Thread Yeti
I would use an unserializer.

http://code.activestate.com/recipes/414334/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Passing an array from PHP to Javascript

2008-09-16 Thread Carlos Medina

Yeti schrieb:

I would use an unserializer.

http://code.activestate.com/recipes/414334/


Hi,
why not JSON?

Regards

Carlos

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Passing an array as a hidden variable

2007-05-13 Thread WeberSites LTD
Check out the 1st code example : 

http://www.php-code-search.com/?q=how%20to%20pass%20an%20array%20from%20one

berber 

-Original Message-
From: Richard Lynch [mailto:[EMAIL PROTECTED] 
Sent: Sunday, May 13, 2007 6:58 AM
To: Todd Cary
Cc: php-general@lists.php.net
Subject: Re: [PHP] Passing an array as a hidden variable



On Fri, May 11, 2007 11:53 pm, Todd Cary wrote:
 When I use the following syntax, the 2 dimensional array loses it's 
 contents.  Can an array be passed this way?

? echo 'input type=hidden name=attend_ary_save value=' .
 $attend_ary_save .''; ?

No.

You'll just get Array back.

You can do a few things:

?php
  foreach($attend_ary_save as $k1 = $v1){
foreach($v1 as $k2 = $v2){
  ?input type=hidden name=attend_ary_save[?php echo $k1?][?php
echo $k2?] value=?php echo $v2? /?php
}
  }
?
Actually, you should wrap htmlentities() around each value being echo-ed
out.

Another option is to http://php.net/serialize the data before you send it to
HTML, and then (duh) unserialize it when it comes back.

Or, be REALLY smart, and use session_start() and just put the array in
$_SESSION and don't send data back-n-forth over HTTP, which is A) expensive,
and B) subject to user tampering, and C) inefficient.

Actually, A and C technically depend on your bandwidth versus hard drive
speed, or wherever you store you session data, so, in theory, it could be
cheaper or more efficient to use HTTP...  But I sure doubt it in any real
world hardware setup.

PS Just FYI, internally, PHP's session data is just serialized the same way
you'd do it for HTTP.

--
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

--
PHP General Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Passing an array as a hidden variable

2007-05-12 Thread Richard Lynch


On Fri, May 11, 2007 11:53 pm, Todd Cary wrote:
 When I use the following syntax, the 2 dimensional array loses
 it's contents.  Can an array be passed this way?

? echo 'input type=hidden name=attend_ary_save value=' .
 $attend_ary_save .''; ?

No.

You'll just get Array back.

You can do a few things:

?php
  foreach($attend_ary_save as $k1 = $v1){
foreach($v1 as $k2 = $v2){
  ?input type=hidden name=attend_ary_save[?php echo
$k1?][?php echo $k2?] value=?php echo $v2? /?php
}
  }
?
Actually, you should wrap htmlentities() around each value being
echo-ed out.

Another option is to http://php.net/serialize the data before you send
it to HTML, and then (duh) unserialize it when it comes back.

Or, be REALLY smart, and use session_start() and just put the array in
$_SESSION and don't send data back-n-forth over HTTP, which is A)
expensive, and B) subject to user tampering, and C) inefficient.

Actually, A and C technically depend on your bandwidth versus hard
drive speed, or wherever you store you session data, so, in theory, it
could be cheaper or more efficient to use HTTP...  But I sure doubt it
in any real world hardware setup.

PS Just FYI, internally, PHP's session data is just serialized the
same way you'd do it for HTTP.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Passing an array as a hidden variable

2007-05-11 Thread Robert Cummings
On Fri, 2007-05-11 at 21:53 -0700, Todd Cary wrote:
 When I use the following syntax, the 2 dimensional array loses 
 it's contents.  Can an array be passed this way?
 
? echo 'input type=hidden name=attend_ary_save value=' . 
 $attend_ary_save .''; ?

No! RTFM!

http://www.php.net/manual/en/language.types.type-juggling.php

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Passing the Array as Parameter to either the function or object/class???

2004-10-21 Thread Greg Donald
On Thu, 21 Oct 2004 09:57:07 -0400, Scott Fletcher [EMAIL PROTECTED] wrote:
 I wanted to know is can it be done by passing the array as a parameter
 to the function?

Yes.  By reference and by value.

 I also wanted to know is is it possible to pass around the array in the
 object-orientated feature like object/class stuffs?

Yes.  By reference and by value.

Some people have issues with theoretical posts like this one.  Showing
an honest attempt with some broken code usually gets help the
quickest.


-- 
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Passing the Array as Parameter to either the function or object/class???

2004-10-21 Thread Robby Russell
On Thu, 2004-10-21 at 09:57 -0400, Scott Fletcher wrote:
 Hi!
 
 I wanted to know is can it be done by passing the array as a parameter
 to the function?
 
 I also wanted to know is is it possible to pass around the array in the
 object-orientated feature like object/class stuffs?
 

yes and yes.

ie:

function foo($bar)
{
  print_r($bar);
}

$myarray = array(1,2,3,4);

foo($myarray);

ouputs:

Array
(
[0] = 1
[1] = 2
[2] = 3
[3] = 4
)


cheers,

Robby

-- 
/***
* Robby Russell | Owner.Developer.Geek
* PLANET ARGON  | www.planetargon.com
* Portland, OR  | [EMAIL PROTECTED]
* 503.351.4730  | blog.planetargon.com
* PHP/PostgreSQL Hosting  Development
/



signature.asc
Description: This is a digitally signed message part


Re: [PHP] passing an array via GET and a hidden form element

2003-11-02 Thread John W. Holmes
Robb Kerr wrote:
I'm trying to pass a variable from a search page to the results page via
GET. The $MANUFACTURERS variable contains an array and is obtained from the
URL. I've tried the following to no avail...
input name=manufacturer[] type=hidden multiple id=manufacturer[]
value=?php $manufacturer ?
[snip]

input name=manufacturer type=hidden multiple id=manufacturer
value=?php echo htmlentities(serialize($manufacturer)); ?
Then to get the array back on the receiving page:

$manufacturer = unserialize($_GET['manufacturer);

Or just stick the array in the session...

$_SESSION['manu'] = $manufacturer;

and on receiving page:

$manufacturer = $_SESSION['manu'];

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Passing Serialized Array via Hidden field

2003-07-21 Thread Mirek Novak
Andrei Verovski (aka MacGuru) napsal(a):
Hi,

I am need to pass serialized assotiative array via form hidden field 
(not GET or POST). In order to do it, I did the following: 
urlencode(serialize($my_array)). However, after retrieving data from 
hidden field and unserialize I've got junk.

Someone can explain me what I did wrong?

Also, do I need to do addslashes/stripslashes with serialized (or 
encoded ?) data?

Thanks in advance for any suggestion.
try to encodedata with base64_encode http://cz.php.net/base64-encode
and retrieved data base64_decode
Ha :) here http://cz.php.net/serialize - in the wiki it is already said :)
--
Mirek Novak
jabberID: [EMAIL PROTECTED]
ICQ: 119499448
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Passing Serialized Array via Hidden field

2003-07-21 Thread Jacob Vennervald Madsen
Just tried it out and you should use htmlspecialchars() instead of
urlencode(). When you put it in a hidden field the browser is
responsable for urlencoding the data.

Jacob

On Mon, 2003-07-21 at 09:24, Andrei Verovski wrote:
 Hi,
 
 I am need to pass serialized assotiative array via form hidden field 
 (not GET or POST). In order to do it, I did the following: 
 urlencode(serialize($my_array)). However, after retrieving data from 
 hidden field and unserialize I've got junk.
 
 Someone can explain me what I did wrong?
 
 Also, do I need to do addslashes/stripslashes with serialized (or 
 encoded ?) data?
 
 Thanks in advance for any suggestion.
 
 
 *
 *   Best Regards   ---   Andrei Verovski
 *
 *   Personal Home Page
 *   http://snow.prohosting.com/guru4mac
 *   Mac, Linux, DTP, Development, IT WEB Site
 *
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
-- 
Venlig hilsen / Best regards,
Jacob Vennervald
System Developer
Proventum Solutions ApS
Tuborg Boulevard 12
2900 Hellerup
Denmark
Phone:  +45 36 94 41 66
Mobile: +45 61 68 58 51



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Passing Serialized Array via Hidden field

2003-07-21 Thread John Nichel
Andrei Verovski (aka MacGuru) wrote:
Hi,

I am need to pass serialized assotiative array via form hidden field 
(not GET or POST). In order to do it, I did the following:
Uis there a third form method that I'm not aware of?

urlencode(serialize($my_array)). However, after retrieving data from 
hidden field and unserialize I've got junk.
Why are you urlencode'ing it?

Someone can explain me what I did wrong?


Did you urldecode it before you unserialized it?  Better yet, don't 
urlencode it at all.

Also, do I need to do addslashes/stripslashes with serialized (or 
encoded ?) data?
You shoudn't, but if you add on the submit, don't forget to strip on the 
retrival.

Thanks in advance for any suggestion.

*
*   Best Regards   ---   Andrei Verovski
*
*   Personal Home Page
*   http://snow.prohosting.com/guru4mac
*   Mac, Linux, DTP, Development, IT WEB Site
*


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Passing Serialized Array via Hidden field

2003-07-21 Thread Chris Shiflett
--- Andrei Verovski [EMAIL PROTECTED] wrote:
 I am need to pass serialized assotiative array via form hidden
 field (not GET or POST).

This is impossible. A hidden form field is simply a form field that is not
displayed to the user. Form actions must be GET or POST.

 In order to do it, I did the following: urlencode(serialize($my_array)).

Don't URL encode the value of the form field, since the browser will take care
of that. You should probably use POST rather than GET, because serializing an
array might yield a very long string and make the URL too large for the Web
browser and/or Web server to handle.

Hope that helps.

Chris

=
Become a better Web developer with the HTTP Developer's Handbook
http://httphandbook.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Passing Serialized Array via Hidden field

2003-07-21 Thread John Manko
Just a small point, you can have both GET and POST.

-- search.html -
form method=POST 
action='page.php?action=searchsid=09h34fnn3f0qn34f8n38fn34htq83th83qh' 
input name=search type=text
input type=submit value='Find It!'
/form

- page.php 
$sid = $_GET['sid'];
session_id($sid);
session_start();
$search = $_POST['search'];

Also, for those who don't know, you can even reference hash links

a href='page.php?action=something#myhashlink



Chris Shiflett wrote:

--- Andrei Verovski [EMAIL PROTECTED] wrote:
 

I am need to pass serialized assotiative array via form hidden
field (not GET or POST).
   

This is impossible. A hidden form field is simply a form field that is not
displayed to the user. Form actions must be GET or POST.
 

In order to do it, I did the following: urlencode(serialize($my_array)).
   

Don't URL encode the value of the form field, since the browser will take care
of that. You should probably use POST rather than GET, because serializing an
array might yield a very long string and make the URL too large for the Web
browser and/or Web server to handle.
Hope that helps.

Chris

=
Become a better Web developer with the HTTP Developer's Handbook
http://httphandbook.org/
 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Passing Serialized Array via Hidden field

2003-07-21 Thread CPT John W. Holmes
 --- Andrei Verovski [EMAIL PROTECTED] wrote:
  I am need to pass serialized assotiative array via form hidden
  field (not GET or POST).

 This is impossible. A hidden form field is simply a form field that is not
 displayed to the user. Form actions must be GET or POST.

  In order to do it, I did the following: urlencode(serialize($my_array)).

 Don't URL encode the value of the form field, since the browser will take
care
 of that. You should probably use POST rather than GET, because serializing
an
 array might yield a very long string and make the URL too large for the
Web
 browser and/or Web server to handle.

I didn't see the original thread, but judging from the title, this is how
you'd do it:

input type=hidden name=serialized_array
value=?=htmlentities(serialize($array))?

And to retrieve:

$array = unserialize(stripslashes($_POST['serialized_array']));
(assuming magic_quotes_gpc is ON)

---John Holmes...


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Passing Serialized Array via Hidden field

2003-07-21 Thread Chris Shiflett
--- John Manko [EMAIL PROTECTED] wrote:
 Just a small point, you can have both GET and POST.
 
 -- search.html -
 form method=POST 
 action='page.php?...

Notice your form method is POST, not both GET and POST. The HTTP request sent
after a user submits this form will be a POST request, even though you do have
GET variables. Try not to confuse GET/POST variables with GET/POST request
methods.

Chris

=
Become a better Web developer with the HTTP Developer's Handbook
http://httphandbook.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] passing an array in a form element

2002-08-12 Thread David T-G

Mark, et al --

...and then Mark Charette said...
% 
% I use
% 
% $data=base64_encode(serialize($array_name));
% 
% to send and
% 
% $array_name=unserialize(base64_decode($data));
% 
% to receive.

Aha!  Yes, that works nicely; thanks.  Now to go and see how they work to
see if I need the base64 stuff; that sounds safest to me.


% 
% $data can be passed via a hidden INPUT field.

Right.


Thanks, all; I'll be sure to poke at the other ideas as well.

:-D
-- 
David T-G  * It's easier to fight for one's principles
(play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie
(work) [EMAIL PROTECTED]
http://www.justpickone.org/davidtg/Shpx gur Pbzzhavpngvbaf Qrprapl Npg!




msg75153/pgp0.pgp
Description: PGP signature


Re: [PHP] passing an array in a link

2002-08-11 Thread Bas Jobsen

print a href=\/myscript.php?keylist=.str_replace( 
,+,implode(+,$keylist)).\link/a ;


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] passing an array in a link

2002-08-11 Thread David T-G

Bas, et al --

...and then Bas Jobsen said...
% 
% print a href=\/myscript.php?keylist=.str_replace( 
% ,+,implode(+,$keylist)).\link/a ;

I tried this and my link the looks like

  Click a  href=testme.php?a+b b b+chere/a to go round againbr

(that is, not only have I not taken care of the spaces but I now also
lose the fact that these are part of $keylist).

The entire little script is attached.  You can see various means of
printing the array.

I *have* found that I can construct a link like

  testme.php?keylist[]=akeylist[]=b ...

so that takes care of walking the array but now I need to protect myself
from the spaces.  I've looked at htmlentities() but it doesn't seem to
convert spaces...


Thanks again  HAND

:-D
-- 
David T-G  * It's easier to fight for one's principles
(play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie
(work) [EMAIL PROTECTED]
http://www.justpickone.org/davidtg/Shpx gur Pbzzhavpngvbaf Qrprapl Npg!



html

  head

title
  Test page
/title

  /head

  body

?php

  if ( ! $keylist )
  {
print No \$keylist; starting from scratchbr\n ;
#$keylist = array('a','b','c') ;# works (of course)
#$keylist = array('a','b%20b%20b','c') ;# works; is 'b b b' on 2nd pass
$keylist = array('a','b b b','c') ; # doesn't work; spaces are bad
print \$keylist is $keylistbr\n ;
foreach ($keylist as $k)
  { print \$k is .$k.br\n ; }
#print Click a href=\/testme.php?keylist=$keylist\here/a to go round 
againbr\n ;
print Click a href=\testme.php? ;
#foreach ( $keylist as $k ) { print keylist[]=$k ; }
print str_replace(,+,implode(+,$keylist)) ;
print \here/a to go round againbr\n ;
  }
  else
  {
print I have a \$keylist.  It is .$keylist.br\n ;
foreach ( $keylist as $k ) { print \$k is .$k.br\n ; }
  }

  print br\nbr\n ;



?

  /body

/html



msg74958/pgp0.pgp
Description: PGP signature


Re: [PHP] passing an array in a form element

2002-08-11 Thread David T-G

Hi again --

...and then David T-G said...
% 
...
% How can I pass myself an array -- and recognize it on the receiving end?

I had been spending all of my time digging into htmlentities() and the
like when, in fact, all I had to do was a simple preg_replace on each
component :-)

Now how can I pass an array as a form element?  The trick, it seems, will
be recognizing all of the keys unless I can have a form element that has
them all stretched out...


TIA  HAND

:-D
-- 
David T-G  * It's easier to fight for one's principles
(play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie
(work) [EMAIL PROTECTED]
http://www.justpickone.org/davidtg/Shpx gur Pbzzhavpngvbaf Qrprapl Npg!




msg74965/pgp0.pgp
Description: PGP signature


Re: [PHP] passing an array in a link

2002-08-11 Thread B.C. Lance

from my experience, you don't really have to worry much on the space 
issue.  is the delimiter to determine that the string terminates and a 
new argument begins next. and very often, the browser will do an auto 
conversion from space to %20 when you click on the link.

David T-G wrote:
snip
 
 so that takes care of walking the array but now I need to protect myself
 from the spaces.  I've looked at htmlentities() but it doesn't seem to
 convert spaces...
/snip


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Passing an array on

2002-05-22 Thread Jim lucas

you can use serialize() and unserialize() and make sure that you urlencode()
and urldecode() the serialized string before attaching it to your URL.  if
you don't, you might find that some chars will not be right on the other end
of the line.

Jim Lucas
- Original Message -
From: John Fishworld [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Wednesday, May 22, 2002 9:05 AM
Subject: [PHP] Passing an array on


 Whats the best way to pass on array on in a link ?

 eg
 offset is where we are (what page)
 but state is an array, with a variable size

 href=joblist.php?offset=$offsetstate=$state

 thanks



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Passing an array as an argument

2002-03-14 Thread Rasmus Lerdorf

You can't put $a[][] inside a qouted string like that.  Either use
${a[][]} or put it outside like this:

Print( option value=\.$aOptions[1][0].\.$aOptions[1][1].\n);

-Rasmus

On Thu, 14 Mar 2002, Mauricio Cuenca wrote:

 Hello,

 I've built a function that receives an array as an argument to create an
 HTML drop-down list, but when I try to print the list this is all I got:
 select name=my_list
  option value=Array[0]Array[1]
  option value=Array[0]Array[1]
 /select

 This is my code:
 ---

   Function TextList($sName, $aOptions)
   {
$nCount = Count($aOptions); //Counts the elements of the array
Print(select name=\$sName\\n);
For ($i = 1; $i = $nCount; $i++)
 {
  Print( option value=\$aOptions[1][0]\$aOptions[1][1]\n);
 }
Print(/select\n);
   }

 */ Now I build the array */
$my_array = Array( Array(0,0), Array(1,Enero), Array(2,Febrero),
 Array(3,Marzo), Array(4,Abril);

 */ And call the function */
 TextList(my_list, $my_array);

 I need to know how exaclty can I pass and receive an array as a function
 argument. Hope you can help me, TIA.
 --


 Mauricio Cuenca



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Passing an array to a C program from a php script??

2001-07-02 Thread Nicolas Guilhot

Here is a solution I've found for my problem. I use join to convert my array
into a string. Then, I use exec to run the c program, having a pipe passing
the result from an echo.  I would like to know if this solution is a good
one (in term of speed, security...), and would appreciate your comments.
Thanks.


Nicolas

Here is a short example :
// Initialize the array
$ary_test = array(15, 150, 32, 46, 69, 40, 22);
// Convert it to a string
$str_test = join(' ', $ary_test);

// Execute the c program
exec(echo \$str_test\ | test1, $ary_result, $num_return);

// Display the return value and the result of the program
echo Return value : $num_return\n;
echo Result :\n;
print_r($ary_result);


-Message d'origine-
De : Nicolas Guilhot [mailto:[EMAIL PROTECTED]]
Envoye : lundi 25 juin 2001 12:59
A : [EMAIL PROTECTED]
Objet : [PHP] Passing an array to a C program from a php script??


Hi all,

I have a big array (nearly 1000 lines) that I would like to pass to a C
program. I don't want to create a temporary file to pass my array (If
possible ?!?), and I don't think the command line will fit my needs.

Is there a way to execute a program with a php string as the standard
input. Something like shell redirection 'c_program  input.file' but with
input.file being a php variable and not a real file ?? Any other solution
??

Hope I am clear enough !

Any help would be appreciated.


Nicolas

--



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Passing an array to a C program from a php script??

2001-06-28 Thread Richard Lynch

 I have a big array (nearly 1000 lines) that I would like to pass to a C
 program. I don't want to create a temporary file to pass my array (If
 possible ?!?), and I don't think the command line will fit my needs.

 Is there a way to execute a program with a php string as the standard
 input. Something like shell redirection 'c_program  input.file' but with
 input.file being a php variable and not a real file ?? Any other solution
 ??

2 choices:

#1 (for the real hacker geek)
Compile your C program *into* PHP as a function, using the PEAR stuff.
You may need to use PHP's http://php.net/serialize function to turn your
array into a giant string and write a C routine to unserialize it, or, by
the time you get done converting your program to PEAR, it will just accept
your PHP array as an argument.

#2 (pretty slick, though...)
Run your C program using http://php.net/psockopen and use
http://php.net/fputs to spew your data at it one line at a time.

--
WARNING [EMAIL PROTECTED] address is an endangered species -- Use
[EMAIL PROTECTED]
Wanna help me out?  Like Music?  Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Passing an array to a C program from a php script??

2001-06-26 Thread Jason Lustig

Why not make a separate .txt file which is read by the PHP script to make
its variable with file(), and have the C file read it with ifstream to make
up its variable?

--Jason


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Passing an array to a C program from a php script??

2001-06-26 Thread Jason Murray

 I have a big array (nearly 1000 lines) that I would like to pass to a C
 program. I don't want to create a temporary file to pass my array (If
 possible ?!?), and I don't think the command line will fit my needs.
 
 Is there a way to execute a program with a php string as the standard
 input. Something like shell redirection 'c_program  input.file' but with
 input.file being a php variable and not a real file ?? Any other solution
 ??

If your PHP script outputs to stdout, then you could run:

  c_program  myscript.php

Your PHP script will need to output the array as if it were outputting
to the screen or web page (ie, echo/print), and your C program will need
to know what format it's coming in as.

Jason

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Passing an array to a C program from a php script??

2001-06-26 Thread mailing_list

 Hi all,
 
 I have a big array (nearly 1000 lines) that I would like to pass to a C
 program. I don't want to create a temporary file to pass my array (If
 possible ?!?), and I don't think the command line will fit my needs.
 
 Is there a way to execute a program with a php string as the standard
 input. Something like shell redirection 'c_program  input.file' but with
 input.file being a php variable and not a real file ?? Any other solution
 ??
 
 Hope I am clear enough !

what you can do is serialize the array and then parse it with you c-program
(it is not very difficult, to get the syntax ;-) ):
popen($fh,|my_c_program);
pwrite($fh,$serialized_array);
pclose($ph);

(hope that was what you were asking)
michi

-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net

--
GMX Tipp:

Machen Sie Ihr Hobby zu Geld bei unserem Partner 11!
http://profiseller.de/info/index.php3?ac=OM.PS.PS003K00596T0409a


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Passing an array as an argument.

2001-02-07 Thread Christian Reiniger

On Tuesday 06 February 2001 18:18, April wrote:

 How do you pass an array as an argument to a function?

Just as any other variable. Read on...

 function process_members($asker_rank, $email) {

 global $database_mysql;
 mysql_select_db($database_mysql);

 while (list ($key, $val) = each ($email)) {
echo "$key = $valbr";
 }

 }

 #  Doing the same thing with the function here returns this
 error, though.  
 // Warning: Variable passed to each() is not an array or object in
 lib.inc on line 447
  process_members($asker_rank, $total_members, $email);

Look at the definition of process_members() again. The function takes two 
values. The first is called $asker_rank and the second $email.
Now you pass *three* values to it. #1, $asker_rank, is fine. But #2, 
$total_members, is passed in place of $email, so every time the function 
body accedded its "$email" parameter, it gets the value of $total_members 
- which is not an array.
The third parameter is ignored.

-- 
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)

"Software is like sex: the best is for free" -- Linus Torvalds

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Passing an array as an argument.

2001-02-06 Thread Web Admin

Hi April,
I suggest you code your array into one string (it depends to the size)
then decode it at the other end using your own code. It's the easiest
trick to pass the array, compress it into one variable, then extract it at 
the other end.
Any other ideas? ;-)
Ahmad
  - Original Message - 
  From: April 
  To: PHP General 
  Sent: Tuesday, February 06, 2001 8:48 PM
  Subject: [PHP] Passing an array as an argument.


  How do you pass an array as an argument to a function?

  My code (or at least the important parts):


  function process_members($asker_rank, $email) {

  global $database_mysql;
  mysql_select_db($database_mysql);

  while (list ($key, $val) = each ($email)) {
 echo "$key = $valbr";
  }

  }


  #  This will display fine.   #
  while (list ($key, $val) = each ($email)) {
  echo "$key = $valbr";
  }


  #  Doing the same thing with the function here returns this error,
  though.  
  // Warning: Variable passed to each() is not an array or object in lib.inc
  on line 447
   process_members($asker_rank, $total_members, $email);


  -- 
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail: [EMAIL PROTECTED]





RE: [PHP] Passing an array as an argument.

2001-02-06 Thread Ryan Gaul

try:

function process_members($asker_rank, $total_members, $email=array()) {

  global $database_mysql;
  mysql_select_db($database_mysql);

  while (list ($key, $val) = each ($email)) {
 echo "$key = $valbr";
  }

}


process_members($asker_rank, $total_members, $email);

Your original function declaration only has two variables passed to it. You
are passing three variables when you call the function.

What's happening is this:

function process_members($asker_rank, $email) {

  global $database_mysql;
  mysql_select_db($database_mysql);

  while (list ($key, $val) = each ($email)) {
 echo "$key = $valbr";
  }

}

process_members($asker_rank, $total_members, $email);

step one:
php sets $asker_rank (in function declaration) equal to $asker_rank
step two:
php sets $email (in function declaration) equal to $total_members
step three:
php ignores $email array passed to process_members()
step four:
php passes $email to each(). $email is set to the value 
of $total_members, which is not an array, and chokes.

Using :

function process_members($asker_rank, $total_members, $email=array())
{
...
}

allows you to have a default value for $email. So you can either pass it or
not. 

-Original Message-
From: April [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 06, 2001 12:18 PM
To: PHP General
Subject: [PHP] Passing an array as an argument.


How do you pass an array as an argument to a function?

My code (or at least the important parts):


function process_members($asker_rank, $email) {

global $database_mysql;
mysql_select_db($database_mysql);

while (list ($key, $val) = each ($email)) {
   echo "$key = $valbr";
}

}


#  This will display fine.   #
while (list ($key, $val) = each ($email)) {
echo "$key = $valbr";
}


#  Doing the same thing with the function here returns this error,
though.  
// Warning: Variable passed to each() is not an array or object in lib.inc
on line 447
 process_members($asker_rank, $total_members, $email);


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]