У меня есть форма, в которой есть 4 типа разделов (текст, контакт, портфолио, отзыв). У меня есть одна кнопка, чтобы добавить новый раздел (ДОБАВИТЬ РАЗДЕЛ).При нажатии открывается всплывающее окно для выбора типа раздела (текст, контакт, портфолио, отзыв). Я не знаю, как мне обработать запрос на публикацию этой формы
Я попытался зациклить массив разделов, но если у меня естьраздел с двумя типами текста и всего 5 разделов, а затем для текстового раздела выводится сообщение об ошибке с ошибкой.
<code>if(isset($_FILES["content"]) || isset($_POST["content"])){
$errors = 0 ;
$this->load->library("form_validation");
$this->form_validation->set_rules("title[]", "Title", "trim|callback_validate_input");
$this->form_validation->set_rules("tagline[]", "Tagline", "trim|callback_validate_input");
for ($i=0; $i < count($_POST["section_type"]); $i++) {
if($_POST["section_type"][$i] == "testimonial"){
$this->form_validation->set_rules("content[testi_name][]", "Testimonial Name", "trim");
$this->form_validation->set_rules("content[testi_heading][]", "Testimonial Heading", "trim");
$this->form_validation->set_rules("content[testi_content][]", "Testimonial", "trim");
}else{
$this->form_validation->set_rules("content[]", "Text Content", "trim|callback_validate_input");
}
}
$this->form_validation->set_rules("status[]", "Status", "trim|required");
$this->form_validation->set_rules("section_type[]", "Section Type", "trim|required");
$this->form_validation->set_rules("section_ids", "Sections IDs", "trim|required");
$this->form_validation->set_rules("priority", "Priority", "trim|required");
$this->form_validation->set_rules("user_id", "User ID", "trim|required|is_natural");
if($this->form_validation->run() == FALSE){
$errors = 1 ;
$response["message"] .= validation_errors("<p class='text-danger'>", "<p><br>");
}
if(isset($_FILES["content"])){
$allowed_types = array("image/png", "image/jpg", "image/gif", "image/jpeg");
$max_size = 153600;
if(isset($_FILES["content"]["name"]["portfolio"])){
//validate portfolio images
$portfolio_path = "./assets/images/portfolio/";
for($b = 0; $b < count($_FILES["content"]["name"]["portfolio"]); $b++){
$file_name = $_FILES["content"]["name"]["portfolio"][$b];
$type = $_FILES["content"]["type"]["portfolio"][$b];
$tmp = $_FILES["content"]["tmp_name"]["portfolio"][$b];
$size = $_FILES["content"]["size"]["portfolio"][$b];
if(!empty($file_name)){
if(!in_array($type, $allowed_types)){
$errors = 1 ;
$response["message"] .= "<p class='text-danger'> ".$file_name ." is not a valid image for portfolio.<p><br>";
}else if($size > $max_size){
$errors = 1 ;
$response["message"] .= "<p class='text-danger'> ".$file_name ." is lager than allowed upload size(150 kb).<p><br>";
}else if(!move_uploaded_file($tmp, $portfolio_path."$file_name")){
$errors = 1 ;
$response["message"] .= "<p class='text-danger'> ".$file_name ." could not be uploaded.<p><br>";
}
}
}
}
if(isset($_FILES["content"]["name"]["testi_img"])){
//validate testimonial images
$portfolio_path = "./assets/images/testimonial/";
for($a = 0; $a < count($_FILES["content"]["name"]["testi_img"]); $a++){
$file_name = $_FILES["content"]["name"]["testi_img"][$a];
$type = $_FILES["content"]["type"]["testi_img"][$a];
$tmp = $_FILES["content"]["tmp_name"]["testi_img"][$a];
$size = $_FILES["content"]["size"]["testi_img"][$a];
if(!empty($file_name)){
if(!in_array($type, $allowed_types)){
$errors = 1 ;
$response["message"] .= "<p class='text-danger'> ".$file_name ." is not a valid image for testimonial.<p><br>";
}else if($size > $max_size){
$errors = 1 ;
$response["message"] .= "<p class='text-danger'> ".$file_name ." is lager than allowed upload size(150 kb).<p><br>";
}else if(!move_uploaded_file($tmp, $portfolio_path."$file_name")){
$errors = 1 ;
$response["message"] .= "<p class='text-danger'> ".$file_name ." could not be uploaded.<p><br>";
}
}
}
}
}
if($errors === 0){
$section_ids = explode(",", $_POST["section_ids"]);
//update / add new sections
$this->load->model("sections_model");
$output = array();
for ($i=0; $i < count($_POST["section_type"]); $i++) {
$user_id = $_POST["user_id"] ;
$section_id = $section_ids[$i];
$priority = $i;
$title = $_POST["title"][$i] ;
$tagline = $_POST["tagline"][$i] ;
$status = $_POST["status"][$i] ;
$section_type = $_POST["section_type"][$i] ;
$section = array(
"section_id" => $section_id,
"user_id" => $user_id,
"section_name" => $title,
"section_tagline" => $tagline,
"section_priority" => $priority,
"section_type" => $section_type,
"status" => $status,
);
if($section_type == "portfolio"){
foreach ($_FILES["content"]["name"]["portfolio"] as $portfolio) {
$section["section_content"][] = $portfolio ;
}
}else if($section_type == "testimonial"){
$count = 0 ;
foreach ($_FILES["content"]["name"]["testi_img"] as $testi_image) {
$section["section_content"][$count] = array(
"image" => $testi_image,
"name" => $_POST["content"]["testi_name"][$count],
"heading" => $_POST["content"]["testi_heading"][$count],
"content" => $_POST["content"]["testi_content"][$count]
);
$count++;
}
}else {
$section["section_content"] = $_POST["content"][$i];
}
$check_section = $this->sections_model->select_all(array(
"where" => array(
"section_id" => $section_id,
"user_id" => $user_id
)
));
$output[$i] = $section;
// if($check_section->num_rows()>0){
// //update query
// if($this->sections_model->update_row(array(
// "section_id" => $section_id,
// "user_id" => $user_id
// ), $section)){
// $response["message"] = "<p class='text-success'>Section Updated Successfully.</p>";
// }else{
// $response["message"] = "<p class='text-danger'>Unknown Error! Try Again Later.</p>";
// }
// }else{
// //insert query
// if($this->sections_model->insert_row($section)){
// $response["message"] = "<p class='text-success'>Section Added Successfully.</p>";
// }else{
// $response["message"] = "<p class='text-danger'>Unknown Error! Try Again Later.</p>";
// }
// }
}
echo "<pre>";
print_r($output);
echo "
";}} else {$ response [" message "]. ="прямой сценарий не разрешен
";}
// это то, что я получил взамен
Обнаружена ошибка PHP. Серьезность: Уведомление
Сообщение: неопределенное смещение: 3
Имя файла: admin / Users.php
Номер строки: 642
Backtrace:
Файл: E: \ VIKASH \ xampp \ htdocs \ zrurt \ application \ controllers \ admin \ Users.php Строка: 642 Функция: _error_handler
Файл: E: \ VIKASH \ xampp \ htdocs \ zrurt \ index.php Строка: 315Функция: require_once
Обнаружена ошибка PHP. Серьезность: Уведомление
Сообщение: неопределенное смещение: 4
Имя файла: admin / Users.php
Номер строки: 642
Backtrace:
Файл: E: \ VIKASH \ xampp \ htdocs \ zrurt \ application \ controllers \ admin \ Users.php Строка: 642 Функция: _error_handler
Файл: E: \ VIKASH \ xampp \ htdocs \ zrurt \ index.php Строка: 315 Функция: require_once
Array
(
[0] => Array
(
[section_id] => 18
[user_id] => 31
[section_name] => portfolio
[section_tagline] => portfolio tagline
[section_priority] => 0
[section_type] => portfolio
[status] => active
[section_content] => Array
(
[0] => user6.png
[1] => user7.png
[2] => user8.png
)
)
[1] => Array
(
[section_id] => 19
[user_id] => 31
[section_name] => testimoinial
[section_tagline] => testimonial tagline
[section_priority] => 1
[section_type] => testimonial
[status] => active
[section_content] => Array
(
[0] => Array
(
[image] => user1.png
[name] => user 1
[heading] => heading one
[content] => testimonial one.
)
[1] => Array
(
[image] => user2.PNG
[name] => user 2
[heading] => user two
[content] => testimonial two.
)
)
)
[2] => Array
(
[section_id] => 20
[user_id] => 31
[section_name] => about us
[section_tagline] => about tagline
[section_priority] => 2
[section_type] => text
[status] => active
[section_content] => contact section. contact section. contact section. contact section. contact section. contact section. contact section. contact section. contact section. contact section. contact section. contact section. contact section. contact section. contact section. contact section. contact section. contact section. contact section.
)
[3] => Array
(
[section_id] => 21
[user_id] => 31
[section_name] => contact us
[section_tagline] => contact tagline
[section_priority] => 3
[section_type] => text
[status] => active
[section_content] =>
)
[4] => Array
(
[section_id] => 22
[user_id] => 31
[section_name] => contact us
[section_tagline] => contact tagline
[section_priority] => 4
[section_type] => contact
[status] => active
[section_content] =>
)
)
Я хочу проверить все поля и сохранить их в базе данных.