0

I have this code for calling a form and than submit it..

<?php 
// hook_menu
function pricepackages_menu()
{
    $items = array();
    $items['membership/packages'] = array(
        'title' => t('Manage Membership Packages'),
        'page callback' => 'drupal_get_form',
        'page arguments' => array('pricepackages_form'),
       //'access callback' => TRUE,
       'access arguments' => array('access administration pages'),
    );
    return $items;
}
// FORM SHOW HOOK
function pricepackages_form($form, &$form_state)
{
    $form = array();

    $form['packagename'] = array(
        '#type' => 'textfield',
        '#title' => 'Package Name',
        //'attribute' => array('class' => 'package'),
        '#required' => TRUE,
    );
    $form['packageDescp'] = array(
        '#type' => 'textfield',
        '#title' => 'Package Short Description',
        //'attribute' => array('class' => 'package'),
        '#required' => FALSE,
    );
    $form['price'] = array(
        '#type' => 'textfield',
        '#title' => 'Package Price',
        //'attribute' => array('class' => 'package'),
        '#required' => TRUE,
    );
    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Submit'),
    );
    $form['submit'][] = array('package_get_form'=> array());

    return $form;
}

function package_get_form($form, &$form_state)
{
    drupal_set_message('working');
?>
    <script language="javascript">
        alert("aaa");
    </script>
<?php
return; 
    }
?>

but this one is not wokring proerly and form is not being submitted on the specific form... neither its showing alert or message...

please help me...

1

Change this:

$form['submit'][] = array('package_get_form'=> array());

to this:

$form['#submit'][] = 'package_get_form';

btw.

function package_get_form($form, &$form_state)
{
    drupal_set_message('working');
?>
    <script language="javascript">
        alert("aaa");
    </script>
<?php
return; 
}
?>

This looks really messy. Try that instead:

function package_get_form($form, &$form_state) {
  debug('test');
}

But the best option would be to use standard submit handler instead declaring your own name convention:

function pricepackages_form_submit($form, &$form_state) {
...
}
| improve this answer | |
0

You are missing the pound sign where you add the submit handler:

  $form['#submit'][] = 'package_get_form';

$form['#submit'] should be an linear array, and each value should be a valid function.

Submit handlers will get $form and $form_state as arguments in that order. If the submit handler is not included, you can run form_load_include to make sure the file is included before calling the submit handler.

Also, note that you can add an implicit submit handler if you define a function named pricepackages_form_submit.

| improve this answer | |

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.