post

×

Error message

Warning: apc_store(): Potential cache slam averted for key 'www.hashbangcode.com::cache_bootstrap::variables' in DrupalAPCCache->set() (line 206 of /var/www/www.hashbangcode.com/2014-03-22-2105/docroot/sites/all/modules/contrib/apc/drupal_apc_cache.inc).
post

PHP Question: Post Variables

Friday, July 29, 2011 - 18:10

Question

Take the following HTML form.

1
2
3
4
<form id="form" name="form" method="post">
<input type="text" name="number" value="0" />
<input type="submit" />
</form>

What is the output of the following PHP code after the above form has been submitted, and why?

1
2
3
4
5
if ($_POST['number'] === 0) {
        echo 'number is zero';
} else {
        echo 'number is not zero';
}
Category: 

Add A Post To Twitter Button To Your Wordpress Posts

Thursday, June 4, 2009 - 22:00

This is quite a simple thing to do and it is quite easy to add a little link to your Wordpress posts. If the user is logged into Twitter on the web (which isn't all that common with multiple Twitter apps taking over) then when they click on a link they will be taken to their Twitter profile and their status box will contain the text you have set. You won't actually be able to update a users status for them, they have the final control over that, but some users will update their status so it is worth doing.

This is all done through a URL using the status parameter, like this.

Category: 

Multi Page Forms In PHP

Tuesday, May 5, 2009 - 12:14

Multi pages forms are just as they sound, a single form spread across multiple pages. These are useful in terms of usability as it can break up an otherwise dauntingly big form into smaller chunks. It can also be useful if you want to process some of the results in order to determine what forms the user sees on later steps.

There are two ways in which it is possible to do this using PHP.

The first (and simplest) is just to cycle through the items submitted on a previous form and print them out as hidden fields. Our first page source code will look like this:

Category: 

Wordpress Post Friendly Code With JavaScript Replace

Thursday, February 12, 2009 - 12:03

I recently talked about adding code to blogs and comments to Wordpress and making sure that certain characters are encoded properly. So to simplify things I thought I would create a little set of regular expressions that takes a sample of code and convert it into a Wordress friendly format. It consists of the following function, which takes the value of a text area called tochange and runs some regular expression replace functions on it.

Category: 

Turn Off Analytics In Preview Mode With Wordpress

Tuesday, June 3, 2008 - 09:45

The preview mode in Wordpress exists to allow you to see how a post will look before you publish it to your site. This is an important feature if you have lots of readers as once your click that publish button your post will be live and your RSS feed will be pinged out to lots of different services. Previewing a post can avoid embarrassing spelling or formatting errors before the post goes live.

Category: 

Creating A URI Slug With PHP

Friday, March 28, 2008 - 12:43

The use of mod_rewrite on a site can have a powerful effect on search engine positioning, but to do it properly you will need to create a "slug" for each page. A slug is a lowercase alphanumeric version of the page title, with any spaces removed.

To get a slug you will need to use a function to turn a readable page title into a string that can be used as part of a URI.

Category: