I'm a web developer who works with HTML, PHP, CSS, ExpressionEngine, Javascript, jQuery, MySQL, SEO and UI/UX design. Always looking to learn new web related stuff, and a bit of a PC gamer. You can also find me on Twitter and LinkedIn.

Posts Tagged: code

Text

Today I came across the eval()’d code error in core.functions.php in ExpressionEngine.

It occurred when I was posting the result of a form to the same (PHP enabled) page, which would update the page content depending on what the user had selected.

The problem was that I was attempting to use the $_POST variable to highlight the selected <option> in a <select>. Since the $_POST variable has not been set when the page first loaded (i.e. no variables had yet been posted by the form), the error sprang up.

In order to remove the error, we can use the following code at the top of the page (where the name of the <select> is “fld_select”):

$fld_select = $_POST ? $_POST["fld_select"] : "";

This will set the $fld_select variable, which we can use in place of $_POST[“fld_select”], and avoid the error by checking to see if a post operation has been performed and setting the variable value accordingly.

Text

Validate your code.

Why?

Well, the W3C can tell you why you should validate your code, and they do a much better job of telling you what you need to know than I would. But I will list the basic reasons if you can’t be bothered to click the link:

  • Validation used as a debugging tool
  • Future-proof quality checking
  • Helps teach good practices
  • Gives a sign of professionalism

How?

There’s a great little Firefox add-on called HTML Tidy. In conjunction with viewing the source of a page, you can easily track down invalid code to set it back on the straight and narrow.

You can also use the online W3c HTML Validation Service and the online W3c CSS Validation Service if you develop using other browsers.

Text

Indent your code.

Quite simple reasoning to this one, it makes it easier to read. I mean, what would you rather look at when coding? This:

<html>

  <head>

    <title>This is our home page</title>

  </head>

  <body>

    <h1>Hello World!</h1>

    <p>Here's a list of random stuff:</p>

    <ul>

      <li>Alligator</li>

      <li>Radiator</li>

      <li>Flibbetygibbet</li>

    </ul>

  </body>

</html>

Or this:

<html><head><title>This is our home page</title></head><body><h1>
Hello World!</h1><p>Here's a list of random stuff:</p>
<ul><li>Alligator</li><li>Radiator</li><li>Flibbetygibbet</li>
</ul></body></html>

Text

Just a quick one.

I’ve recently had the need to use a submit button in a web form, with no CSS styling and without using an image (the client wanted it to look like a standard form button), which had to have the value text of the button on 2 sperate lines.

Using the <br /> tag didn’t work, and neither did the use of ‘/n’. So after a bit of digging I found an ascii code which worked: &#10;

Here’s an example of the code in use:

<input type="submit" value="Submit&#10;Query" />