我正在尝试将名称,电子邮件等表单数据从简单的html页面传递到CodeIgniter应用程序。 Direcotry Structute: SampleDir
我正在尝试传递表单(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>
控制器代码:
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
的应用如果root src文件夹是约会的,那么http://localhost/appointment将我带到约会/ application / views / appointmentments / book.php和appointment / application / controllers / appointmentments.php
看看并建议做什么。
答案 0 :(得分:0)
我也有这个问题,你必须在你的代码上添加这一行:
$_POST = json_decode(file_get_contents("php://input"), true);
这会让你在代码点火器帖子上使用json,所以在那行之后你可以做
$this->input->post('yourkey')
你会得到你想要的东西:)