1

i want to put two button in my view.and two button send value to one controller. how to check which button press?! according this link Link

but in controller not get value of button.any idea?

asked Jan 26, 2017 at 19:18
1
  • Not an expert but if you want to identify that which button is pressed then you can give that button name and get that name in the input post array. Commented Jan 27, 2017 at 3:37

2 Answers 2

3

Use the same approach, however in CodeIgniter your code will look a bit clearer :

<form action="TheController/PostHandler" method="POST">
 <input type="submit" name="button1" id="button1" value="Button 1" />
 <input type="submit" name="button2" id="button2" value="Button 2" />
</form>

Because in CodeIgniter, this is :

$something = $this->input->post('something');

equivalent to :

$something = isset($_POST['something']) ? $_POST['something'] : NULL;

Simply check for null values with a code like this :

public function PostHandler(){
 if (!is_null($this->input->post('button1'))){
 // code for button 1
 }
 if (!is_null($this->input->post('button2'))){
 // code for button 2
 }
}
answered Jan 26, 2017 at 19:31
Sign up to request clarification or add additional context in comments.

3 Comments

i put only this code "if (!is_null($this->input->post('button1'))){}". but i press button 2 this works.i really confuse.sorry
yes, I had a type under button 2 name, just fixed it
1
$this->input->post('some_data'); // The function returns FALSE (boolean) if some_data not isset

Use

if($this->input->post('button1')){
$button1 = $this->input->post('some_data',true) //for xss
} else { $bouton1 = false;} 
answered Jan 27, 2017 at 6:56

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.