Welcome Guest, Not a member yet? Register   Sign In
Store form data in database and email it to email address x
#1

[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>&lt;?=$heading?&gt;</h1>
    &lt;?=form_open('rentalform/insert_rentalform'); ?&gt;
    <div style="float:left;">
    <h3>Company name</h3>
    <p>&lt;input type="text" name="company_name" /&gt;&lt;/p>
    <h3>Company address</h3>
    <h4>street name</h4>
    <p>&lt;input type="text" name="company_street_name" /&gt;&lt;/p>
    <h4>post code</h4>
    <p>&lt;input type="text" name="company_post_code" /&gt;&lt;/p>
    <h4>City</h4>
    <p>&lt;input type="text" name="company_city" /&gt;&lt;/p>
    <h4>Country</h4>
    <p>&lt;input type="text" name="company_country" /&gt;&lt;/p>
    <h3>Phone Number</h3>
    <p>&lt;input type="text" name="company_phone" /&gt;&lt;/p>
    <h3>Email address</h3>
    <p>&lt;input type="text" name="company_email" /&gt;&lt;/p>
    </div>
    <div style="float:right;">
    <h3>Price range</h3>
    <h4>Small</h4>
    <p>&lt;input type="radio" name="company_price_range_small" value="50%" /&gt;&lt;/p>
    <h4>medium</h4>
    <p>&lt;input type="radio" name="company_price_range_medium" value="25%" /&gt;&lt;/p>
    <h4>large</h4>
    <p>&lt;input type="radio" name="company_price_range_large" value="10%" /&gt;&lt;/p>
    <h4>Largest</h4>
    <p>&lt;input type="radio" name="company_price_range_largest" value="5%" /&gt;&lt;/p>
    <h3>Description</h3>
    <p>&lt;textarea name="company_description" rows="10"&gt;&lt;/textarea></p>
        <p>&lt;input type="submit" value="Submit Comment" /&gt;&lt;/p>
        </div>
        &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

Is what I want possible? Any hints how to would be really appreciated!


Messages In This Thread
Store form data in database and email it to email address x - by El Forum - 02-12-2010, 03:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB