Professional CodeIgniter

(singke) #1

Chapter 8: Last-Minute Upgrades


253


$this- > MSubscribers- > createSubscriber();
$this- > session- > set_flashdata(‘subscribe_msg’, ‘Thanks for subscribing!’);
redirect(‘welcome/index’,’refresh’);
}else{
$this- > session- > set_flashdata(‘subscribe_msg’, “You didn’t fill out the
form!”);
redirect(‘welcome/index’,’refresh’);
}
}

Creating the Form


Finally, you can work on the form. You need to allow for two form fields — a name and an email. You
also know that you need to post to welcome/subscribe. That ’ s all you really need in order to create the
form. In the example below, fieldsets and labels are used, but other approaches are equally valid.

One important note: The Subscription form has been added to the home view. As you can see, it is a
simple form that prompts the user to fill in his name and e - mail address. In this particular case, the
example uses a fieldset to delineate the form, but you could use any visual design convention to separate
it from other parts of the page.

< div id=’pleft’ >
< ?php
echo “ < img src=’”.$mainf[‘image’].”’ border=’0’ align=’left’/ > \n”;
echo “ < h2 > ”.$mainf[‘name’].” < /h2 > \n”;
echo “ < p > ”.$mainf[‘shortdesc’]. “ < br/ > \n”;
echo anchor(‘welcome/product/’.$mainf[‘id’],’see details’). “ < br/ > \n”;
echo anchor(‘welcome/cart/’.$mainf[‘id’],’add to cart’). “ < /p > \n”;
? >

< br style=’clear:both’ > < br/ >
< ?php
if ($this- > session- > flashdata(‘subscribe_msg’)){
echo “ < div class=’message’ > ”;
echo $this- > session- > flashdata(‘subscribe_msg’);
echo “ < /div > ”;
}
echo form_open(“welcome/subscribe”);
echo form_fieldset(‘Subscribe To Our Newsletter’);
$data = array(‘name’= > ’name’, ‘id’ = > ‘name’,’size’= > ’25’);
echo “ < p > < label for=’name’ > Name < /label > < br/ > ”;
echo form_input($data). “ < /p > ”;
$data = array(‘name’= > ’email’, ‘id’ = > ‘email’, ‘size’= > ’25’);
echo “ < p > < label for=’email’ > Email < /label > < br/ > ”;
echo form_input($data). “ < /p > ”;
echo form_submit(“submit”,”subscribe”);
echo form_fieldset_close();
echo form_close();
? >
< /div >

< div id=’pright’ >
< ?php
Free download pdf