Ulyssesonline

the tech surfer

  • Home
  • About
  • Archives
You are here: Home / Archives for 2011

Archives for 2011

December 18, 2011

Problem With CodeIgniter Form_Radio

I was trying out CodeIgniter’s Form Helper the other day. I came across one issue with form_radio. I could not get the submitted results to display properly. I’m using radio buttons to show a priority with a range that goes from 1 to 5. I tried several suggestions from the CodeIgniter’s Forum, but none of them seem to work. This article discusses an alternative way to get form_radio to display submitted data properly.

First of all, let’s go through the basics.

The Basics

To load CodeIgniter’s Form Helper, we will add this code to our controller.

$this->load->helper(‘form’);

Once the form helper is loaded, we can now start using the built-in functions like:

echo form_open(’email/send’);

which is similar to:

<form method=”post” action=”http:/example.com/email/send” />

Form_Radio

Here’s the form_radio function:

echo form_radio(‘var’, ‘1’, TRUE);

Which is similar to:

<input type=”radio” name=”var” value=”1″ checked=”checked” />

My Code

echo form_radio(‘var’, ‘1’, set_radio(‘var’, ‘1’));
echo form_radio(‘var’, ‘2’, set_radio(‘var’, ‘2’));
echo form_radio(‘var’, ‘3’, set_radio(‘var’, ‘3’));
echo form_radio(‘var’, ‘4’, set_radio(‘var’, ‘4’));
echo form_radio(‘var’, ‘5’, set_radio(‘var’, ‘5’));

But, this code doesn’t seem to display the submitted value properly.

Suggestions

Here’s a couple of suggestions from the User Guide:

echo form_radio(‘var’, ‘1’, set_radio(‘var’, ‘1’));

Or

<input type=”radio” name=”var” value=”1″ <?php echo set_radio(‘var’, ‘1’, TRUE); ?> />

Both examples didn’t work for me. I ended up using the code below.

Solution

By the way, the variable “$row->var” is the submitted data.

<input type=”radio” name=”var” value=”1″ <?php if ($row->var==’1′) echo ‘checked=”checked”‘; ?> />1

I could use a ternary as well …

<input type=”radio” name=”var” value=”1″ <?php echo ($row->var==’1’) ? ‘checked=”checked”‘ : ”; ?> />1

Final Code

Here’s my final code.

<input type=”radio” name=”var” value=”1″ <?php if ($row->var==’1′) echo ‘checked=”checked”‘; ?> />1
<input type=”radio” name=”var” value=”1″ <?php if ($row->var==’2’) echo ‘checked=”checked”‘; ?> />2
<input type=”radio” name=”var” value=”1″ <?php if ($row->var==’3’) echo ‘checked=”checked”‘; ?> />3
<input type=”radio” name=”var” value=”1″ <?php if ($row->var==’4’) echo ‘checked=”checked”‘; ?> />4
<input type=”radio” name=”var” value=”1″ <?php if ($row->var==’5’) echo ‘checked=”checked”‘; ?> />5

The end result is, only one radio button is selected based on submmited data. There is nothing like using some old-fashioned PHP and HTML markup to display submitted data properly.

Filed Under: General

December 16, 2011

The Reasons Why I Dont Use Internet Explorer

Every now and then, I use Internet Explorer just to see how an application behaves with the dreaded browser from Microsoft. The results at times are surprising, to say the least. Using IE usually involves using Windows, which I don’t use that often. But, I have my old, trusty Windows XP, running in Virtualbox.

Inside Windows XP, I have a slightly older Internet Exporer 7. I want to upgrade to IE9, but there is a slight problem. When I headed over to Microsoft’s website, I learned that I can’t run IE9 on Windows XP. Microsoft suggests that I upgrade to Windows 7. No thanks. So, the best I can do with this Windows XP, is go with IE8. I guess I can do that, but I need another computer to test IE9.

In the meantime, I decided to blog just a little. I logged in to WordPress using IE7. Guess what? WordPress complained that I’m using an insecure browser the moment I logged in to the WordPress Dashboard. The message is right up there on top of the page, inside a bright red background. You can’t miss it.

So, I decided to write a quick blog, and then the unimaginable happened. The IE7 browser disappeared. It’s gone in a puff of smoke, right before my eyes. Where did it go? It crashed! It’s a good thing, I pressed ‘Save Draft’ just moments before its disappearance. So, now I’m using Google Chrome to complete this post.

Oh, what fun. And I still have to test that dreaded application with IE7, IE8 and IE9. I can’t wait what’s in store for me.

Filed Under: General, Linux, WordPress Tagged With: chrome, ie7, ie8, ie9, windows, xp

December 15, 2011

USB Devices Unavailable in Virtualbox

If your USB device is not available in a virtual machine within Virtualbox, the most likely culprit is that you have a permission problem. You can easily fix this by adding your username to the ‘vboxusers’ group. You can do this by launching System > Administration > User and Groups. Click Manage Groups. Find the ‘vboxusers’ group. Make sure to check the checkbox to add your username to the ‘vboxusers’ group.

If you prefer the Terminal, you can run the command:

sudo usermod -a -G vboxusers username

sudo usermod -a -G vboxusers username

You will need to restart your computer and rerun Virtualbox. Launch your virtual machine again. Your USB device should now be available for usage. Cool beans.

Filed Under: General, Linux Tagged With: group permissions, machine, usb, vboxusers, virtual, virtualbox

  • « Previous Page
  • 1
  • 2
  • 3
  • 4
  • 5
  • …
  • 60
  • Next Page »

Copyright © 2003 - 2018