Tags down


associative array php

By : Ken Brown
Date : May 05 2020, 09:07 AM

I 'm trying to doing a back-end validation and I wonder if there is a better way to do this instead of typing all the variables of each data,

here's my code like :

  public function status_check()       
        $radioStatus = $this->input->post('radioStatus');

        $JuniorHS = array(    
            $SeniorHSGradeYear = $this->input->post('SeniorHSGradeYear'),
            $radioHSTracks = $this->input->post('radioHSTracks'),
            $radioCollegeCourses = $this->input->post('radioCollegeCourses'),
            $radioGraduateCourses = $this->input->post('$radioGraduateCourses'),
            $hsSchoolName = $this->input->post('$hsSchoolName'),
            $hsSchoolLocation = $this->input->post('$hsSchoolLocation'),
            $hsYearsAttended = $this->input->post('$hsYearsAttended'),
            $hsGradDate = $this->input->post('$hsGradDate'),
            $collegeSchoolName = $this->input->post('$collegeSchoolName'),
            $collegeSchoolLocation = $this->input->post('$collegeSchoolLocation'),
            $collegeYearsAttended = $this->input->post('$collegeYearsAttended'),
            $formerCollegeDegree = $this->input->post('$formerCollegeDegree'),
            $collegeGradDate = $this->input->post('$collegeGradDate'),

        if  ($radioStatus == "JuniorHS")
            if (!empty($JuniorHS))
                $this->form_validation->set_message('status_check', 'Please check the information you provided');
                return false;
        return true;

I put all the variables inside an array and i want to check if any of it has a value, if the array is not empty then it will return as false, hence if its empty then it will return true, but the code always return as false even if its empty, am i even doing it right?

Answer :

I was reading that:

Since CI 2.1.0, you can now do the following easy way to get all post data from the form.

$data = $this->input->post(NULL, TRUE); // returns all POST items with XSS filter
$data = $this->input->post(); // returns all POST items without XSS filter 

So, I think this code could work for you:

public function status_check() { $data = $this->input->post(); foreach ($data as $key => $value) { if ($key == 'radioStatus') { $radioStatus = $value; }else{ $JuniorHS[] = $value; } } if ($radioStatus == "JuniorHS") { foreach ($JuniorHS as $key => $value) { if (!empty($value)) { $this->form_validation->set_message('status_check', 'Please check the information you provided'); return false; } } } return true; }

Share : facebook icon twitter icon
Related Posts Related Posts :
  • clear array after form submit
  • pass url variable to javascript
  • access data using api
  • div position fixed css
  • add horizontal line between two div
  • disable toggle button css
  • css fixed line height
  • background image not working
  • table cell border
  • text line break css
  • overlay div on div
  • text direction rtl css
  • javascript convert string to an object
  • bind inner div click to outer div
  • jquery ajax oncomplete
  • how to use promise in for loop
  • jquery get element using variable
  • javascript send textbox value
  • pass div class content to another class or id
  • css new line after element
  • css calc not working properly
  • link disabled jquery
  • sql join table to subquery
  • MS Access SQL Issue with OR AND Operators
  • set textarea value using php
  • php merge two arrays into one
  • php form with google captcha
  • update current row in php
  • php date format mysql
  • mysql pdo select query
  • php function return an array
  • PHP mysqldump database to sql file
  • display image query
  • php create array using foreach loop
  • group_concat in mysql laravel
  • php array_push empty
  • mysql on update cascade not working
  • pdo insert prepared statement
  • mysql insert ignore vs on duplicate key
  • mysql insert into existing row
  • mysql multi insert query
  • mysql group by show all rows
  • php change profile image
  • combine multiple arrays into one array php
  • how to sum values in an array
  • how to get sum of the total time
  • How to Create Facebook live stream without notification using API ?
  • on button click make div visible
  • css affect another element on hover
  • insert line after paragraph word
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org