CodeIgniter From Scratch: Day 4

CodeIgniter From Scratch: Day 4 – Newsletter Signup

Aug 12th, 2009 in Screencasts by Jeffrey Way

Continuing on from Day 3, we'll expand our little application into a simple newsletter signup form. This will allow us to taker a closer look at both the email and the form_validation classes. Learn it all in this 30 minute screencast.

PG

Author: Jeffrey Way

Hi, I'm Jeff. I'm the editor of Nettuts+, and the Site Manager of both ThemeForest, and CodeCanyon. I spend too much time in front of the computer and find myself telling my fiance', "We'll go in 5 minutes!" far too often. I just can't go out to dinner while I'm still producing FireBug errors...drives me crazy. During my free time, I sporadically write articles for my own personal blog. If it will keep you in the good graces of the church, follow us on Twitter.

Catch Up

Day 4

If you're having trouble viewing the video, watch it here instead.


Related Posts

Check out some more great tutorials and articles that you might like

Enjoy this Post?

Your vote will help us grow this site and provide even more awesomeness

Plus Members

Source Files, Bonus Tutorials and
More for $9 a month for all TUTS+
sites in one subscription.

Join Now

User Comments

( ADD YOURS )
  1. PG

    Joseph Wilson August 12th

    I spent most of yesterday refreshing my browser…waiting for the next installment in the series! *blushes*

    Thanks, Jeffrey, for continuing the series. (And no, I haven’t watched this video yet. ;) )

    ( Reply )
    1. PG

      Shane August 12th

      Me too – thanks for continuing the series Jeffrey!

      ( Reply )
      1. PG

        Jeffrey Way August 12th

        Thanks, guys!

    2. PG

      Joseph Wilson August 12th

      Okay…just finished it! “Fully awesome!” :D

      ( Reply )
  2. PG

    Mohsen August 12th

    Watching the tut…
    thanks

    ( Reply )
  3. PG

    ibura August 12th

    thank you jeff, i am building my knowledge base only from you.

    ( Reply )
  4. PG

    Johan August 12th

    Nice! Just one little thing:

    Did’nt you say in the first video that you would walk the “readers” thru writing an CMS? We are already in video 4 of 10 and it’s still very basic stuff going on (only fetching from database). To me the email-class seems like it should be coming a little further down the line…

    The quality is very good though, and I hope you’ll continue with the series.

    ( Reply )
    1. PG

      Jeffrey Way August 12th

      I can’t begin teaching how to build a CMS until I’ve taught the basics.

      ( Reply )
      1. PG

        Jeffrey Way August 12th

        Keep in mind that this series is for beginners who have no experience working with the MVC pattern. It takes time… :)

  5. PG

    Shane August 12th

    That email label’s for attribute references the name input incorrectly. Sorry to be a pedant! :)

    Good stuff Jeffrey!

    ( Reply )
    1. PG

      Jeffrey Way August 12th

      The label references the id of the input.

      ( Reply )
      1. PG

        Shane August 12th

        Yeah – I know what the ‘for’ attribute is um… for :)

        Your second label’s ‘for’ attribute associates it with the first input (the name input.)

        The second label’s for attribute should have a value of email.

      2. PG

        Jeffrey Way August 12th

        Oh, hehe. I guess that ruins the entire tutorial then. :)

      3. PG

        Shane August 12th

        I’m sure we can let you off, just this once ;)

        (And I did apologise :) )

  6. PG

    Yoosuf August 12th

    gonna watch, should be a nice one as usual :)

    ( Reply )
  7. PG

    Drazen Mokic August 12th

    Well done Jeffrey!

    Just a little thing, you did not xss_clean the input fields ‘name’ and ‘email’, maybe you are using global xss cleaning? I think especially beginners should learn to use this every time they work with user input.

    Apart from that, thanks for the tutorial, great work!!!

    ( Reply )
    1. PG

      Jeffrey Way August 12th

      Did I not mention turing on global xss cleaning in the video? I thought I did. If not, we’ll go over that in Day 5.

      ( Reply )
  8. PG

    Chad Hietala August 12th

    Keep them coming Jeffery! All of these screencasts allows me to get a better grasp of the MVC pattern.

    ( Reply )
  9. PG

    asdoaw August 12th

    Jeffrey why dont you just press cmd+tab instead of using this silly window explorer

    ( Reply )
    1. PG

      Jeffrey Way August 12th

      Because I don’t.

      ( Reply )
      1. PG

        Lee August 13th

        Its much more Swoooooshy to do it like that, don’t you agree? :) Great tut Jeff, look forward to the rest!

  10. PG

    Chris August 12th

    Yes! Chicken enchiladas and CodeIgniter. It’s a great day! Thanks Jeffrey!

    ( Reply )
  11. PG

    jlapitan August 12th

    thanks jeff, i just started from Day1.. hehe.. i would like to teach this on my class also, im using your video tutorials about “jquery for absolute beginners” for my class now..

    is there a way i can download your complete video tutorials about jquery?

    Thanks!

    ( Reply )
    1. PG

      Jeffrey Way August 12th

      Go to iTunes and search for “Nettuts.” They should come up for download.

      ( Reply )
  12. PG

    Zac August 12th

    I think updating a database should be included in the next tut. These are great videos! Thank you!.

    ( Reply )
  13. PG

    DaViDz August 12th

    Awesome, thanks from Spain :)

    ( Reply )
    1. PG

      David Rojas August 12th

      Another David from Spain here ;-)

      ( Reply )
      1. PG

        Carlos August 15th

        +1 from Madrid, Spain.

  14. PG

    Jon Piehl August 12th

    Question 1:
    Is there a difference between the config you created (system_root) and the url helper (base_url)? If so, can you please explain.

    Question 2:
    I’m new to MVC so I was wondering why the $name_data array is set in the view instead of the controller and then passed to the view. The real question is when should variables be set in the controller and when should they be set in the view?

    Thanks. These tuts are amazing!

    ( Reply )
  15. PG

    Kevin August 12th

    If you would write a big website, how do you keep things organized? Do you use subfolders for your views/controllers?

    ( Reply )
    1. PG

      Drazen Mokic August 12th

      Yes, if you have i.e. a site with an admin backend then you should use subfolders.

      f.e.

      -views
      -welcome.php
      -register.php
      –admin
      —index.php
      —module1.php
      —module2.php

      ( Reply )
      1. PG

        harton August 12th

        How to you call controllers in subfolders?

        thx. :-)

      2. PG

        Drazen Mokic August 12th

        Controllers are called over the URL…

        domain.com/subfolder/controller …

      3. PG

        Santiago Dimattía August 12th

        @harton

        Simply use:
        $this->load->view(‘folder/file’);

        Note that you can only use one subfolder. If you use 2 or more, it will fail.

      4. PG

        Santiago Dimattía August 12th

        Ups, i think i’m tired.
        Ignore my previous comment!

    2. PG

      Lee August 13th

      I follow the convention of putting all my views in a folder named after the controller, so:
      BLOG
      -Index
      -Comments
      – Etc
      ADMIN
      – Index
      – Users

      And call them like:
      $this->load->view(‘blog/index’);

      Just my method, but keeps things nice and organised!

      ( Reply )
  16. PG

    George August 12th

    Hey guys, I am just waiting for the tutorial to load and I am going to watch it later, great series by the way.
    Can I ask if you would consider offering us a download link to the video file as well?

    ( Reply )
    1. PG

      David Rojas August 12th

      You can download all nettuts videos in iTunes (search NETTUTS), or from blip.tv (in 2 qualities). This video is here: http://nettuts.blip.tv/file/2466799/

      ( Reply )
  17. PG

    harton August 12th

    Hi Jeff,

    great tut. :-)

    One questions though:
    Can you also use “return;” at a method in case you want to abort its action?

    Considering your next tut:
    It would be cool if you can show a tut that passes variables from the view into the controller up to the model and back.

    thanks for your great work :-)
    cheers
    harton

    ( Reply )
  18. PG

    Greg McAusland August 12th

    Loving this series, keep em coming!

    ( Reply )
  19. PG

    Vasili August 12th

    Though I don’t use CI (or any framework for that matter), I still enjoy watching these screencasts. I thought it was funny at first when you were typing the rules and didn’t have them as strings. I was thinking to myself that PHP would parse them as constants, which it did.

    However, my favorite part has got to be the jQuery reference. This is why I love your videos, Jeffrey. They are always funny even if you don’t mean to make them. :P

    ( Reply )
  20. PG

    Brian Temecula August 12th

    CI evangelism at its finest.

    ( Reply )
  21. PG

    Chris Brown August 12th

    Another great tutorial in this series. I’ve really been taking away a lot from each video and even read ‘CodeIgniter for Rapid PHP Application Development’ in 3 days after following the first tutorial.

    This is definitely one of the best video tutorial series to date from Nettuts…maybe even going to be better than the jQuery series. Thanks for the knowledge share!

    ( Reply )
  22. PG

    Cecily August 12th

    I was following along just fine until about 22 minutes in. In the tutorial when you pressed the Submit button to send the empty form, the page reloaded with error messages displaying. When I tried it on my setup, I got a 404 not found error. I’m not exactly sure why, as the send function is included in my email.php controller file. Do you know what might be causing this error?

    ( Reply )
    1. PG

      Cecily August 12th

      Never mind – I figured it out. It had to do with the configuration of my base_url, although I don’t know why it worked fine in episode 3 but not episode 4.

      ( Reply )
      1. PG

        Jeffrey Way August 13th

        My guess is that you forgot to rename the base_url within the config file to day4 (instead of day3)??

  23. PG

    Johnathan August 13th

    Hey Jeff, was wondering if you could maybe keep the names of each video the same like Codeigniter: Day x or w/e I have to keep changing them so they get added to my smart playlist in iTunes. Would make it look a whole lot more organised.
    But apart from that they’re great.
    Thanks :)

    ( Reply )
  24. PG

    kamal August 13th

    Hi Jeffrey Way,

    Thank you for this tuto.

    I search a tutorial of MVC symfony framworks,

    Can you post a tutorial about this MVC

    Thanks again

    ( Reply )
  25. PG

    Domino August 13th

    For anyone trying to make the download files work, the following needs to be changed:

    1. Go to the routes.php in the application>config folder. Change the default controller from ’site’ to ‘email’.

    Mr. Way, the index function in your ’site’ controller is missing a semi-colon and the closing curly brace.

    ( Reply )
  26. PG

    Danijel August 13th

    Just watched it. It’s great. :) Wondering when Part 5 is out?

    ( Reply )
    1. PG

      Jeffrey Way August 13th

      Around next Tuesday.

      ( Reply )
      1. PG

        Danijel August 13th

        Can’t wait :D

  27. PG

    Soner Gönül August 13th

    That’s great! Thanks :)

    ( Reply )
  28. PG

    Arnold August 13th

    Thanks! Jeffrey…I think this is better than Day 3..because you’ve taught lots of good stuff right there…

    In day 5…
    how about we use some more sessions ?or use some javascript library like jQuery

    I cant wait really for day 5..
    yay!

    ( Reply )
  29. PG

    Jim August 13th

    Nice one. I might be jumping the gun here, but it would be cool to see a tutorial or two on using some of the third-party libraries (http://codeigniter.com/wiki/Libraries):

    - IgnitedRecord for ORM
    - Tank Auth for Authentication
    - Modular Extensions for HMVC

    Something along those lines. I’d also really like to see a tutorial for creating an admin area, but I understand you need to teach the fundamentals first. Either way, keep the CI tuts coming!

    ( Reply )
  30. PG

    MEM August 13th

    Those are very nice tutorials.

    CodeIgniter should know about this and put a big link here. Very nice stuff. I’m absolutely new on frameworks, I have played a little with OOP so those tutorials feets like a charm.

    I will however, not follow a path of lets use nice features BUT, lets learn more about basic features. Once we have the basic, we can move on on more complicated stuff.

    For example: Build a menu, a pagination, working with joins… this kind of stuff, it’s the basic, but will allow us to properly develop.

    Regards,
    MEM

    ( Reply )
  31. PG

    jeanv August 14th

    great ! Thanks ! Keep on Jeffrey you’re doing a good job !

    ( Reply )
  32. PG

    rosnovski August 14th

    Jeff,

    Nice screencast. I am glad you still are doing this. I wanted to know if you would be doing one with jquery used to do ajax and all the fun stuff you taught us with the jquery screencasts? anyways love all the screencasts so far and here’s to more good stuff. Keep it up sir!

    ( Reply )
  33. PG

    benoa August 15th

    Sweet! Thank you JW :^)

    ( Reply )
  34. PG

    Bjørn endre August 15th

    Great screencasts, Jeff! I didn’t know about CI before you started with these tutorials. I’m definitely going to use the framework in my current and future web projects.

    A couple of things though; Could you provide a list with planned screencasts, like what topics and when you are going to cover them? And also, could you please bump secure login (with salts and sha1, user levels, the whole pack) up on that list? ;)

    I’m really looking forward to the next screencast, keep ‘em coming!

    ( Reply )
  35. PG

    Javed Gardezi August 15th

    Great series please continue on..
    can not wait for next one… JW

    ( Reply )
  36. Jeffrey, is there a reason on why you’re not using shorthand PHP on the form_open() ?

    ( Reply )
  37. PG

    timo.huber August 16th

    thanks again.
    i’ve learned a lot :)

    ( Reply )
  38. PG

    Khalil August 18th

    Dear Jeffrey Way,

    I am learning from your posts these are very good for new students like me… Please share a post for Login Form with Validation on CI Framework.

    ( Reply )
  39. PG

    Gonzalo August 18th

    Thanks for the tutorial, Jeff. Any chance you share with us your Dreamweaver Coloring Scheme? It’s a dark one with brown tones… you used it here: http://net.tutsplus.com/videos/screencasts/easy-development-with-codeigniter/

    It’s an XML file (Colors.xml) in Documents and Settings\<user\Application Data\Adobe\Dreamweaver CS4\en_US\Configuration\CodeColoring

    Thanks in advance :)

    ( Reply )
  40. PG

    Zach August 19th

    Jeffrey,

    Loving these videos. Constantly refreshing my iTunes podcasts window in the middle of the week to check for updates to the series.

    Please please please keep up the good work.

    Thanks so much.

    ( Reply )
  41. PG

    bluepicaso August 24th

    hello people i want to thank Jeffry Way, elliot and the tuts plus team for there screencasts here…..
    I was a newbie to CI and this week I will be launching my first ever project(a travel site) totally based on codeigniter…
    I’m just loving it… Thanx people…

    follow me on twitter http://www.twitter.com/bluepicaso

    ( Reply )
  42. PG

    Kevin August 26th

    Hey jeffrey,

    The last 3 tutorials were great. But this one doesn’t seem to work for me :(
    It just shows the loading animation, even though the whole thing has finished loading. I’ve tried it in several different browsers.

    Can you put up a download link of the video? It just doesn’t seem to work for me.

    Anyways, the last 3 were great. Thanks alot. Keep up the good work!

    ( Reply )
  43. PG

    Vaidotas August 26th

    Where is day 5? :( Cann’t wait :(

    ( Reply )
    1. PG

      Jeffrey Way August 26th

      Definitely Thursday, or Friday!

      ( Reply )
      1. PG

        Guillermo Carrion August 28th

        Great! Can’t wait! :-)

  44. PG

    Ryan August 28th

    Can’t wait for day 5!!!

    ( Reply )
  45. PG

    Ben August 28th

    Dude your killing me whens the next one!!

    Waiting…..

    Loving them obviously!!!

    ( Reply )
  46. PG

    Alvin Crespo August 30th

    Purely amazing. I did not know that code igniter comes with such a powerful form validation class. This is awesome, thank you so much for taking the time to explain this to us. I feel like I have a good grasp on this framework now, with all that you have taught us in just 4 screencasts. The 5th one is next, cant wait!

    ( Reply )
  47. PG

    patience September 1st

    Video won’t play. Been trying for 2 days now.

    ( Reply )
    1. PG

      Jeffrey Way September 2nd

      How strange. I just added a link below the video where you can watch it directly at Blip.tv.

      ( Reply )
  48. PG

    Wilson September 3rd

    Thanks from Brazil!
    I’m learning so much!
    I love you man!

    ( Reply )
  49. PG

    Chaky September 5th

    Thanks for Hong Kong
    I loving you….you re the bst

    ( Reply )
  50. PG

    Isabela September 11th

    The day 3 and 4 of this series had a very good timing in my project.Thanks Jeff.You’re doing a great job

    ( Reply )
  51. PG

    Howard September 17th

    Is there a “best practice” for multiple page forms?

    For example, the user goes to page and enters some registration information. Based on the choices made in the form, the user is sent to a second page to fill out more information.

    Do you hold the user data in session variables? Or to you update the database after every page?

    Thanks!

    ( Reply )
  52. PG

    Rich Webster September 18th

    First, thank you for the series… quite good. I did have one problem with it, and maybe it was my fault. But for other newbies:

    this->email->set_newline(‘\r\n’); gave me problems.

    it put a newline in the middle of the header, after sending. I think this is because the sending server (qmail, masquerading as sendmail) prepended some header info, then the newline appeared, then the rest of the header info supplied by the Email class appeared… The newline caused part of the header to appear in the body, including the multipart stuff, causing the html to not render, the mime info and some of the header info to look wonky, and me to tear out what little hair I have left. Removing the newline code restored my sanity.

    So is my mail server weird? Did you ever figure out why the line needs to be there (since it seemed to solve MY problems to take it out)? Has anyone else had a similar experience?

    The one thing I’ve done a bit different than this tutorial is: I was loading a pre-designed HTML page as the message, using read_file(), with the intent of creating a system that sends a series of emails to anyone who signs up, starting with the first and continuing monthly for a year… rather than your system that sends a just-saved message on demand. But that shouldn’t have affected the headers.

    ( Reply )
  53. PG

    Gregory October 15th

    Hi Jeff,

    I noticed when you referenced the stylesheet it was for that single view, is it possible to reference a css file for all your views?

    Thanks!

    ( Reply )
  54. PG

    Maxx90 October 22nd

    And third, and probably most importantly, simplifying the benefit formula as part of a larger Social Security reform. ,

    ( Reply )
  55. PG

    anzahen October 27th

    http://nettuts.blip.tv/file/2466799?filename=NETTUTS-CodeIgniterFromScratchDay4184.flv
    where the video?
    problem loading page
    The server at nettuts.blip.tv is taking too long to respond.

    ( Reply )
  56. PG

    t0m3k November 18th

    Hi.
    I’m getting strange issue:
    Fatal error: Call to undefined function form_open() in C:\Program Files\WebServ\httpd\codeigniter\application\views\newsletter.php on line 15

    Somebody knows what’s the problem?
    I downloaded files from this page and I’m getting the same error.

    ( Reply )
  57. PG

    ChoiZ January 3rd

    Hi, i try to send an email with Code Igniter.

    With plain/text it’s works (with smtp protocol like your screecast).

    But when i set: $config['mailtype'] = ‘html’; in my config/email.php file it’s doesn’t works… Any ideas ?

    Thank you for this great tutorials ;)

    ( Reply )
  58. PG

    ChoiZ January 4th

    Ok i’ve got my answer in my config/email.php you have to specify :

    $config['charset'] = ‘iso-8859-1′;

    if you want to send an html mail with code igniter ;)

    Regards,

    ( Reply )
  1. Arrow
    Gravatar

    Your Name
    January 4th