Redirect With Cancel Button

When working with HTML Forms, a Cancel button is sometimes handy when you want to reset a form. It deletes the user’s input and displays the same form again. This is particularly helpful to users that want to reset a form from scratch and start with a new form entry.

Here’s a simple HTML page called “form.html” that uses the “post” form method and uses an action to itself – the same page which is “form.html.” The form also contains a Cancel button which will be rendered using the input markup below. Notice the input type is set to “submit.”

Cancel Button To Reset Form

<html>
<head>
<title>Form</title>
</head>
<body>
<form method="post" action="form.html">
<label for="firstname">Firstname:</label><br/>
<input type="text" name="firstname" value="" />
<input type="submit" name="submit" value="Submit" />
<input type="submit" name="cancel" value="Cancel" />
</form>
</body>
</html>

Redirect With The Cancel Button

To use redirect with the Cancel button, we will use a simple Javascript event called “onclick=window.location” to send the user to another page called “anyfile.html.” We can also redirect the user to another domain if we want to such as “http://google.com.” Notice the input type is now changed from “submit” to “button.” This is very important. The input type needs to be set to “button,” otherwise our redirect will never work.

<input type="button" name="cancel" value="Cancel"
onclick="window.location='anyfile.html'" />

This is just a simple way to redirect users with the Cancel button. There are other ways of redirecting users such as using Javascript functions, etc., but it’s beyond the scope of this article.

Display PHP Arrays

One of the big challenges when working with any programming language is working with arrays. In this article, I will give out an example how to display arrays and how to assign variables to them. These variables can be used later on for other purposes such as storing to a database, etc.

Simple Array

In this example, we will use an array containing the following values:

$a = array('one','two','three','four');

Using Print_r

We can output the array using the print_r() function. I’ve encapsulated the output using HTML <pre> markup for readability purposes. You don’t have to use <pre>, but it just makes it easier to read especially when debugging.

echo '<pre>';
print_r($a);
// echo your closing pre tags

Output

This is the output from the code above:

Array
(
    [0] =&gt; one
    [1] =&gt; two
    [2] =&gt; three
    [3] =&gt; four
)

Using Foreach

Another way of displaying an array is using foreach. I’m using HTML <br/> break for readability purposes.

foreach($a as $b ) :
  echo $b ."&lt;br/&gt;";
endforeach;

Output

This is the output from the code above:

one
two
three
four

Variables

In addition, you can also use the following variables to display its values.

echo $a[0];     // one
echo $a[1];     // two
echo $a[2];     // three
echo $a[3];     // four

So, there you have it. A simple article explaining how to display arrays and how to assign variables to them. The fun really starts when dealing with multidimensional arrays. I will have a follow up article in the next couple days to detail multidimensional arrays.

I Changed To Netflix Streaming Only

It’s official. I changed my Netflix plan to online streaming only for just $7.99 a month plus the applicable taxes. Most likely $8 and some change. Last month, I was dinged for $17 plus for having both online streaming and DVD rentals. I realized I don’t really turn over that much DVDs in a month that’s worth the extra $7 or $8 bucks, so I made the change. I’m glad I did.

I was one of those people that wanted to sit out for a bit, and decide later on, whether to go with online streaming only, DVD only, or both. I went with online streaming only. Now that I’m made my decision, I think $7.99 and some change is much better for my pocket, I would say, especially in this economy. I’m more than curious as to how many people made the same decision I made.

I assume a large chunk of Netflix users have chosen online streaming over DVD rentals. The question is, will Netflix spin Qwikster as a separate company, or possibly sell it to another company. Clearly, the future of Netflix is in online streaming.

Say what you will about the criticisms that Netflix’ management have gotten over price changes and the splitting of its services, but I think Netflix management has made the right choice going forward.

Now, if they can only let all the DVD movies to be available online. That would make everyone happy.