Data in the Codeigniter Framework
I'm trying to create a Date field in the codeligniter for the user to inform the date, I created a helper file with the code for date (I actually used a code that was helpful to another question on this site), but I'm not being able to use. I have some doubts about the code, 1st after loading the helper in my controller I am loading the method created to format date in a variable in which I call it in the view, am I doing the right way? 2º when I perform test a date I typed in the form, I give a vardump to test what returns me, and returns NULL. 3º what is the syntax of the native function of codeigniter _parse_form_attribute, the codeigniter manual is out a few days and I'm not being able to continue my project.
//HELPER
if ( ! function_exists('form_common')){
function form_common($type = 'text', $data = '', $value = '', $extra = '')
{
$defaults = array('type' => $type, 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value);
return "<input "._parse_form_attributes($data, $defaults).$extra." />";
}
}
if ( ! function_exists('form_date')){
function form_date($data = '', $value = '', $extra = '')
{
return form_common($type = 'date', $data = '', $value = '', $extra = '');
}
}
//CONTROLLER REALIZEI TESTE PARA VER O QUE ESTA ME RETORNANDO APÓS DIGITAR A DATA E CLICAR NO BOTÃO, MAS O RESULTADO É NULL
if(isset($_POST['acao']) && $_POST['acao'] == 'Abrir Agenda >>'){
$data = $this->input->post('data');
echo 'A data Informada é '.$data;
var_dump($data);
}
//VIEW
echo form_date('data', 'data');
HOW DO I ADD A NAME TO THIS DATE FIELD AND CALL IT AGAIN TO ASSIGN ITS VALUE TO A VARIABLE.
1 answers
Look closely at your form_date function, when calling the form_common function vc is assigning values in the variables instead of passing the received values to the function, the correct form would be:
if ( ! function_exists('form_date')){
function form_date($data = '', $value = '', $extra = '')
{
return form_common('date', $data, $value, $extra);
}