Welcome Guest, Not a member yet? Register   Sign In
Good Email Form Tutorial or Code


I'm working my way through a form which will simply take details and email them to me.

I've done a search for Codeigniter forms but Godbit was the main one which is based on an older version of codeigniter.

Not like me to ask straight off the bat, but anyone have a link to a good modern tutorial or code that does validation etc. It's an emergency!

Many thanks.


I havn't seen any tutorials for that sort of thing. The form validation has lots of examples on the library page here --> http://ellislab.com/codeigniter/user-gui...ation.html

After you've validated it just need to email it off which is really easy, you can find the info here --> http://ellislab.com/codeigniter/user-gui...email.html

You can put the posted variables in your email by using something like this:

$this->email->message('Some Field:'.$this->input->post('form_field_name'));

[eluser]got 2 doodle[/eluser]

As far as putting your mail message together I've found this technique useful
$message = $this->load->view('contents_email_cart',$data,true);

$data['user_data']= $this->userdata->get_user_data($this->user_id);
$order_email = $this->sitedata->get_site_key('order_email');
$this->email->subject('Website order');

The first line sends the data to a view with the 'true' parameter set, in my case it's a confirmation of an online order.

Here's a chunk of the view code.
Website generated order.
$today = getdate();
$year = $today['year'];
$month = $today['month'];
$daynum = $today['mday'];
$dayname = $today['weekday'];
echo "This order was placed on $dayname, $month $daynum, $year\n";
$the_code = random_string('numeric',8)."\n";
echo "ID Number:$the_code\n\n";

This allows an easy way to build a text message for emailing.

I know it doesn't directly answer your question and it could be considered a hack but it wasn't immediately obvious to me that you could do this in CI, now that I know you can it makes formatting the email real easy. I haven't tried it with html emails, but it should be no problem.

I thought this might save you some time.

Theme © iAndrew 2016 - Forum software by © MyBB