Thursday, December 19, 2013

Form buttons, where should they go?

I am writing this post, because again today while "topping up" our account with Instra, I accidentially "reset" the form instead of submitting it - after entering credit card info and top up amount. Why? Because the reset button was on the right and I instinctively clicked it.

Humans are creatures of habit and we expect things to be in certain places for common activities like using an online form.  IMHO, a confirmation or submit button should be the right aligned button of two in a form. Don't mess with this, it works well, leave it alone please.

Why they felt the need for a reset button on such a small form is another matter.

Now, I wonder who else is experimenting with this?

Tuesday, October 8, 2013

Want to hide file extensions like .php on your website?

One of (yes, there are a few ways to do this) is to use a mod rewrite.  If you host on Linux, this should work for you.  No index on site, so you can't browse files in folders and MultiViews helps with any calls in code that need extension etc.

This should be your .htaccess file in the root:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Options -Indexes
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
# To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

This will make: http://www.mywebsite.com/mypage.php  appear as: http://www.mywebsite.com/mypage

Enjoy!

Thursday, May 16, 2013

Date codes in PHP

OK... so you are coding a dynamic date field in PHP, well these codes will come in handy when working out how to show say 01 Jan '13... or Mon 01 January 2013 for example.

d = "01" to "31"
j = "1" to "31" (no leading zero)
l = "Monday" through "Sunday"
D = "Mon" through "Sun"
F = "January" through "December"
M = "Jan" through "Dec"
Y = "2013"
y = "13"

To view the full date functions, click here.


Enjoy!

Wednesday, April 10, 2013

Word Press Types plugin "Missing argument" error fix

If you have used the Types plugin in your Word Press site, you may come across this error:

"Warning: Missing argument 2 for types_render_field(), called in xxx.php on line xx and defined in..."

This is because the types_render_field now needs a second parameter which should be an array.
The parameters for field types:http://wp-types.com/documentation/functions/

The simple fix is:

Change this: "...types_render_field("xxx");"

To this: "...types_render_field("xxx", array('raw' => 'true'));"

Where "xxx" is your field name.

Happy coding!

Friday, March 29, 2013

Dev on your Mac? How to edit host file for testing!

OK so, you are working on your Mac and want to test a website in your browser... but the domain is not yet delegated - so you only have IP address for your dev server or new web hosting.

What you need to do is edit your host file, so that your browser checks this first before the domain DNS.

  1. Open a terminal window. (Applications/Utilities/Terminal)
  2. Type this line in:



    sudo nano /private/etc/hosts

  3. You will be requested to type your password in.
  4. The terminal window will then show any current host settings. Now add the line you want. Use arrows keys to position flashing cursor where you want.



    EG: 127.0.0.1  mydomain.com.au
  5. Once done, hit Control+O to save. Then press Enter.
  6. Now exit Terminal - Control+X.

You can also download a "Hosts" application that will install and be available from System Preferences. However this will not work for all OSX versions. Terminal is a better way to go.

For more advanced users, you can use "sudo vim".

To flsuh DNS in OSX 10.5 + use "dscacheutil -flushcache" - for OSX 10.4 and below, use "lookupd -flushcache".

NOTE: Had a few questions on this, if you add domain without "www" - you need to check in browser without the www as well.

Friday, March 8, 2013

How to remove file extension via .htaccess

If you want to "tidy up" you site, this is a nifty little tip.
BUT - it should really be done for new sites, else you will have to add 301 redirects.


Further, if you don't know what htaccess is, you probably shouldn't be doing anything like this.

EG for PHP

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

The .htaccess file needs to go in the same directory as the file as it works from the top down. If you have the .htaccess in a certain directory, it will affect any other sub files/folders within it.

To add / at the end

Replace the last line of code:
RewriteRule ^(.*)$ $1.php

With these lines:
RewriteRule ^([^/]+)/$ $1.php
# Forces a trailing slash to be added
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

NOTE: You should use absolute paths, rather than a relative ones for images, CSS etc.
Also, avoid creating an edge case from using folder names the same as file names within it... else you will need to add an exception.

Thursday, February 28, 2013

Design Assets: you can never have enough arrows!

So you are working on an interface design and you need an arrow style for the gallery slider buttons... well this site is just what you need, Shapes4Free - in particular this page with 850 arrow shapes!

Knock yourself out!


Thursday, February 7, 2013

Word Press White Screen of Death... Fixed!

Word Press... I have mixed emotions about Word Press. It's free, so it's hard to get upset with Word Press, and there about a gazillion plugins. However, the admin side can be a bit complicated for clients - and for developers, Word Press cans sometimes cause you great pain, like when you get the dreaded "W-SOD" (White Screen Of Death).

Well, this is how I fixed the problem on one site recently. I'm telling you this to save you the day I wasted on the problem.

BEFORE YOU STUFF AROUND WITH UPGRADING WORD PRESS, SWITCHING THEMES OR DISABLING PLUGINS - DO THIS:

If you, like me had not recently made a code change, it's highly likely to be hosting related. Now, you may not be able to get the hosting company to agree with you at first, you need proof.
  1. Check server logs, review errors and warnings.
    You should be able to get to these from Control Panel.
    Here you will see indication of the error below.
  2. Turn on error checking in your config file.
    Edit wp-config.php and change "false" to "true"
    define('WP_DEBUG', false);
  3. Now try to edit the post that shows a white screen, what do you see?
    If you see something like:
    Fatal error: Out of memory (allocated 26476544) (tried to allocate 122880 bytes)
    Then you need to:
  4. Send error to your hosting company and ask them to increase PHP memory allocation
  5. Then edit your config file again... and increase the size limit. (I made mine max of 512).
    define('WP_MEMORY_LIMIT', '16M');
  6. MAKE SURE THEY REBOOT SERVER!
Now, this fixed my issue - but it took me a day to get there, because first up I was sure it was a plugin issue after reading heaps of forum posts. I disabled plugin and it seemed to mostly work again - but as I was using Types I could not check Posts because they were not showing. With the error - I could not even check Custom Types settings. I also switched themes back and forth, changed permalinks, upgraded Word Press..... but turned out to be a simple hosting issue. DEBUG is your friend in a white out!

While you have the log files and debug turned on, check warnings and fix some of the small issues that may be kicking around too like deprecated features - will post about a few of these too.

I hope you can be lucky with a fix this simple too!

Friday, February 1, 2013

How do Google "Site Links" work?

As most of us do, we search for things in Google... some results show expanding related links from a site referenced. These are called "Site Links".

So as a business owner or web developer, you may wonder, how can you set this and control it?

Well, there is good news and bad news... The bad news is that it's automated by Google. "We only show sitelinks for results when we think they'll be useful to the user." "G" does suggest if your site structure is good, you will see these site links when relevant.

The good news is that you can remove (demote) links you don't want to show.

Google does say they are working on this tool - so maybe in future there will be more you can do with Site Links.  Read more about it here: Google Site Links.