database - 如何将表单数据发布到 aspx url 并将其保存到 codeigniter 中的数据库
问题描述
大家好,希望大家身体健康。
我正在尝试将发布数据从控制器发送到作为 API 链接的 .aspx 链接,但我也在尝试将一些字段数据保存到数据库中,但我在实现这一目标时遇到了一些问题。希望有人可以指导/帮助我做到这一点。
这是我在视图文件中的表格
<div class="row">
<div class="span6">
<input type="hidden" id="order_id" name="order_id" value="<?php echo $order_id ?>">
<input type="hidden" id="order_expiry_date_time" name="order_expiry_date_time"
value="<?php echo $expiry_date ?>">
<?php $error = form_error("customer_name", '<p class="text-error">', "</p>"); ?>
<div class="form-group <?php echo $error ? 'has-error' : '' ?> row">
<label for="customer_name" class="span3">Your Name:</label>
<div class="span8">
<input type="text" name="customer_name" id="customer_name"
value="<?php echo isset($row->customer_name) ? $row->customer_name : ''; ?>"
class="form-control">
<?php echo $error; ?>
</div>
</div>
<?php $error = form_error("customer_email", '<p class="text-error">', "</p>"); ?>
<div class="form-group <?php echo $error ? 'has-error' : '' ?> row">
<label for="customer_email" class="span3">Email:</label>
<div class="span8">
<input type="text" name="customer_email" id="customer_email"
value="<?php echo isset($row->customer_email) ? $row->customer_email : ''; ?>"
class="form-control">
<?php echo $error; ?>
</div>
</div>
<?php $error = form_error("customer_mobile", '<p class="text-error">', "</p>"); ?>
<div class="form-group <?php echo $error ? 'has-error' : '' ?> row">
<label for="customer_mobile" class="span3">Phone Number:</label>
<div class="span8">
<input type="text" name="customer_mobile" id="customer_mobile"
value="<?php echo isset($row->customer_mobile) ? $row->customer_mobile : ''; ?>"
class="form-control">
<?php echo $error; ?>
</div>
</div>
<?php $error = form_error("order_amount", '<p class="text-error">', "</p>"); ?>
<div class="form-group <?php echo $error ? 'has-error' : '' ?> row">
<label for="order_amount" class="span3">Amount:</label>
<div class="span8">
<input type="text" name="order_amount" id="order_amount"
value="<?php echo isset($row->order_amount) ? $row->order_amount : ''; ?>"
class="form-control">
<?php echo $error; ?>
</div>
</div>
<?php $error = form_error("product_description", '<p class="text-error">', "</p>"); ?>
<div class="form-group <?php echo $error ? 'has-error' : '' ?> row">
<label for="product_description" class="span3">Reaon of Donation:</label>
<div class="span8">
<textarea name="product_description" class="form-control"
id="product_description">
<?php if (isset($row->product_description)) {
echo $row->product_description;
} ?>
</textarea>
<?php echo $error; ?>
</div>
</div>
<input type="hidden" id="return_url" name="return_url"
value="<?php echo base_url('thank-you'); ?>">
<input type="hidden" id="status" name="status" value="0">
<div class="align-right">
<div class="form-group">
<div class="span7 submit">
<input type="submit" value="Proceed to Pay" id="btnSubmit"
class="cta btn btn-primary">
</div>
</div>
</div>
</div>
我的模型文件代码将数据保存到数据库中
function saveDonation($slug = null) {
if (!$slug) {
$url_slug = $this->generate_url_slug($this->input->post('customer_name'), 'donations');
$post['customer_name'] = $this->input->post("customer_name");
$post['customer_email'] = $this->input->post("customer_email");
$post['customer_mobile'] = $this->input->post("customer_mobile");
$post['order_amount'] = $this->input->post("order_amount");
$post['product_description'] = $this->input->post("product_description");
$post['order_id'] = $this->input->post("order_id");
$post['slug'] = $url_slug;
$this->db->insert($this->table, $post);
return $this->db->insert_id();
}
}
我的控制器代码
public function index() {
$this->load->view('template/header');
$this->load->view('template/nav');
$this->form_validation->set_rules("customer_name", "Your Name", "trim|required");
$this->form_validation->set_rules("customer_email", "Email", "trim|required|valid_email");
$this->form_validation->set_rules("customer_mobile", "Phone Number", "required");
$this->form_validation->set_rules("order_amount", "Amount", "required|regex_match[/^[0-9]+(\.[0-9]{0,2})?$/]");
$ClientID = '123456789';
$ClientSecret = '987654321';
$customer_name = $this->input->post('customer_name');
$customer_email = $this->input->post('customer_email');
$customer_mobile = $this->input->post('customer_mobile');
$order_amount = $this->input->post('order_amount');
$product_description = $this->input->post('product_description');
$this->load->helper('string');
$order_id = random_string('numeric', 12) . '-' . random_string('numeric', 2);
$payment_via = 'ONLINE_PAYMENT';
$order_expiry_date_time = date('Y-m-d');
$return_url = base_url('thank-you');
$query = '' . $ClientID . '' . $order_id . '' . $return_url . '' . $ClientSecret . '';
$hashed_query = hash('sha256', $query);
$str = md5($hashed_query, FALSE);
$formdata = 'payment_via=' . $payment_via . '&client_id=' . $ClientID . '&order_id=' . $order_id . '&order_amount=' . $order_amount . '.00&customer_name=' . $customer_name . '&customer_email=' . $customer_email . '&customer_mobile=' . $customer_mobile . '&product_description=' . $product_description . '&order_expiry_date_time=' . $order_expiry_date_time . '&encrypted_form_data=' . $str . '&return_url=' . $return_url . '';
if ($this->form_validation->run() == true) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'domain.com/Payment/PaymentProcess.aspx',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $formdata,
CURLOPT_HTTPHEADER => array(
'Referer: http://localhost',
'Content-Type: application/x-www-form-urlencoded'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
if ($response) {
$this->Model->saveDonation();
} else {
$this->session->set_flashdata("error", "Something goes wrong! Please try again later.");
redirect(base_url());
}
}
$data['order_id'] = $order_id;
$data['expiry_date'] = $order_expiry_date_time;
$this->load->view('welcome_message', $data);
$this->load->view('template/footer');
}
但它根本不起作用。有人可以指导/帮助我做错了什么或如何使它工作。
先感谢您。
解决方案
推荐阅读
- c# - 获得答案后,不再为用户分配相同的问题
- sql-server - 使用键/值结构修改 XML 的一部分
- callback - Bokeh + Jupyter - 如何在同一个 JS 回调中更新两个字形和图形
- sublimetext3 - Sublime Text 3 - 具有 csv 范围的片段?
- python - 如何使用 TF-IDF 训练 xgboost
- powershell - 如何更改 powershell 终端颜色或完全关闭颜色编码
- javascript - 通过数组 JavaScript 中的对象字段移动对象
- python-3.x - 对具有类属性的值执行操作
- c# - 我的代码没有根据从组合框 c# 中的选择切换到所需的功能
- python-3.x - 使用按位函数,然后尝试进行二进制补码但没有成功