cforms II required ‘Single line of text’ validation regex

December 21st, 2011 by cfree No comments »

I recently decided to tackle a problem that had been bothering me in regards to the cforms II WordPress plugin, by Delicious Days. cforms is a hefty plugin that makes web form creation, administration, and tracking fairly easy. It has some annoyances, but for the most part, it does it’s job well. I was using WordPress v3.2.1 with cforms v12.2.

I was assigned a to-do asking me to find out why a form was only validating the email and captcha fields, when there were 3 other fields (‘First Name,’ ‘Last Name,’ and ‘Phone’) designated as required in the form’s settings. Upon further investigation, I found that the problem only occurs when the single line fields had the ‘auto-clear’ box checked, otherwise it validated against all fields. The ‘auto-clear’ checkbox will display a default value, like ‘Name,’ in the field until onfocus, then it removes the value so the user can enter something. If the user doesn’t, the default value will reappear onblur.

To fix this, I had to use the regex option for the single line of text. This regex will be compared to the entered value when the form is submitted. If there’s a match, the form validation will fail and an error will be displayed.

I hopped over to the HiFi Regex Tester, a handy regex sandbox, and starting playing around. I came up with: ^(?!First Name$).*$

‘First Name’ is replaceable, as I checked it against ‘Last Name’ and ‘Phone’ with success.

Here’s why it works:

  • ^ and $ will check the entire string.
  • (?!First Name$) This is the negative lookahead syntax that begin matching at the end of the string using a string of ‘First Name.’ Negative lookahead matches the search string where a not-matching pattern begins.
  • .* will match any single preceeding character 0 or more times.

Basically, cforms will use the regex to test and see if ‘First Name’ was entered into the single form field. If it was, it will not validate.

This has solved a lot of headaches in my daily work. If you know of any simpler or better ways to accomplish this validation, please comment.

Pagination of posts per page in a specific category using a template

February 24th, 2011 by cfree No comments »

Clients have been asking for custom amount of posts per page in certain categories. To do this, I have to create a new category template in the theme. For the ‘testimonials’ category, I created a file in my theme directory named category-testimonials.php. The following code is meat of this page’s content:

<?php
 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

 query_posts( array_merge( $wp_query->query, array(
   'paged'    => $paged,
   'cat' => 5,
   'posts_per_page' => 10
 ) ) );
 ?>

 <?if ( have_posts() ) : while ( have_posts() ) : the_post();?>
     <?the_content();?>
 <?endwhile; endif;?>
 <?php wp_reset_query();
?>

The $paged checks to see if the category has more than one page, otherwise it defaults to 1 page. From there, we build the query_posts() options array.

  • paged – How many pages the results will be broken into
  • cat – Which category I want displayed. In my case, category of if ’5′.
  • posts_per_page – How many pages I want displayed per page. Every other category is set to 5 posts per page, but I want this one to be 10.

The rest of the loop is unchanged. There you have it, a category template displaying a custom amount of posts per page with pagination.

Setting width only on post featured image

February 9th, 2011 by cfree No comments »

WordPress allows you to set a featured image for a post or a page. You can call this featured image (thumbnail) in the loop, but you are restricted to how the thumbnail is sized. The options range from the default thumbnail size (150×150), but this cuts off part of the image. The rest of the options are the standard sizes: medium, large, and original size. The other option is to set your height and width using an array.

Recently I was tasked with posting either the thumbnail or the excerpt from a post, but the space where the loop was placed is limited in width. Since you cannot declare just a height *or* just a width, I had to find a work-around to avoid distorting the thumbnail.

#blog article img {
width: 170px;
height: auto;
}

Usually I would set just the width on the actual image itself, but since I don’t have access to the raw HTML, I had to simply use the CSS to define my dimensions. Set the width to what I want and set the height to ‘auto.’ This will resize the height automatically to retain the dimensions of the image while still resizing it to the desired width. Easy enough.

WordPress custom fields to display Page subtitle in navigation

September 14th, 2010 by cfree No comments »

The main navigation is basically a list of Pages in WordPress. In order to display a custom subtitle associated with each individual Page, I created a new custom field, called ‘Subtitle’, and assigned a value to it on each Page. The custom field is optional, and I restricted the navigation to only display parent Pages.

<?php
  $args=array(
    'depth' => 0,
    'echo' => 0,
    'sort_column' => 'menu_order',
    'post_type' => 'page',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'caller_get_posts' => 1,
    'meta_key' => 'Subtitle'
  );

  $attachments = get_pages($args);
?>

<div id="nav">
    <ul id="navLi">
    	<?php for ($i =0; $i<count($attachments); $i++) {
              $post = $attachments[$i];  ?>
              <li><a href="<?php echo get_permalink($post->ID) ?>"><?php echo $post->post_title; ?></a>
              <br/><span class="subtxt">
                  <?php echo $post->meta_value; ?>
              </span>
              </li>
        <?php } ?>
    </ul>
</div>



There you have it. The navigation is comprised of the title of the Page followed by the designated Subtitle underneath. The results, with CSS styling applied, can be seen below. Titles of the Pages are in black, Subtitles are in purple.

Page navigation w/ subtitles

StackOverflow DevDays, Seattle

October 24th, 2009 by cfree No comments »

logoWhile following Ralph Whitbeck on Twitter, I learned of a StackOverflow-sponsored dev conference series. Ralph was scheduled to present the jQuery talk at the Toronto DevDay, but by the time I learned of it, tickets were sold out. Using some of my connections, I was able to fly out to Seattle for their DevDay on October 21, 2009 at the Benaroya Hall.

A mere $99 got me a full day of information on / introduction to a few of the exciting new and upcoming technologies, a free lunch, and some StackOverflow swag. The conference was opened by an entertaining video leading to the introduction of the first speaker, Joel Spolsky, CEO of Fog Creek Software and co-founder of StackOverflow. After a general welcome speech, the conference began with a talk from Scott Hanselman on ASP.NET MVC. Althought Scott was enjoyable to listen to, I didn’t feel like I got enough information about .NET MVC, which may have been his way of making us buy his book on the same topic. Regardless, .NET MVC sounds like a technology I’d love to learn.

After a quick break, Rory Blyth talked about his experience with iPhone development and some new tips and tricks for those wanting to start programming, such as a development tool that allows for C#-based iPhone app construction. Being in the land of Microsoft, this awed many attendees. Joel spoke again after Rory, pitching his companies latest products, including FogBugz, Kiln, and StackOverflow, and introduced their newest project, StackExchange. Since the conference, I have created my own StackExchange, Seasoned Medic, which has yet to take off, but the knowledge exchange idea is still fairly useful in theory.

Cody Lindley gave a talk on the status of jQuery with a few examples. This is another technology that has been gaining incredible popularity in the dev community in the last few years. With my previous co-workers having such close connections with the jQuery team, I feel like I’m doing myself an injustice by not jumping on board sooner. I hope to find a project to explore this technology with soon. This talk was followed by a speech on Nokia’s recently acquired Qt software platform, which is intended to provide developers with a platform to code for multiple other platforms. For example, programming in Qt means you can produce the same product usable in .NET, Symbian platforms, etc. They hope to have Objective C support soon. Trying to code for 8 difference phone operating systems takes a ton of work to make one product look and feel the same for multiple platforms.I see a lot of potential for that, as developers will try to program for the broadest range possible.

During lunch, one of the conference’s sponsor, Microsoft, upgraded every attendee’s laptop memory to it’s maximum for free. Unfortunately, my Macbook is already maxed out, but I thought that the gesture was amazing on MS’s part.

Python was the next talk, which was fairly interesting. I have little experience with server-side scripting other than PHP and I would love to learn more. Dan Sanderson followed up with a review of changes with Google’s App Engine. Steve Seitz, a professor at the University of Washington, closed the DevDay with a few demonstrations of the work his classes had been doing with photography and information processing. Basically, his work revolves around the mapping and creation of algorithms pertaining to certain places. Using amateur photos taken from Flickr, he was able to give an almost 3-D rendering of the Vatican, Venice, and other popular traveling destinations.

Overall, the experience was fantastic. I learned so much about several hot topics and I can appreciate the introduction to some newer, lesser-known technologies that may be influencing the field in the coming months or years. The conference reminded me that there was so much more to learn and that I needed to find more time to play with code.

Sidebar: the iPhone application, OneBusAway, was incredibly helpful in navigating Seattle via the bus. I highly recommend it, though it’s too bad it really only works for Seattle.

Just two more

March 10th, 2009 by cfree No comments »

The new quarter started yesterday. I always love this time, since the classes are all fresh and interesting and we get to see what we are in for before we start learning. I am taking a full courseload this time, which I typically have trouble with. Do or die!

Social Psychology: I was disheartened to learn that this class was at 8am. I haven’t taken an 8am class in years and Seniors should not have to. The teacher seemed down to earth, though she made some awkward comments to a student during the break that caught me off guard. I can tell this class will be a lot of work, as it’s not just memorizing concepts, it’s using them and being able to identify them. Oh, and no textbook. (Mondays, Wednesdays 8am-10am)

Human Biology III: Human Health and Disease
: I am really excited for this class, since it is a review of some body systems and how they work together to fight off disease, etc. My interests recently have been learning towards biology, so it’s nice to have some connection to the field while finishing this degree. Also, we will be looking at bacteria, fungi, virii, and other interesting pathologies. Plus the teacher is easy to listen to, enthusiastic, and easy on the eyes. (Mondays, Wednesdays, Fridays 10am-11am; Lab: Tuesdays 2pm-4pm)

Human Communication: I figured I could use some help in the communications department, so I picked this class. Interestingly it is a "blended course," so it only meets one day per week and the rest of the work is done online. I hope I can keep motivated to do the work necessary. The topics sound intriguing, and I already have a good group for the 30 minute presentation. The 20-page paper is slightly intimidating, however. (Mondays, Wednesdays 2pm-4pm)

iPhone Application Development: I go back and forth between being really nervous to take this and really excited. Based on the descriptions, it sounds like a really challenging but will prove to be VERY useful in the workplace. There are several group and individual projects expected, and we will be creating a homepage that will integrate with an application that we develop. Cool! Give me ideas of apps you’d like to see! (Tuesdays, Thursdays 10am-12pm)

Graduation is approaching…

Oh, and I am ecstatic to know that President Obama has signed an executive order that ends the ban on federal funding of embyonic stem cell research. Although advances have been made in the recent past, federal funding towards this amazing research will greatly advance the science and healthcare fields immensely. It is so exciting to be on the cusp of this revolution; I can’t wait to be apart of something so big!

Change has come!

I really don’t mind… I really don’t mind… I really don’t mind…

January 15th, 2009 by cfree No comments »

I really don’t mind the usual gripes, such as the shoveling, the constant car-cleaning, the horrible winter-drivers…

However, when it’s 7 degrees and WINDY, I have to keep reminding myself that I enjoy winter.
I got in the car and had icicles on my face….

Who’d have thought?

January 14th, 2009 by cfree No comments »

Finals

December 28th, 2008 by cfree No comments »

Tomer and I spent a few all-nighters studying and writing papers. Won’t miss days like this.

Seizure later!

October 28th, 2008 by cfree No comments »

Title: Epilepsy Drug Could Reverse Early Stages Of Alzheimer’s Disease, Say Scientists
Author: Fiona Macrae

Summary:
Researchers have discovered that mice, with early signs of Alzheimer’s disease, have shown improvements in memory and slowed disease progression while being administered valproic acid. The studies have been so successful that there are human trials in progress with results likely to be announced within the next year.

History and Progression:
Alzheimer’s disease (AD) usually develops later in life, manifesting as memory problems, mood swings, aphasia, irritability, aggression, and loss of motor function. While not fully understand, it is believed that AD is caused by plaque and sticky protein that choke the brain’s functioning. Current AD drugs can halt the degradation process, however not everyone experiences the same effects. Eventually the AD drugs wear off and the disease progresses as normal.
Valproic acid is an anticonvulsant that is typically used as treatment for manic depression, schizophrenia and epilepsy. It also tends to block production of the plaque/sticky protein that causes AD. Apparently the drug has a decreased effect as the disease progresses. While the trials are producing exciting results, it is discouraged as a current use for AD because of the apparent side effects.

Quality:
Valproic acid was not initially intended to serve as an adequate treatment for AD. Despite promising results from initial mice and human trials, the side effects are still unknown so the drug should be considered unstable until proven otherwise.

Order:
Patients using this treatment option seem to gain memory function back, which will help with their self awareness and pride of their condition. They would need less supervision because they could potentially function better on their own.

Conflict:
This drug would probably not be a good treatment candidate for a current seizure, depression or bi-polar patient with AD. I imagine conflicting treatments if they were compliant with another type of treatment for the previously mentioned ailments and with valproic acid.

Positive Benefits:
Alternative treatment options for AD are presented to hopefully produce greater results than current marketed treatments.

Negative Effects:
Valproic acid has not been fully studied as an alternative treatment for AD and therefore side effects are currently unpredictable.

Political Beliefs:
I believe the government should support towards this research, as many citizens are already afflicted with AD and that number is expected to double within the coming years. Pharmaceutical companies would have much to gains, so I predict they will be lobbying for continued support of research in this area.

Religious Beliefs:
As with most chemicals, some may find religious conflicts by ingesting a medication. I do not know of any religious objections to the current AD treatments. I approve of the use of the valproic acid, as patients would likely have a better cognitive relation with their god.