0

I am adding content to my page using file_get_contents (I'm rendering the content to strip all template html as in this example: https://stackoverflow.com/questions/247991/displaying-a-drupal-view-without-a-page-template-around-it).

Some of the pages have forms which should be submitted normally, as in the page should be validated and redirected after submission. However submission is not working. For example, if the page is at http://mysite.com/myform and pressing the cancel button should call myform_cancel() and redirect me to http://mysite.com/, I instead get redirected to http://mysite.com/myform?response_type=embed and no submit methods are called.

What do I need to so to make my form submit as expected?

Edit:
A similar thing happens when I instead render the form using menu_get_item to get the callback and arguments, then render the html using: drupal_render(call_user_func_array($menu_item['page_callback'], $menu_item['page_arguments'])). This time I am redirected to my 'http://mysite.com/ajax-form' which is my menu url to the ajax call used to return the html.

1 Answer 1

0

I was able to solve this using the following code:

function bikebike_ajax_form()
{
    if (isset($_POST['url']))
    {
        $url = $_POST['url'];
        $menu_item = menu_get_item($url);
        $form = call_user_func_array($menu_item['page_callback'], $menu_item['page_arguments']);
        if (isset($form['#action']))
        {
            $form['#action'] = url($url);
        }
        $html = drupal_render($form);
        die($html);
    }
    die('');
}

As you can see, instead of rendering the page using file_get_contents, I simply grabbed the elements from the function defined in hook_menu. I needed to change the 'action' parameter of the resulting form structure.

If anyone has a better solution to this problem, I'll happily give you the answer.

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.