Re: Passing an array from PHP to Javascript

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



dele454 wrote:
http://www.nabble.com/file/p19511848/untitled-1.gif
N.B : I had to use anchor to replace the 'anchor tag' in the code below
because nabble was disallowing it
hi,

i am not a js guru so pls permit my naiveness. I need the 'delete' button on
the highlighted graphic to delete all checked pics for delete. My view has
the checkboxes as an array so i need to pass this array to a javascript
function.

NB I already replied to this topic over in the ZendFrame work mailing list.. (where it was quite off topic really).

But for completeness here it is again.

And to the OP you should not really cross post questions to different lists as it considered bad netiquette unless you do so openly and there is a valid reason.


My Reply:

As a general bit of advice, I would never do any destructive with GET requests (e.g. manipulating the URL and redirecting via window.location).

If you need to do it fully in javascript, look at some kind of AJAX call that can do POSTs (my preference is jquery, but dojo may be preferred with ZF...)


But, really this is over engineered and you should look at a different approach.. here is my hint:

1. Just use a normal form. Have all the checkboxes and the "Delete Selected" button on the same form.
2. POST said form (do not use GET).
3. If you want to give the user a chance to backout with a javascript confirmation, define an onsubmit handler for the form. Depending on what this handler returns, the browser will either process or cancel the form submission. So you in it's most basic form: <form method="post" action="myurl" onsubmit="return confirm('Are you sure?');">

That should be better!

Oh, and just for future reference if you want to pass arrays or generic classes to javascript from php, you want to look into JSON and specifically the json_encode() function (although there may be a ZF wrapped up version - not sure!)

Col


--

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
  Mandriva Linux Contributor [http://www.mandriva.com/]
  PulseAudio Hacker [http://www.pulseaudio.org/]
  Trac Hacker [http://trac.edgewall.org/]


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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux