Welcome Guest, Not a member yet? Register   Sign In
Creating a dynamic lead form to send data to DB and send emails
#1

[eluser]ModernM[/eluser]
I need some advice on how to proceed with my project.

Overview:

I have a view (called site) that loads a page that has 2 options for a user to enter data. If they click "option 1" they are presented with a form that collects basic Name, rank, serial number in the first section, then below that there is information that is specific to the "Option 1" click. If they click "Option 2" they are presented with a form that has the same info Name, Rank, etc but the second section below has different data values.

So what I have done is create 2 controllers to handle the different options. so option1 controller loads all the code to handle the process of getthing the data from the post method, generating and email to the lead manager and a thank you email to the person filling out the form. and another controller optoin2 to do the same thing.

My questoin is this. Since there are only 4-5 fields that are different from option1 and option 2 do I need to have a seperate controller for each?

Or is there some way to be able to have one controller process everything based on what view is loaded.

Here is my code.


The site controller loads the view site which has an html page with 2 buttons

option 1 controller

I have another controller called option 2 that looks exactly the same except the get post variables are different

Example

DO I NEED 2 CONTROLLERS TO DO THIS?

COMMON DATA FOR BOTH FORMS.

$first_name = $this->input->post('first_name');
$last_name = $this->input->post('last_name');
$webtolead_email1 = $this->input->post('webtolead_email1');
$phone_home = $this->input->post('phone_home');
$call_time = $this->input->post('call_time');
$birthdate= $this->input->post('birthdate');
$call_time = $this->input->post('call_time');
$primary_address_street = $this->input->post('primary_address_street');
$primary_address_city = $this->input->post('primary_address_city');
$primary_address_state = $this->input->post('primary_address_state');
$primary_address_postalcode = $this->input->post('primary_address_postalcode');

// Option 1 DATA
$insurance_type_c = $this->input->post('insurance_type_c');
$insurance_company_c = $this->input->post('insurance_company_c');
$plan_type_c = $this->input->post('plan_type_c');
$time_insured_c = $this->input->post('time_insured_c');

// Option 2 DATA
$plan_type_c = $this->input->post('plan_type_c');
$insurance_needs_c = $this->input->post('insurance_needs_c');
$insurance_reason_c = $this->input->post('insurance_reason_c');


Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Insured extends Ci_Controller
{

function __construct(){
  
  parent::__construct();
}

function index()
{
  $this->load->view('forms/insured_form');
}

function send()
{

/*
* Get post data from form
*/

$first_name = $this->input->post('first_name');
$last_name = $this->input->post('last_name');
$webtolead_email1 = $this->input->post('webtolead_email1');
$phone_home = $this->input->post('phone_home');
$call_time = $this->input->post('call_time');
$birthdate= $this->input->post('birthdate');
$call_time = $this->input->post('call_time');
$primary_address_street = $this->input->post('primary_address_street');
$primary_address_city = $this->input->post('primary_address_city');
$primary_address_state = $this->input->post('primary_address_state');
$primary_address_postalcode = $this->input->post('primary_address_postalcode');

// INSURED DATA
$insurance_type_c = $this->input->post('insurance_type_c');
$insurance_company_c = $this->input->post('insurance_company_c');
$plan_type_c = $this->input->post('plan_type_c');
$time_insured_c = $this->input->post('time_insured_c');

// INSURED DATA
// $plan_type_c = $this->input->post('plan_type_c');
//$insurance_needs_c = $this->input->post('insurance_needs_c');
//$insurance_reason_c = $this->input->post('insurance_reason_c');



$company = $this->input->post('company');
$telephone = $this->input->post('telephone');
$email = $this->input->post('email');

$data = array('name'=>$name,'company'=>$company,'telephone'=>$telephone,'email'=>$email);

  $this->load->library('email');
  $this->email->from('[email protected]');
  $this->email->to($email);  
  $this->email->subject('Thank you for Registering with Nano Materials Group');
  
  $this->email->message($this->load->view('email_templates/lead', $data, true));
  $this->email->set_alt_message('Thank you for registering with');  
  
  
  if($this->email->send())
  {
  
   /*
   * Update Database with Lead
   */
  
   // To Do
  
   /*
   * Send thank you email
   */
   $this->email->from('[email protected]', 'Your Name');
   $this->email->to('[email protected]');
   $this->email->subject('Email Test');
   $this->email->message('Testing the email class.');
   $this->email->send();
  
   /*
   * Load thank you page
   */
   $message = array
* code got cut off.

Any help would be great, thanks.
#2

[eluser]dnc[/eluser]
Personally, I think I would do this with one controller. Simply pass the $_POST value to the data array and then thank the user and send the email.

The data['options'] will need to be different because the input will vary. Other than that data[] will be the same key.



I would just populate the data['same_input'] and also populate the appropriate $data['options'] depending on what the user chose on submit.




Theme © iAndrew 2016 - Forum software by © MyBB