[eluser]jayrulez[/eluser]
[quote author="natsabari" date="1258152847"]thanks eoinmcg, for the fast reply :-) .
i cant load different view,i want to redirect the user to the same page with data he had added.
here is my controller
Code:
if($this->uri->segment(4) === 'Y'){
$argument = $this->input->post('argumentLeftText');
$url = $this->input->post('currUrlLeft');
}else{
$argument = $this->input->post(');
$url = $this->input->post(');
}
log_message('DEBUG','Adding new argument-->'.$argument.' side -->'.$this->uri->segment(4).' uri-->'.$this->uri->uri_string());
$debateArray=array(
'creater_id' =>$this->dx_auth->get_user_id(),
'debate_id' =>$this->uri->segment(3),
'side' => $this->uri->segment(4),
'type' => $this->uri->segment(6),
'argument' => $argument,
'parent_argument_id' => $this->uri->segment(5)
);
//print_r($debateArray);
if($this->debateDb->addArgument($debateArray)){
log_message('DEBUG','Going to redirect the page to -->'.$url);
redirect($url,'refresh');
}else{
echo 'some problem';
}
my view
Code:
<form name="rightForm" action="<?=base_url()?>debate/new_argument/<?=$debate->id?>/N/02/P" method="post">
<input type="hidden" value="<?php echo $this->uri->uri_string()?>" name="currUrlRight"/>
<textarea id="argumentRightText" name="argumentRightText" rows="5" cols="50" style="width: 100%;" >default</textarea><br/>
<div style="text-align: center"><input type="submit" value="Add" id="rightSubmitBtn" name="rightSubmitBtn" /></div>
</form>
Note:am new to PHP and codeigniter just 1 week before i started to learn PHP and codeigniter,so if some thing wrong in the code just indicate it.
Thanks in advance
nathan[/quote]
it's common practice to check for the presence of $_POST before saving data to the db. with php you can do it like this
Code:
if(isset($_POST)){ //process input and save to db... }else{ // render form }
. You can use the codeignitor equivalent to if(isset($_POST)) although using if(isset($_POST)) should work fine also.