gpt4 book ai didi

javascript - Codeigniter - 特定输入不按表单获取

转载 作者:行者123 更新时间:2023-12-03 06:43:24 24 4
gpt4 key购买 nike

我的 View 文件:new_request.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>New Request</title>
<script type="text/javascript">
window.onload = function() {
document.getElementById('ifYes').style.display = 'none';
document.getElementById('ifNo').style.display = 'none';
}
function yesnoCheck() {
if (document.getElementById('yesCheck').checked) {
document.getElementById('ifYes').style.display = 'block';
document.getElementById('ifNo').style.display = 'none';
}
else if(document.getElementById('noCheck').checked) {
document.getElementById('ifNo').style.display = 'block';
document.getElementById('ifYes').style.display = 'none';
}
}

</script>

</head>
<body>
<h3>Make a new Request!</h3>

<?php
echo form_open('requests/new_function');
echo validation_errors();
echo form_label('Service : ', 'service[]');
$options = array(
'facial' => 'Facial',
'threading' => 'Threading',
'spa' => 'Spa',
'service' => 'Service'
);
echo "<br>";
echo form_multiselect('service[]', $options);
echo "<br>";
echo form_label('Time(hh:mm:ss) : ', 'time');
echo form_input('time', '');
echo "<br>";
echo form_label('Date(dd-mm-yyyy) : ', 'date');
echo form_input('date', '');
echo "<br>";

echo form_label('Address : ', 'address');
?>
My Address
<input type="radio" onclick="javascript:yesnoCheck();" name="yesno" id="yesCheck"/>
New Address
<input type="radio" onclick="javascript:yesnoCheck();" name="yesno" id="noCheck"/>
<br>
<div id="ifYes" style="display:none">
<?php
echo form_label('Street : ', 'street');
echo form_input('street', $street);
echo "<br>";
echo form_label('City : ', 'city');
echo form_input('city', $city);
echo "<br>";
echo form_label('State : ', 'state');
echo form_input('state', $state);
echo "<br>";
echo form_label('PinCode : ', 'pincode');
echo form_input('pincode', $pincode);
echo "<br>";
?>
</div>

<div id="ifNo" style="display:none">
<?php
echo form_label('Street : ', 'street');
echo form_input('street', '');
echo "<br>";
echo form_label('City : ', 'city');
echo form_input('city', '');
echo "<br>";
echo form_label('State : ', 'state');
echo form_input('state', '');
echo "<br>";
echo form_label('PinCode : ', 'pincode');
echo form_input('pincode', '');
echo "<br>";
?>
</div>

<?php



echo "<br>";
//adding CAPTCHA
$random_number = substr(number_format(time() * rand(),0,'',''),0,6);
$vals = array(
'word' => $random_number,
'img_path' => './captcha/',
'img_url' => base_url().'captcha/',
'img_width' => 140,
'img_height' => 32,
'expiration' => 7200
);
$cap = create_captcha($vals);
echo $cap['image'];
?>
<br>
<?php
$this->session->set_userdata('captchaWord', $cap['word']);
echo form_label('Please fill in the string above : ', 'captcha');
echo form_input('captcha', '');
echo "<br>";
echo form_submit('submit-button-request', 'Submit Request');
echo form_close();
?>


</body>
</html>

问题是 $this->input->post('street') 和类似的 'city'、'state'、'pincode' 不起作用。它返回空字段。“ifYes”div 是从数据库中预先填充的。

这是 Controller 文件:Requests.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Requests extends CI_Controller {

public function new_req()
{
$this->load->model('model_users');
$object = $this->model_users->getRow($this->session->userdata('email'));
//var_dump($object);die();
$data['street'] = $object[0]->street;
$data['city'] = $object[0]->city;
$data['state'] = $object[0]->state;
$data['pincode'] = $object[0]->pincode;
$this->load->view('new_request', $data);
}

public function new_function()
{
$this->form_validation->set_rules('service[]', 'Service', 'required');
// $this->form_validation->set_rules('street', 'Street', 'required');
// $this->form_validation->set_rules('city', 'City', 'required');
// $this->form_validation->set_rules('state', 'State', 'required');
// $this->form_validation->set_rules('pincode', 'Pincode', 'required');
$this->form_validation->set_rules('time', 'Time', 'required|regex_match[/^[0-9]{2}:[0-9]{2}:[0-9]{2}$/]');
$this->form_validation->set_rules('date', 'Date', 'required|regex_match[/^[0-9]{2}-[0-9]{2}-[0-9]{4}$/]');
$this->form_validation->set_rules('captcha', 'Captcha', 'required|callback_checkCaptcha');
$date = $this->input->post('date');
$time = $this->input->post('time');
$date_time = nice_date($date, 'Y-m-d') . " " . $time;
$service = implode(',' , $this->input->post('service[]'));
$data = array(
'email_customer' => $this->session->userdata('email'),
'service' => $service,
'date_time' => $date_time,
'street' => $this->input->post('street'),
'city' => $this->input->post('city'),
'state' => $this->input->post('state'),
'pincode' => $this->input->post('pincode'),
);
$this->load->model('model_users');

if($this->form_validation->run() == FALSE)
{
$this->load->view('new_request');
}
else
{
$this->model_users->insert_request($data);
redirect('main/members');
}

}

public function old_req()
{

}

public function checkCaptcha($captcha)
{
if($this->session->userdata('captchaWord') == $captcha)
{
return true;
}
else
{
$this->form_validation->set_message('checkCaptcha', 'Please fill in the Captcha String Correctly!');
return false;
}
}

}

最佳答案

问题是您重复了字段名称。提交表单后,任何重复命名的字段中的最后一个字段将被发布。换句话说,只有“isNo”Div 被服务器接受并放入 $_POST 中。

解决方案是重命名一组字段或另一组字段,即在“isNo”div 中在所有字段名称前面加上“new_”,即 new_street、new_city 等。

关于javascript - Codeigniter - 特定输入不按表单获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37852984/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com