3

I have a custom module where I create a table from some data. In one of the columns I need to have a button that when clicked will open a new tab and show the user a form and a submit button and some of the form fields are pre-filled with data from the table (data from the same row).

I know how to add a button but I don't know how to pass the data to the form.

Also, for the button I'm using the following code and maybe this is already wrong:

$new_button = '<a href="/examples/form-example" target="_blank" class="btn btn-primary" role="button">New form</a>';

Note: the data is not in the drupal database. The table is made on the fly using REST.

Any help will be greatly appreciated. Thanks!

3

Prepopulate module can pass value to form with query parameter.

Simple example:

<a href="/node/add/content?edit[title]=This is the title" target="_blank" class="btn btn-primary" role="button">New form</a>';

More examples can be found on its documentation.

If you find problems, please check this issue, some known bug has been introduced from 7.x-2.1 version. You may need to patch it.

  • Thanks Jimmy Ko but this is also valid for my case where the table has data not from drupal database? – zephirus Jul 25 '16 at 21:53
  • 1
    No worry about that. What you want is to pass the value to form, right? The value is passed directly on the query parameter. It does not involve any database manipulation. – Jimmy Ko Jul 25 '16 at 21:54

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.