Re: [fw-general] Passing an array from PHP to Javascript
dele454 wrote: Thanks for the tips. But i CAN'T apply any of them now. The design has been approved and i need to i implement things as they are. 'Over engineered' - I dont care. As long my code works as expected. I simply want to pass my PHP array into my javascript function. - very simple code i dont see why i need to implement a library just for that. Here's a solution that doesn't require a library: http://devshed.excudo.net/scripts/javascript/source/php-array+2+javascript-array - http://devshed.excudo.net http://devshed.excudo.net -- View this message in context: http://www.nabble.com/Passing-an-array-from-PHP-to-Javascript-tp19511848p20617910.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Passing an array from PHP to Javascript
thanks for the solution, it was quiet helpful. i had the exact same problem. i just have a little problem though. how qould i the fetch the array of values back in php(zend). that has proven to be a problem? -- View this message in context: http://www.nabble.com/Passing-an-array-from-PHP-to-Javascript-tp19511848p20609153.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Passing an array from PHP to Javascript
that's what JSON is for. It's a serialized javascript array, so you simply serialize the array in javascript, pass it through to your PHP app, and there are JSON tools in PHP to instantly decode / encode the arrays. http://www.php.net/json for more info! On Fri, Nov 21, 2008 at 5:16 AM, cali_dotocm [EMAIL PROTECTED] wrote: thanks for the solution, it was quiet helpful. i had the exact same problem. i just have a little problem though. how qould i the fetch the array of values back in php(zend). that has proven to be a problem? -- View this message in context: http://www.nabble.com/Passing-an-array-from-PHP-to-Javascript-tp19511848p20609153.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Passing an array from PHP to Javascript
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Uhm, sorry, the correct answer is Zend_Json ;) ... : ___ _ ___ ___ ___ _ ___: : | \ /_\ / __| _ \ _ (_) \ : : | |) / _ \\__ \ _/ / | |) | : : |___/_/:\_\___/_| |_|_\_|___/ : ::: : Web: http://www.dasprids.de : : E-mail : [EMAIL PROTECTED] : : Jabber : [EMAIL PROTECTED] : : ICQ: 105677955 : ::: Cameron schrieb: that's what JSON is for. It's a serialized javascript array, so you simply serialize the array in javascript, pass it through to your PHP app, and there are JSON tools in PHP to instantly decode / encode the arrays. http://www.php.net/json for more info! On Fri, Nov 21, 2008 at 5:16 AM, cali_dotocm [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: thanks for the solution, it was quiet helpful. i had the exact same problem. i just have a little problem though. how qould i the fetch the array of values back in php(zend). that has proven to be a problem? -- View this message in context: http://www.nabble.com/Passing-an-array-from-PHP-to-Javascript-tp19511848p20609153.html Sent from the Zend Framework mailing list archive at Nabble.com. -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkkl9D4ACgkQ0HfT5Ws789BkLwCgkZnWUtvLmg0JfXr/4AxZLinH G2MAoK4JyeLjx3SpspMRBSfY4i9aATwV =pIWk -END PGP SIGNATURE-
Re: [fw-general] Passing an array from PHP to Javascript
heh, suck up :P On Fri, Nov 21, 2008 at 8:35 AM, Ben Scholzen 'DASPRiD' [EMAIL PROTECTED]wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Uhm, sorry, the correct answer is Zend_Json ;) ... : ___ _ ___ ___ ___ _ ___: : | \ /_\ / __| _ \ _ (_) \ : : | |) / _ \\__ \ _/ / | |) | : : |___/_/:\_\___/_| |_|_\_|___/ : ::: : Web: http://www.dasprids.de : : E-mail : [EMAIL PROTECTED] : : Jabber : [EMAIL PROTECTED] : : ICQ: 105677955 : ::: Cameron schrieb: that's what JSON is for. It's a serialized javascript array, so you simply serialize the array in javascript, pass it through to your PHP app, and there are JSON tools in PHP to instantly decode / encode the arrays. http://www.php.net/json for more info! On Fri, Nov 21, 2008 at 5:16 AM, cali_dotocm [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: thanks for the solution, it was quiet helpful. i had the exact same problem. i just have a little problem though. how qould i the fetch the array of values back in php(zend). that has proven to be a problem? -- View this message in context: http://www.nabble.com/Passing-an-array-from-PHP-to-Javascript-tp19511848p20609153.html Sent from the Zend Framework mailing list archive at Nabble.com. -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkkl9D4ACgkQ0HfT5Ws789BkLwCgkZnWUtvLmg0JfXr/4AxZLinH G2MAoK4JyeLjx3SpspMRBSfY4i9aATwV =pIWk -END PGP SIGNATURE-
Re: [fw-general] Passing an array from PHP to Javascript
Thanks for the tips. But i CAN'T apply any of them now. The design has been approved and i need to i implement things as they are. 'Over engineered' - I dont care. As long my code works as expected. I simply want to pass my PHP array into my javascript function. - very simple code i dont see why i need to implement a library just for that. Colin Guthrie-6 wrote: dele454 wrote: WHat exactly am i doing wrong??? currently my URL reads as Code: http://mainevent.com/admin/galleries/delete-pics/pid/delete[]/type/event/id/313 I think the main hassle is from posting the form getting all the checkboxes in array delete[] to the js and then to the controller that then initiates the delete by reading the parameter from the URL, iterating over the array variable etc. Pls help!! 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/] - dee -- View this message in context: http://www.nabble.com/Passing-an-array-from-PHP-to-Javascript-tp19511848p19514015.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Passing an array from PHP to Javascript
Thanks for the tips. But i CAN'T apply any of them now. The design has been approved There are several things wrong with this statement... In any event, if you want to share data between PHP and JavaScript, look at Zend_Json and JSON in general. -Matt On Tue, Sep 16, 2008 at 8:16 AM, dele454 [EMAIL PROTECTED] wrote: Thanks for the tips. But i CAN'T apply any of them now. The design has been approved and i need to i implement things as they are. 'Over engineered' - I dont care. As long my code works as expected. I simply want to pass my PHP array into my javascript function. - very simple code i dont see why i need to implement a library just for that. Colin Guthrie-6 wrote: dele454 wrote: WHat exactly am i doing wrong??? currently my URL reads as Code: http://mainevent.com/admin/galleries/delete-pics/pid/delete[]/type/event/id/313 I think the main hassle is from posting the form getting all the checkboxes in array delete[] to the js and then to the controller that then initiates the delete by reading the parameter from the URL, iterating over the array variable etc. Pls help!! 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/] - dee -- View this message in context: http://www.nabble.com/Passing-an-array-from-PHP-to-Javascript-tp19511848p19514015.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Passing an array from PHP to Javascript
hi Colin, My apologies if i came out as been naive and ungrateful. I was just under a lot of presssure here and just wanted a quick fix - my apologies sincerely. After taking a break off the work load and having my mind cleared i feel so stupid for such a reply from me. So i retract my initial comment. Thanks for taking the time to elaborate on the possible way of going about this. I will take some time to implement something - based on your suggestions and let you know the outcome. Thanks once again and my apologies Colin Guthrie-6 wrote: dele454 wrote: Thanks for the tips. But i CAN'T apply any of them now. The design has been approved and i need to i implement things as they are. 'Over engineered' - I dont care. As long my code works as expected. I simply want to pass my PHP array into my javascript function. - very simple code i dont see why i need to implement a library just for that. I wasn't suggesting you change the visual design, or do you mean a different kind of design? Do you allow the user to select some pictures and not others? If so your delete multiple button does not work as you pass the *gallery* id, not the list of selected picture ids. If you do not allow the user to select some and not others, then there is no point in producing the individual checkboxes next to the pictures, just use a Delete gallery button and be done with it. I've explained how you would implement a form that could happily accept an array of selected picture ids so there is little more help I can give you are not going to follow that route. I have explained also how to pass a PHP array into JS, but as I said before, this is almost certainly not what you want to do to achieve this kind of interface. What you actually have is a list of selected items in javascript and you want to pass that back to PHP as an array! it's precisely the other way around. This is easily possible and by naming the checkboxes as you have you are very much on the right route, but you should allow the form to be submitted naturally, do not try to force it via a window.location = 'blah' hack. If you insist on doing this then you will have to cycle through the elements of the form with the specific name and append delete[]=ID multiple times to your URL (or /delete/ID multiple times if you've wrapped up the URL parsing in a ZF route appropriately). But trust me. Use a form. Use POST, submit it normally with an onsubmit confirmation function. (you could also submit the form by calling the submit() method on the form itself, but this will prevent your interface working on browsers which have JS disabled - my recommended way would work just find without javascript, albeit sans a warning). Col 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/] - dee -- View this message in context: http://www.nabble.com/Passing-an-array-from-PHP-to-Javascript-tp19511848p19520162.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Passing an array from PHP to Javascript
I see exactly what you have been saying - again my mind was too saturated to see clearly! :( Anyway, just to reply one some of the questions you asked. The intention is that the user can either delete the picture indivually using the delete button next to each picture or select all and delete all. - but at the same time the user could deselect some pics - the intention is such that the user can delete a lot of pics at once. The reason my URL looks like am using a GET method is because the delete button is not a button but a link. the full view of my design is this just to explain a bit more: http://www.nabble.com/file/p19520252/untitled-2.gif I see what am doing wrong now - just to butress on your suggestions, i need to make that 'delete' button an actual button not a link - so the form can actually get submitted naturally via the POST method. From my controller retrieve the delete[] and iterate for deletion. I see clearly now. I think i got confused along the line while coding. Colin Guthrie-6 wrote: dele454 wrote: Thanks for the tips. But i CAN'T apply any of them now. The design has been approved and i need to i implement things as they are. 'Over engineered' - I dont care. As long my code works as expected. I simply want to pass my PHP array into my javascript function. - very simple code i dont see why i need to implement a library just for that. I wasn't suggesting you change the visual design, or do you mean a different kind of design? Do you allow the user to select some pictures and not others? If so your delete multiple button does not work as you pass the *gallery* id, not the list of selected picture ids. If you do not allow the user to select some and not others, then there is no point in producing the individual checkboxes next to the pictures, just use a Delete gallery button and be done with it. I've explained how you would implement a form that could happily accept an array of selected picture ids so there is little more help I can give you are not going to follow that route. I have explained also how to pass a PHP array into JS, but as I said before, this is almost certainly not what you want to do to achieve this kind of interface. What you actually have is a list of selected items in javascript and you want to pass that back to PHP as an array! it's precisely the other way around. This is easily possible and by naming the checkboxes as you have you are very much on the right route, but you should allow the form to be submitted naturally, do not try to force it via a window.location = 'blah' hack. If you insist on doing this then you will have to cycle through the elements of the form with the specific name and append delete[]=ID multiple times to your URL (or /delete/ID multiple times if you've wrapped up the URL parsing in a ZF route appropriately). But trust me. Use a form. Use POST, submit it normally with an onsubmit confirmation function. (you could also submit the form by calling the submit() method on the form itself, but this will prevent your interface working on browsers which have JS disabled - my recommended way would work just find without javascript, albeit sans a warning). Col 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/] - dee -- View this message in context: http://www.nabble.com/Passing-an-array-from-PHP-to-Javascript-tp19511848p19520252.html Sent from the Zend Framework mailing list archive at Nabble.com.
Re: [fw-general] Passing an array from PHP to Javascript
Hi Colin, Am not really bent of having the form process on GET. My forms use the POST method and i am changing it to GET. I simply used the URL path i posted earlier as a way of idenitfying which of the pics need to be deleted as a parameter. Colin Guthrie-6 wrote: dele454 wrote: I see exactly what you have been saying - again my mind was too saturated to see clearly! :( Anyway, just to reply one some of the questions you asked. The intention is that the user can either delete the picture indivually using the delete button next to each picture or select all and delete all. - but at the same time the user could deselect some pics - the intention is such that the user can delete a lot of pics at once. The reason my URL looks like am using a GET method is because the delete button is not a button but a link. the full view of my design is this just to explain a bit more: http://www.nabble.com/file/p19520252/untitled-2.gif I see what am doing wrong now - just to butress on your suggestions, i need to make that 'delete' button an actual button not a link - so the form can actually get submitted naturally via the POST method. From my controller retrieve the delete[] and iterate for deletion. I see clearly now. I think i got confused along the line while coding. That's OK, and don't worry about the initial reply, it happens to us all from time to time. You could still keep you delete button as a link if you like. If you have the form, you can just do something like form id=myform method=get action=/my/url/handler input type=checkbox name=delete[] value=123 / input type=checkbox name=delete[] value=456 / input type=checkbox name=delete[] value=789 / etc. /form # Delete Selected That should then post your form to the following URL: /my/url/handler?delete[]=123delete[]=456 (assuming the first two checkboxes are selected and the third is not). This value will appear in PHP's $_GET array and in the ZendFrameworks request object as an array containing two numbers, 123 and 456. This is pretty much exactly what you want I believe and shouldn't require much in the way of reengineering. All that said, it's still a good general rule not to do anything destructive with GET requests and links, the reason being that some browsers could (for example) preload links (it wouldn't happen here as there is javascript involved). If, however you use simple GET links to delete the individual images in your gallery, of the form: /my/url/handler?delete[]=123 Delete this image Then it is *very* possible a browser could try and preload that URL when you visit the page (remember that the AVG antivirus tool used to preload all the links on a page!) This is why anything destructive should only be done via a POST. Hope this helps. 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/] - dee -- View this message in context: http://www.nabble.com/Passing-an-array-from-PHP-to-Javascript-tp19511848p19525409.html Sent from the Zend Framework mailing list archive at Nabble.com.