2015-08-18 3 views
0

Я пытаюсь передать данные формы, такие как имя, адрес электронной почты с простой страницы html в приложение CodeIgniter. Direcotry Structute: SampleDirПередача данных формы извне в CodeIgniter

  • CodeIgniterApp
  • form.html

Я пытаюсь передать форму (POST) и получать внутри CodeIgniter. Я новичок в CodeIgniter и пытаюсь подключить свое приложение к стороннему приложению. Из того, что я искал, CodeIgniter имеет контроллеры и представления. Сначала вызываются контроллеры, которые запускают просмотр.

Я попытался

$view = array (
       'available_services' => $available_services, 
       'available_providers' => $available_providers, 
       'company_name'   => $company_name, 
       'manage_mode'   => $manage_mode, 
       'appointment_data'  => $appointment, 
       'provider_data'   => $provider, 
       'customer_data'   => $customer, 
       'post_data'    => json_decode($_POST) 
      ); 

и передачи его для просмотра, но он не показывает вверх.

HTML код:

<form action="/appointment" method="POST" target="_blank"> 
      <div style="display:none!important;"> 
       <input type="text" placeholder="name" name="name" id="name" ng-model="cust.name"> 
       <input type="text" placeholder="email" name="email" id="email" ng-model="cust.email"> 
       <input type="text" placeholder="telephone" name="phone" id="phone" ng-model="cust.phone"> 
      </div> 

      <div class="text-center btn-toolbar" style="margin-top: 30px;"> 
       <button class="btn btn-primary" ng-click="cancel()" style="font-size: 20px;">OK</button> 
       <button type="submit" name="process" class="btn btn-success" style="font-size: 20px;">Schedule a Call</button> 
      </div> 
     </form> 

Controller Код:

public function index($appointment_hash = '') { 
    // echo $this->input->post('email'); 
    var_dump($_SERVER['REQUEST_METHOD']); 
    if (!$this->check_installation()) return; 

    $this->load->model('appointments_model'); 
    $this->load->model('providers_model'); 
    $this->load->model('services_model'); 
    $this->load->model('customers_model'); 
    $this->load->model('settings_model'); 

    if (strtoupper($_SERVER['REQUEST_METHOD']) !== 'POST') { 
     try { 
      $available_services = $this->services_model->get_available_services(); 
      $available_providers = $this->providers_model->get_available_providers(); 
      $company_name  = $this->settings_model->get_setting('company_name'); 

      // If an appointment hash is provided then it means that the customer 
      // is trying to edit a registered appointment record. 
      if ($appointment_hash !== ''){ 
       // Load the appointments data and enable the manage mode of the page. 
       $manage_mode = TRUE; 

       $results = $this->appointments_model->get_batch(array('hash' => $appointment_hash)); 

       if (count($results) === 0) { 
        // The requested appointment doesn't exist in the database. Display 
        // a message to the customer. 
        $view = array(
         'message_title' => $this->lang->line('appointment_not_found'), 
         'message_text' => $this->lang->line('appointment_does_not_exist_in_db'), 
         'message_icon' => $this->config->item('base_url') 
             . '/assets/img/error.png' 
        ); 
        $this->load->view('appointments/message', $view);       
        return; 
       } 

       $appointment = $results[0]; 
       $provider = $this->providers_model->get_row($appointment['id_users_provider']); 
       $customer = $this->customers_model->get_row($appointment['id_users_customer']); 

      } else { 
       // The customer is going to book a new appointment so there is no 
       // need for the manage functionality to be initialized. 
       $manage_mode  = FALSE; 
       $appointment = array(); 
       $provider  = array(); 
       $customer  = array(); 
      } 

      // Load the book appointment view. 
      $view = array (
       'available_services' => $available_services, 
       'available_providers' => $available_providers, 
       'company_name'   => $company_name, 
       'manage_mode'   => $manage_mode, 
       'appointment_data'  => $appointment, 
       'provider_data'   => $provider, 
       'customer_data'   => $customer, 
       'post_data'    => json_decode($_POST) 
      ); 

     } catch(Exception $exc) { 
      $view['exceptions'][] = $exc; 
     } 

     $this->load->view('appointments/book', $view); 

    } else { 
     // The page is a post-back. Register the appointment and send notification emails 
     // to the provider and the customer that are related to the appointment. If google 
     // sync is enabled then add the appointment to the provider's account. 

     try { 
      $post_data = json_decode($_POST['post_data'], true); 
      $appointment = $post_data['appointment']; 
      $customer = $post_data['customer']; 

      if ($this->customers_model->exists($customer)) 
        $customer['id'] = $this->customers_model->find_record_id($customer); 

      $customer_id = $this->customers_model->add($customer); 
      $appointment['id_users_customer'] = $customer_id; 

      $appointment['id'] = $this->appointments_model->add($appointment); 
      $appointment['hash'] = $this->appointments_model->get_value('hash', $appointment['id']); 

      $provider = $this->providers_model->get_row($appointment['id_users_provider']); 
      $service = $this->services_model->get_row($appointment['id_services']); 

      $company_settings = array( 
       'company_name' => $this->settings_model->get_setting('company_name'), 
       'company_link' => $this->settings_model->get_setting('company_link'), 
       'company_email' => $this->settings_model->get_setting('company_email') 
      ); 

      // :: SYNCHRONIZE APPOINTMENT WITH PROVIDER'S GOOGLE CALENDAR 
      // The provider must have previously granted access to his google calendar account 
      // in order to sync the appointment. 
      try { 
       $google_sync = $this->providers_model->get_setting('google_sync', 
         $appointment['id_users_provider']); 

       if ($google_sync == TRUE) { 
        $google_token = json_decode($this->providers_model 
          ->get_setting('google_token', $appointment['id_users_provider'])); 

        $this->load->library('google_sync'); 
        $this->google_sync->refresh_token($google_token->refresh_token); 

        if ($post_data['manage_mode'] === FALSE) { 
         // Add appointment to Google Calendar. 
         $google_event = $this->google_sync->add_appointment($appointment, $provider, 
           $service, $customer, $company_settings); 
         $appointment['id_google_calendar'] = $google_event->id; 
         $this->appointments_model->add($appointment); 
        } else { 
         // Update appointment to Google Calendar. 
         $appointment['id_google_calendar'] = $this->appointments_model 
           ->get_value('id_google_calendar', $appointment['id']); 

         $this->google_sync->update_appointment($appointment, $provider, 
           $service, $customer, $company_settings); 
        } 
       } 
      } catch(Exception $exc) { 
       $view['exceptions'][] = $exc; 
      } 

      // :: SEND NOTIFICATION EMAILS TO BOTH CUSTOMER AND PROVIDER 
      try { 
       $this->load->library('Notifications'); 

       $send_provider = $this->providers_model 
         ->get_setting('notifications', $provider['id']); 

       if (!$post_data['manage_mode']) { 
        $customer_title = $this->lang->line('appointment_booked'); 
        $customer_message = $this->lang->line('thank_you_for_appointment'); 
        $customer_link = $this->config->item('base_url') . '/index.php/appointments/index/' 
          . $appointment['hash']; 

        $provider_title = $this->lang->line('appointment_added_to_your_plan'); 
        $provider_message = $this->lang->line('appointment_link_description'); 
        $provider_link = $this->config->item('base_url') . '/index.php/backend/index/' 
          . $appointment['hash']; 
       } else { 
        $customer_title = $this->lang->line('appointment_changes_saved'); 
        $customer_message = ''; 
        $customer_link = $this->config->item('base_url') . '/index.php/appointments/index/' 
          . $appointment['hash']; 

        $provider_title = $this->lang->line('appointment_details_changed'); 
        $provider_message = ''; 
        $provider_link = $this->config->item('base_url') . '/index.php/backend/index/' 
          . $appointment['hash']; 
       } 

       $this->notifications->send_appointment_details($appointment, $provider, 
         $service, $customer,$company_settings, $customer_title, 
         $customer_message, $customer_link, $customer['email']); 

       if ($send_provider == TRUE) { 
        $this->notifications->send_appointment_details($appointment, $provider, 
          $service, $customer, $company_settings, $provider_title, 
          $provider_message, $provider_link, $provider['email']); 
       } 
      } catch(Exception $exc) { 
       $view['exceptions'][] = $exc; 
      } 

      // :: LOAD THE BOOK SUCCESS VIEW 
      $view = array(
       'appointment_data' => $appointment, 
       'provider_data'  => $provider, 
       'service_data'  => $service, 
       'company_name'  => $company_settings['company_name'] 
      ); 

     } catch(Exception $exc) { 
      $view['exceptions'][] = $exc; 
     } 

     $this->load->view('appointments/book_success', $view); 
    } 
} 
$this->load->view('appointments/book', $view); 

Чтобы быть более точным, этого приложение я пытаюсь подключиться к https://github.com/alextselegidis/easyappointments

Если корневая папка SRC является назначение, затем http://localhost/appointment принимает меня к назначению/приложению/просмотрам/встречам/book.php и назначению/приложению/контроллерам/meetingments.php

Посмотрите и предложите, что делать.

+1

где все эти переменные вы используете в этом массиве? нам нужно будет увидеть эту часть кода .... – Rooster

+0

Странно: когда я делаю var_dump ($ _ SERVER ['REQUEST_METHOD']); Я получаю «GET» на вид –

+0

@Rooster: отредактирован вопрос с кодом контроллера или см. Https://github.com/alextselegidis/easyappointments/blob/master/src/application/controllers/appointments.php –

ответ

0

У меня есть эта проблема тоже, вы должны добавить эту строку в коде:

$_POST = json_decode(file_get_contents("php://input"), true); 

, что позволит вам использовать JSON на код зажигательного поста так после этой строки вы можете сделать

$this->input->post('yourkey') 

, и вы получите то, что хотите :)

+0

Nope. Я получаю bool (false), когда я делаю $ _POST = json_decode (file_get_contents ("php: // input"), true); var_dump ($ this-> input-> post ('name')); –

+0

Почему -1? я просто пытаюсь помочь вам, у меня такая же проблема, вы обрабатываете данные json для конечной точки воспламенителя кода? pls Добавьте печать вашего $ _POST (var_dump ($ _ POST)), чтобы увидеть, что у вас есть –

+0

Я этого не делал. Сожалею. если это сделано. Я очень ценю вашу помощь и благодарность. Ваши предложения помогли продвинуться вперед и решить проблему. но мне не пришлось использовать $ _POST = json_decode (file_get_contents ("php: // input"), true); –

Смежные вопросы