I'm venturing into new territory regarding drupal module development. I'm working on a module that creates a form for collecting information used to build a url. The url is for an api that returns XML (not JSON). I need to know the preferred method for using ajax to either populate a div on the existing page or redirect to a new page. About all I've come up with while searching is AHAH and JSON.
I've done such things by writing my own ajax script and straight php but never with drupal. Help with best practices would be greatly appreciated.
On Mon, 10 May 2010, Scott wrote:
I'm venturing into new territory regarding drupal module development. I'm working on a module that creates a form for collecting information used to build a url. The url is for an api that returns XML (not JSON). I need to know the preferred method for using ajax to either populate a div on the existing page or redirect to a new page. About all I've come up with while searching is AHAH and JSON.
This is just my experience - I've got no idea about "best practice".
Basically, for the page containing the form, you would need to call drupal_add_js(file.js) to pipe your AJAX javascript to the client. In the file.js you add your jquery AJAX callback function to your module menu defined 'type'=>MENU_CALLBACK function - (which is a hidden URL that never appears in the menu)
And for me, at least, my callback func had to finish with
if (!empty($_POST['js'])) { //jQuery made the call. //This will return a result to jQuery's request. drupal_json($myReturnedJSON); exit(); }
One of the issues I encountered, in Drupal 6 is that every Forms API button, thinks its a "submit" button and wants to callhome for a page refresh, rather than an asynchronous background page update.
I had to work around that with a from element like this:
$fform['apply']['Update'] = array( '#weight' => 200, // #button_type attribute ignored (=submit) bug work-around '#type' => 'markup', '#prefix' => '<input type="button" id="edit-apply-Update"' . ' value="Save new schedule" onclick="' . 'mymodule_update_schedule_js('' . $base_url . '/?q=mymodule/admin/bookings/schedule/update');" ' . '/>', '#value' => ' ', );
where mymodule_update_schedule_js() is something you defined in file.js and its argument is your target MENU_CALLBACK url. I had something like this:
function proposaldb_update_schedule_js(updateTarget) { var jsonData = JSON.stringify( stuff ); var instrument = $('#edit-filter-instrument').val(); $.ajax({ type: 'POST', url: updateTarget + "/" + $('#edit-filter-instrument').val(), dataType: 'json', data: 'js=' + jsonData, error: function( XmlHttpObj,status,errorT) { alert("error uploading new JSON schedule " + status + ": " +errorT); }, success: function( data) { alert("successfully rescheduled"); } }); }
Hope this helps Cheers Doug
Doug wrote:
One of the issues I encountered, in Drupal 6 is that every Forms API button, thinks its a "submit" button and wants to callhome for a page refresh, rather than an asynchronous background page update.
But you can have more than one button on the page each with its different submit handlers specified with '#submit'. Same for '#validate'.
On Tue, 11 May 2010, Earnie Boyd wrote:
Doug wrote:
One of the issues I encountered, in Drupal 6 is that every Forms API button, thinks its a "submit" button and wants to callhome for a page refresh, rather than an asynchronous background page update.
But you can have more than one button on the page each with its different submit handlers specified with '#submit'. Same for '#validate'.
The issue I had was this one: http://drupal.org/node/50147 Basically every button is a "submit" button which causes a page refresh - the antithesis of AJAX.
Doug wrote:
On Tue, 11 May 2010, Earnie Boyd wrote:
Doug wrote:
One of the issues I encountered, in Drupal 6 is that every Forms API button, thinks its a "submit" button and wants to callhome for a page refresh, rather than an asynchronous background page update.
But you can have more than one button on the page each with its different submit handlers specified with '#submit'. Same for '#validate'.
The issue I had was this one: http://drupal.org/node/50147 Basically every button is a "submit" button which causes a page refresh - the antithesis of AJAX.
All, I can say is that I too have noticed that a '#type' => 'button' is more of a '#type' => 'submit' than not. Too bad you're not pointing at a Drupal core issue that could perhaps use some of what is stated in the forum post that is no lost to deprecation. I have yet to get big into AJAX but do like what it can do. I'm using the ajax item list pagers that come with Views in Panels on my for-my-kids.com site. Kind of nice that I can page in the panel without refreshing the entire form.
I want to use Ubercart with multiple images per product, wherever that is necessary. Such as where certain products come as a pair or set (blouse and skirt, for example) but are added to cart or billed as a single item.
I am looking for an Amazon style solution where clicking on or hovering over one of the (smaller) secondary images swaps out the (larger) primary image and is replaced by the secondary image. Again, clicking the primary image itself opens a new window with the primary image enlarged and displayed in it.
Here is an example of what I mean:
http://www.amazon.com/eMachines-EZ1601-01-All-in-One-Desktop/dp/B002EECKVM/r...
Using Ubercart and Lightbox2 I am at the stage where primary images show up OK and enlarge when clicked, but I don't know where to begin implementing an Amazon style display solution with multiple image swap outs as I described above.
Any pointers on what to do or references relating to code snippets would be greatly appreciated.
Thanks!
You can make your image field that you already have accept multiple values so that it has more than one photo and then work with theme to determine how they should be displayed.
Another option is that if your first image acts diffrent than images after than you can add another image field to your content type and work with the display in the theme.
Hope this helps. Sent on the Sprint® Now Network from my BlackBerry®
-----Original Message----- From: "Moses Elias (2)" iom@netvision.net.il Date: Sun, 16 May 2010 00:10:20 To: support@drupal.org Subject: [support] Ubercart - Amazon Display Style Swap Out of Multiple Images Per Product
I want to use Ubercart with multiple images per product, wherever that is necessary. Such as where certain products come as a pair or set (blouse and skirt, for example) but are added to cart or billed as a single item.
I am looking for an Amazon style solution where clicking on or hovering over one of the (smaller) secondary images swaps out the (larger) primary image and is replaced by the secondary image. Again, clicking the primary image itself opens a new window with the primary image enlarged and displayed in it.
Here is an example of what I mean:
http://www.amazon.com/eMachines-EZ1601-01-All-in-One-Desktop/dp/B002EECKVM/r...
Using Ubercart and Lightbox2 I am at the stage where primary images show up OK and enlarge when clicked, but I don't know where to begin implementing an Amazon style display solution with multiple image swap outs as I described above.
Any pointers on what to do or references relating to code snippets would be greatly appreciated.
Thanks!