forms - get checkbox group values -


this has driven me bananas. it's simple , easy , yet can't figure out what's wrong it.

i want checkbox value populated in controller (for testing purposes).

here form.

<a href='#' name='submitform'>submit form</a>    //i have jquery attached tag , submit form when user clicks  echo form_open('test/show');  echo form_checkbox('checkbox[]','value1'); echo form_checkbox('checkbox[]','value2'); echo form_checkbox('checkbox[]','value3'); echo form_checkbox('checkbox[]','value4');  echo "<input type='text' name='text1' value='ddd'>";  echo form_close();   //my controller test  public function show(){  $data1=$this->input->post('text1');   //i can text1 value input box  $data2=$this->input->post('checkbox');   //it keeps giving me undefined index 'checkbox'  $data3=$_post['checkbox']; //same error message //wth going on here!!!!!  } 

please help. thing drives me nuts! thanks.

update: help. more precisely, submit button <a> tag , outside of form tag. appear have include <a> tag inside form tag make them works. true?

a checkbox not submit data if unchecked they're not considered successful (as per w3c specification here)

if tick box , submit, it'll work - in fact does, i've tested it.

you need wrap calls $_post in isset() function.

if( isset( $_post['checkbox'] ) ) {} 

calling $this->input->post('checkbox') shouldn't give undefined index error method deals eventuality. input::post() method returns false or value of checkbox.

edit --

in response amendment question, must use element of type input type attribute set submit in order submit form data without use of javascript etc. button must inside <form></form> intending submit.

<input type="submit" value="submit"> 

the type="submit" causes browser send data submit event occurs. if wish use element insider or outside of form need use javascript. can disabled on per browser/user basis , isn't reliable result.

// standard javascript <form name="myform"... <a onclick="javascript:document.myform.submit();" href="javascript:void(0)">submit</a>  // jquery $('#my-a-tag-submit-button').live( 'click', function() {     $('#my-form').submit(); } 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -