Check Box

Hi All

I had working on some module which have some checkboxes, if some of them are selected i need their value and title in the mymodule_form_submit function.

Here is the code which i had written

function mymodule_form_submit($form_id, $form_values) {

where i need the value and title
}

function mymodule_form()
{
$sar = " some thing";
$sar1 = " some other thing";
$form['manfact_1'] = array(
'#type' => 'checkbox',
'#title' => $sar,
);
$form['manfact_2] = array(
'#type' => 'checkbox',
'#title' => $sar1,
);
}

if you could not got the problem currectly then please help me by giving sample code of checkbox with submit form or/and some tutorial or documentation on form checkbox

Comments

wla_g’s picture

The issue is quite simple, your checkbox must return something. Either do it by setting a return value or a default value (read the Forms API documentation).
Here is some code that worked for me:
in the form function:

  if($fe == $node->nid) $fe = 'firstitem';
  else $fe = '';

  $form['firstitem'] = array(
     '#title' => t('Topmost entry'),
     '#type' => 'checkbox',
    '#default_value' => $fe,
  );
.....

and in the submit function something like

  if ($form['#post']['firstitem'] == "firstitem") {
  >>here you have some handling<<
  }

Hope this is enough to clarify.

Regards
Werner

avinash kumar’s picture

Thanks for the reply, Yes i got the little bit idea, as i am using forms first time, i am not getting full flow on that, first i will explain my problem on which i am doing some experiments,

1. the full code

function somefunction()
{
$output .= mymodule_page();

return $output;

}

function mymodule_page() {
return drupal_get_form('mymodule_form');
}

function mymodule_form() {
$i = 0;
$queryStr = "SELECT distinct(user) FROM {usertable} WHERE categoryId ='4";
$result=db_query($queryStr);

while($tre=db_fetch_array($result)) {
$i++;
$form['manfact_'.$i] = array(
'#type' => 'checkbox',
'#title' => $sar,
'#default_value' => 'manfact_'.$i,
);

}

$form['submit'] = array('#type' => 'submit', '#value' => t('go'));
return $form;
}

This create 5 check boxes with thier title. upto this clear after that i want to submit the form only those value which are selected in below function.

function ajaxtable_docs_form_submit($form_id, $form_values) {
$q = $_GET['q'];
here i want the title of check box which are selected in a variable with '|' seperater .
return $q.'/'.'That variable is here'.
}

This is all about my main problem on which i am working.

2. As i started using drupal, i am facing problems on forms, it is because of less work on that, can you help me some issue i am facing like
a. how to have to different forms on single page,(i know hook_forms will do this)
b. how to have table with form in that (i know two solution, one is prefix and sefix having table and second is formtable module)
and so on .......

but i could not got simple example by seeing that i can manage to solve the problem my self.

for example i had problem on ajax, on the same time one of my forum friend like you give the site link and some of the easy understanding and working example on jquery, know i can handle that quite easly.

sorry for my more explaination, but i need good solution so i can solve problem my self.

avinash kumar’s picture

thanks wla_g,

From your previous reply i got the solution for my problem, for that i used both default value and return value. i will give full explaination on that after you give some hint on how to handle forms, and my another issue as i explained in previous comment how to use hook_forms and insert that form in a table row by row.