0

I've created a custom module which creates a form and shows it in a block but whenever I submit it, it just refreshes the page and doesn't seem to execute the submit handler at all.

I'm going crazy trying to get this to work.

I've stripped the code right back but it's still not working.

<?php

// declare block info
function paypoint_block_info() {
    $blocks['paypoint_block'] = array(
        'info' => t('Paypoint Payment Form'), // block admin title
        'cache' => DRUPAL_NO_CACHE,
    );

    return $blocks;
}

// declare block functions
function paypoint_block_view($delta = '') {
    switch ($delta) {
        case 'paypoint_block':
            $block['content'] = drupal_get_form('paypoint_form');
            return $block;
            break;
    }

}

function paypoint_form($form, &$form_state) {
    $form['#attributes'] = array('class' => 'content-page-form');

    $form['strForename'] = array(
        '#type' => 'textfield', //you can find a list of available types in the form api
        '#title' => 'Forename',
        '#size' => 30,
        '#maxlength' => 37,
        '#required' => TRUE, //make this field required
    );

    $form['submit'] = array(
        '#type' => 'submit',
        '#value' => t('Make a payment'),
        '#attributes' => array('class' => array('btn', 'btn-default')),
    );

    return $form;
}

function paypoint_form_validate($form, &$form_state) {

}

function paypoint_form_submit($form, &$form_state) {
    drupal_set_message($form_state['values']['strForename']);
}

The validate function seems to get called, just not the submit one. I put print_r($form) in the validate function and got this: http://pastebin.com/Yt6T6Cr8

9
  • Is this code in the .module file?
    – Jaypan
    Commented Dec 20, 2016 at 13:30
  • Yes, paypoint.module. The form renders fine it just does nothing on submit
    – nexus_6
    Commented Dec 20, 2016 at 13:30
  • set brakepoint on submit function and tell if it jumps in there :)
    – kwoxer
    Commented Dec 20, 2016 at 13:51
  • 1
    @nexus_6 Have you tried adding a watchdog() to the submit handler? Then check the resent logged messages (/admin/reports/dblog) to make sure the function is not firing?
    – Jance
    Commented Dec 20, 2016 at 15:47
  • 1
    Also, have to just double check, have you cleared the site cache?
    – Jance
    Commented Dec 20, 2016 at 16:00

3 Answers 3

1

Your code looks fine to me. I think you might be on to something with your last comment, there might be something interfering with the hook.

One thing you might wanna do is run module_implements and look for the submit hook. That should give you a list of modules that implement that hook. At the very least you can check to see if there is anything strange going on with those modules.

0

Maybe, you need to point the submit handler in the form function clearly ?

$form['#submit'][] = 'paypoint_form_mysubmit';
1
  • That doesn't seem to have any effect, even if I do add that and change the the submit function name.
    – nexus_6
    Commented Dec 20, 2016 at 15:23
0

Just wanted to add that if you overload POST with too many form fields, exceeding your PHP max_post_size, PHP will purge POST. Since that includes submission information, no submission will occur. I had a custom form running in a loop off a database query. If it returns too many rows, the form is too large and cannot be submitted. Doesn't look like that was the problem in this case, but wanted to put it here since people searching for a solution may be running into this.

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.