Posting blog messages via Android App

image

This is a test post from the WordPress app on my Samsung Galaxy Tab to see how it works.

Bookmark and Share
Tags:
Posted in Test by Chris. No Comments

jQuery – Ajax existing form

This article will attempt to show how to take an existent form in html and to ajax the form, that is to bring up the form into a jQuery UI dialog box and then to send the data back to the target URL for processing. This article assumes you have some knowledge on how jQuery works and a little bit on the jQuery UI framework. If you need to learn about this first, then head over to www.jquery.com and www.jqueryui.com.

Warning, this article only covers the basics and assumes you have a simple form without validation. Obviously depending on what you are working on or want to achieve, you will need to modify whats below. So take this article just as a basis.

So to kick off lets assume you already have a form in its own file:

form.php

Gold Silver Blue

Nothing to hectic about the file above. The form is set to POST mode and has a target action for processing of the data. I have included html elements such as radio boxes, a checkbox and a select dropdown list to show you that jQuery can collect all forms of form data.

Our target php script simply dumps the POST variables for now.

form-process.php

foreach($_POST as $key =--> $value)
{
	print("<p>{$key}: ");
	print_r($value);
	print("</p&ht;");
}

So now for the fun part. We want to write some Javascript code to dynamically load the html form and show it in a jQuery UI dialog box. Then we need to add buttons to grab the forms filled in data and to send them via ajax to our target script. For this article we will show the response, which is simply the output dump of the POST variables.

Firstly lets add a button. Simple stuff:

The our Javascript code


Explanation of the code above:

1: Starting our Javascript code. This is a basic feature of jQuery where we pass through a custom function to the jQuery core which will be executed once the page is fully loaded. Nothing fancy here.

2: Here we are dynamically added a click event to our button. This code will do everything we need to load a form via ajax, show it, collect the data, send the data to another script and then show the results.

3: We need to load the form via ajax. Since our form is sitting in its own file, we simple call an ajax get request on it. Once the html is returned we then show it in a dialog box. If you need more info on ajax methods in jQuery, head over to their website.

4: The line here simple creates a jQuery object that wraps around an html div element. We set the contents of the div to the form html that was returned from the GET ajax request.

5: Our dialog box will need some buttons. The buttons will be in an array where the key is the title of the button and the value is the click event of the button. Our first button is a Cancel button which simply closes the form. The submit buttons will be added dynamically for this tutorial.

6: If we leave the submit buttons of the form in the code, then they will appear in the dialog. The problem is that the user can still click on them which will submit our form, not via AJAX, but as normal. So what we want to do is remove the buttons from the html form and insert them into the button bar of the dialog box. We will just add them after our cancel button in step 5. So for each button in our html form, we will do steps 7 to 9 on them.

7: Find the form element in the code. With that grab the action attribute of the form. We are assuming for this tutorial that the form has the POST method. The action attribute tells the browser where to post the data when the user submits the form. We will use this target in the ajax POST request in step 9.

8: Now for the easy part. We will use a very nifty jQuery function to grab all the form data from the form and put it nicely in an array ready for sending down our ajax POST request. A problem we have in this example is that our form has two submit buttons, each with their own name. So depending on which one was used to submit the data (in a normal form, not ajax), there would be a different post variable with the name of the button that was clicked. To handle that in the ajax way, we simple push the name and value of the button onto our array returned by the jQuery function. Simple as that.

9: Now we are ready to send our data via ajax. Simple call the $.post method provided by jQuery. The first element is the target url, then the data, then the response function. Here we simple show the results in a dialog box so we can see that the data sent via ajax is the same as if we wont using ajax.

10: This line just removed the submit button from the code so the user will not click on it.

11: Show the modified form to the user in a jQuery dialog box.

And thats about it. Remember that this is only the basics as there is so much that goes into forms. Exceptionally when it comes to client side validation and confirmation before sending.

Bookmark and Share
Posted in jQuery by Chris. No Comments

Cricket World Cup 2011

2011 Cricket World Cup Logo

With just under a month to go to the 2011 Cricket World Cup, all focus will be on Bangladesh as they host the 10th World Cup in the game of cricket. 14 countries in two pools will battle it out on the cricket grounds in Asia to fight for the ultimate trophy in the game. The tounramnet kicks off on 19 February and goes through to 2 April with 49 50/50 one day international day/night games to be played at 13 stadiums in 3 countries.

The torunament is divided into 2 phases: the group stage and the knockout stage.

Firstly the fourteen participants are divided into 2 groups A and B and each team will play each other once at various cricket grounds. After all teams have played their 6 matches, the top 4 will go onto the quarter finals, with winners going on to the semi finals and then to the finals. In the group 2 points are awarded to the winning team and 0 to the losing team and if the result is a draw then just 1 point.

The groups are as follows:

Group A: Australia, Canada, Kenya, New Zealand, Pakistan, Sri Lanka, Zimbabwe

Group B: Bangladesh, England, India, Ireland, Netherlands, South Africa, West Indies.

In the history of the tournament, South Africa has only appeared 5 times and has never reached the finals, only the semis (1992, 1999, 2007) so lets hope the Proteas can make it all the way this year. A final would be great but a win would be legendary.

The preliminary South African Squad is as follows:

Proteas Logo

  • Graeme Smith (Captain)
  • Hashim Amla
  • Johan Botha
  • AB de Villiers
  • JP Duminy
  • Faf du Plessis
  • Colin Ingram
  • Jacques Kallis
  • Morne Morkel
  • Wayne Parnell
  • Robbin Peterson
  • Dale Steyn
  • Imran Tahir
  • Lonwabo Tsotsobe
  • Morne van Wyk (wicket keeper).

But no matter how the tournament ends up, I’m sure that all games are going to be a blast to watch with lots of beers to be drunk and biltong to be eaten.

Go Proteas!!!!

Bookmark and Share
Posted in Cricket Sport by Chris. No Comments

Knight and Day

Knight and Day starring June Heavens (Cameron Diaz) and Roy Miller (Tom Cruise) is a movie filled with action, adventure and a splash of comedy. June Heavens owns a garage back in Boston and whilst heading back home for her sisters wedding, her life gets tangled with a secret FBI agent who tries his best to not get her on the plane. June ends up on the flight anyways despite the efforts of Roy. While flying she get a glimpse of the life that the FBI agent has and from here on, trouble fills her life. It then becomes Roy’s campaign to not only keep himself alive and protect the one merchandise that he is carrying, but to also keep June out of harms way from the people that are after him.

This for me was a great movie with some favorable characters and I don’t think the directors could of picked a better match for the lead roles. There were some parts however that anyone will find a bit unrealistic, especially the gun fights and high speed chases on the on the highway, but thats Hollywood for you and was at least very entertaining to watch.

Bookmark and Share
Posted in Movies Review by Chris. No Comments

Microsoft Flight – Preview Images December 2010

Microsoft has released the first set of screenshots of their upcoming game from Microsoft Game Studios: Microsoft Flight.

This images were taken from their website: www.microsoft.com/games/flight/

Bookmark and Share