1

Could anyone please point out where I might be doing something wrong? I can't seem to capture the form values to manipulate them when this form is submitted.

   function admin_score_table_block_view($delta = '') {
      //The $delta parameter tells us which block is being requested.
        switch ($delta) {
            case 'admin_score_table':

                $block['subject'] = t('Admin Editable Score Table');
                $block['content'] = '';
                global $user;

            $form = drupal_get_form('admin_scores');

            $block['content'] = $form;

        break;
    }
    return $block;
}


function admin_scores($form) {
  if ($node = menu_get_object()) {
        $node = node_load($nid = $node->nid);

        $programmetmp = $node->field_sportevent_cd;
        $programme = $programmetmp['und'][0];
    }

    $form['#tree'] = 1;

    $result = db_query("SELECT cdt.entity_id AS nid FROM field_data_field_team_corpdec AS cdt WHERE cdt.field_team_corpdec_nid = " . $programme['nid']);
    foreach($result as $row){
        $team = node_load($row->nid);

        $form[$team->nid]['nid'] = array(
            '#type' => 'hidden',
            '#value' => $team->nid,
        );
        $form[$team->nid]['team'] = array(
            '#type' => 'textfield',
            '#value' => $team->title,
            '#title' => 'Team',
            '#attributes' => array('class' => 'field-team'),
            '#name' => 'team[' . $team->nid . ']'
        );
        $form[$team->nid]['score'] = array(
            '#type' => 'textfield',
            '#value' => '',
            '#title' => 'Score',
            '#attributes' => array('class' => 'field-score'),
            '#name' => 'score[' . $team->nid . ']'
        );
    }

    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => 'Save scores',
    );

    return $form;
}


function admin_scores_form_submit($form, &$form_state){
    var_dump($form_id);

}
4
  • 2
    try var_dump($form_state["values"]); Feb 6, 2012 at 9:49
  • 3
    off topic: in D7 you should use the new db layer. Read this for more info. Feb 6, 2012 at 9:50
  • 3
    or at least you could use the placeholders: db_query("SELECT cdt.entity_id AS nid FROM field_data_field_team_corpdec AS cdt WHERE cdt.field_team_corpdec_nid = :nid", array(":nid" => $programme['nid'])); Feb 6, 2012 at 9:52
  • 2
    I agree with @MariusIlie. It's bad form to inject dynamic values into a SQL query, as it could lead to SQL injection.
    – apaderno
    Feb 6, 2012 at 15:30

1 Answer 1

2

Your form is called admin_scores() but your submit function is called admin_scores_form_submit()...this isn't Drupal's naming convention so your submit handler will never be executed.

Either change the name of your submit handler:

function admin_scores_submit($form, &$form_state) {

}

Or add your non-standard submit handler in the form itself:

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

Also the signature you're using for your form function is slightly wrong, in Drupal 7 it's like this:

function admin_scores($form, &$form_state) {
1
  • was facing a similar problem, this helped. does our new submit handler override the normal submit procedures ? and how can we make sure that our code in the submit handler is executed last of all the other normal submit procedures defined for that node ? eg I want the article to be added into the DBS and then only run my custom code in the submit handler.
    – geeky_bat
    Aug 12, 2012 at 14:24

Your Answer

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

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