[eluser]rhand_ci[/eluser]
Just started using CI about two weeks ago. Did a few tutorials and am now trying to make my first form that already stores data into a table even though validation is not done yet. What I am wondering about is how I can send this data to an email address and store it into a database at the same time. Here is the controller code I have made so far:
Code:
<?php
class Rentalform extends Controller {
// Extend controller with new one
function Rentalform()
{
parent::Controller();
$this->load->helper(array('form', 'url')); // load two helpers
$this->load->library('form_validation'); // load form validation from the library
$this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]');
$this->form_validation->set_rules('email', 'Email', 'required|valid_email');
}
function index()
{
$data['title'] = "Rental Form";
$data['heading'] = "Rental Form Heading";
$this->load->view('rentalform_view', $data);
}
function insert_rentalform()
{
$this->db->insert('rentalform', $_POST);
redirect('rentalform');
}
}
And here is the view:
Code:
<html>
<head>
<link href="<?=base_url()?>style.css" rel="stylesheet" type="text/css">
<title><?=$title?></title>
</head>
<body>
<h1><?=$heading?></h1>
<?=form_open('rentalform/insert_rentalform'); ?>
<div style="float:left;">
<h3>Company name</h3>
<p><input type="text" name="company_name" /></p>
<h3>Company address</h3>
<h4>street name</h4>
<p><input type="text" name="company_street_name" /></p>
<h4>post code</h4>
<p><input type="text" name="company_post_code" /></p>
<h4>City</h4>
<p><input type="text" name="company_city" /></p>
<h4>Country</h4>
<p><input type="text" name="company_country" /></p>
<h3>Phone Number</h3>
<p><input type="text" name="company_phone" /></p>
<h3>Email address</h3>
<p><input type="text" name="company_email" /></p>
</div>
<div style="float:right;">
<h3>Price range</h3>
<h4>Small</h4>
<p><input type="radio" name="company_price_range_small" value="50%" /></p>
<h4>medium</h4>
<p><input type="radio" name="company_price_range_medium" value="25%" /></p>
<h4>large</h4>
<p><input type="radio" name="company_price_range_large" value="10%" /></p>
<h4>Largest</h4>
<p><input type="radio" name="company_price_range_largest" value="5%" /></p>
<h3>Description</h3>
<p><textarea name="company_description" rows="10"></textarea></p>
<p><input type="submit" value="Submit Comment" /></p>
</div>
</form>
</body>
</html>
Is what I want possible? Any hints how to would be really appreciated!