0

Just newly working on Drupal 7. Using Form API I created a text field with one submit button. I need to pass the text field's value in the select query as a parameter. I need to output the result set of the select query in table layout. Please help me out by providing a set of codes.

1

This is actually very easily done out of the box with form-api, you just have to know how to use it. You have to read up on drupal 7 forms, especially the validate and submit functions/hooks. A quick and dirty example to output form values in submit function (called after function form_*_validate() hook) is shown below.

function form_example_tutorial_7_submit($form, &$form_state) {
  drupal_set_message(t('The form has been submitted. name="@first @last", year of birth=@year_of_birth', 
    array('@first' => $form_state['values']['first'], '@last' => $form_state['values']['last'], '@year_of_birth' => $form_state['values']['year_of_birth'])));
}

Of course, you can also show messages like this in the validation step. You would need to change above code to use whatever variables you want shown.

Tons of very helpful form api code examples here.

If videos are more your thing, these explains the basic basics ok.

Cheers!

  • Hi, thanks for your information. But i needs to display the "select" query data in the form by hitting "submit" action.For example: select firstname,designation from emptable where code='txtboxvalue' (passing parameter). the result set of this should gets displayed into my form. How can i do this ? thanks – jacksantho Apr 18 '12 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.