complex form help - El Forum - 01-12-2010
[eluser]dadamssg[/eluser]
can you not define a function in a controller and then use it in another function?? im trying validate a script that uses dates and its saying that im calling an undefined end_timestamp(). Im trying to use my function end_timestamp() in my hasnt_ended() function
Code: function create()
{
if($this->session->userdata('logname')){}else
{
redirect('mains');
}
$data['notifications'] = $this->Loginmodel->get_notifications();
$data['messages'] = $this->Loginmodel->get_messages();
$data['title'] = "Publish Event";
$this->load->view('header_view', $data);
#####decide which views to load###################
if($this->session->userdata('logname') == "")
{
$this->load->view('login_view', $data);
}
else
{
$this->load->view('logged_view', $data);
}
$this->load->helper('url');
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_rules('title', 'Title', 'trim|required');
$this->form_validation->set_rules('location', 'Location', 'trim|required');
$this->form_validation->set_rules('description', 'Description', 'trim|required');
$this->form_validation->set_rules('smonth', 'Smonth', 'callback_start_date');
$this->form_validation->set_rules('emonth', 'Emonth', 'callback_end_date|callback_hasnt_ended');
$this->form_validation->set_error_delimiters('<h5>', '</h5>');
if ($this->form_validation->run() == TRUE)
{
$this->load->view('main_view');
}
else
{
$this->load->view('create_event');
}
$this->load->view('footer_view');
}
function end_date()
{
if(checkdate($_POST['emonth'], $_POST['eday'], $_POST['eyear']))
{
return TRUE;
}else
{
$this->form_validation->set_message('end_date', "Your end date doesn't exists.");
return FALSE;
}
}
function start_date()
{
if(checkdate($_POST['smonth'], $_POST['sday'], $_POST['syear']))
{
return TRUE;
}else
{
$this->form_validation->set_message('start_date', "Your start date doesn't exists.");
return FALSE;
}
}
function start_timestamp()
{
if($_POST['sampm'] == "pm")
{
$sh = $_POST['shour'] + 12;
$start = mktime($sh,$_POST['sminute'],0, $_POST['smonth'], $_POST['sday'], $_POST['syear']);
return $start;
}
else
{
$start = mktime($_POST['shour'],$_POST['sminute'],0, $_POST['smonth'], $_POST['sday'], $_POST['syear']);
return $start;
}
}
function end_timestamp()
{
if($_POST['eampm'] == "pm")
{
$sh = $_POST['ehour'] + 12;
$end = mktime($sh,$_POST['eminute'],0, $_POST['emonth'], $_POST['eday'], $_POST['eyear']);
return $end;
}
else
{
$end = mktime($_POST['ehour'],$_POST['eminute'],0, $_POST['emonth'], $_POST['eday'], $_POST['eyear']);
return $end;
}
}
function hasnt_ended()
{
$hr = (int) date("H")+5;
$mi = (int) date("i");
$mo = (int) date("n");
$da = (int) date("j");
$yr = (int) date("Y");
$now = gmmktime( $hr,$mi,0,$mo,$da,$yr);
$end = end_timestamp();
if($end > $now)
{
return TRUE;
}else
{
$this->form_validation->set_message('hasnt_ended', "Your event has already ended.");
return FALSE;
}
}
complex form help - El Forum - 01-12-2010
[eluser]helmutbjorg[/eluser]
You need to refer to your function in the scope of the controller.
Change
Code: $end = end_timestamp();
To
Code: $end = $this->end_timestamp();
complex form help - El Forum - 01-12-2010
[eluser]dadamssg[/eluser]
hmm alright. I ended up doing this and its almost working....i think. I get this error
Message: Undefined index: sradio
Filename: controllers/event.php
Line Number: 132
this is line 132
Code: if($_POST['sradio'] == "pm")
and heres where i use it in my view
Code: $sradioam = array( 'name' => 'sradio',
'value'=> 'am' );
echo form_radio($sradioam)." am ";
$sradiopm = array( 'name' => 'sradio',
'value'=> 'pm' );
echo form_radio($sradiopm)." pm <br><br>";
its not wanting to recognize my radio button as inputs..?????
complex form help - El Forum - 01-12-2010
[eluser]dadamssg[/eluser]
forgot to show you the whole funcion
Code: function check_everything()
{
if($_POST['sradio'] == "pm")
{
$sh = $_POST['shour'] + 12;
$start = mktime($sh,$_POST['smin'],0, $_POST['smonth'], $_POST['sday'], $_POST['syear']);
}else{
$start = mktime($_POST['shour'],$_POST['smin'],0, $_POST['smonth'], $_POST['sday'], $_POST['syear']);
}
if($_POST['eradio'] == "pm")
{
$sh = $_POST['ehour'] + 12;
$end = mktime($sh,$_POST['emin'],0, $_POST['emonth'], $_POST['eday'], $_POST['eyear']);
}else{
$end = mktime($_POST['ehour'],$_POST['emin'],0, $_POST['emonth'], $_POST['eday'], $_POST['eyear']);
}
$hr = (int) date("H")+5;
$mi = (int) date("i");
$mo = (int) date("n");
$da = (int) date("j");
$yr = (int) date("Y");
$now = gmmktime( $hr,$mi,0,$mo,$da,$yr);
if($end < $now)
{
$this->form_validation->set_message('check_everything', "Your event already ended.");
return FALSE;
}
elseif($start < $end)
{
$this->form_validation->set_message('check_everything', "Your event ends before it starts.");
return FALSE;
}
else
{
return TRUE;
}
}
complex form help - El Forum - 01-12-2010
[eluser]Colin Williams[/eluser]
Use $this->input->post()
And brush up on your PHP. And read the whole User Guide, two or three times until it sinks in.
Stuff like this
Code: if($this->session->userdata('logname')){}else
{
redirect('mains');
}
It's downright silly.
complex form help - El Forum - 01-12-2010
[eluser]helmutbjorg[/eluser]
hahaha
complex form help - El Forum - 01-12-2010
[eluser]dadamssg[/eluser]
haha sorry. I keep forgetting the new way to use posts.
complex form help - El Forum - 01-12-2010
[eluser]Colin Williams[/eluser]
Also, pay attention to the errors PHP gives you. "Undefined index in array", "Call to a member function on a non-object", etc., these are all very specific and usually answer the problem you are having. When you actually know what an array index is, and what a member function is, things are pretty clear. It's how the rest of us get along without jumping into the forums every time PHP throws us an error message.
|