I'm using the module EntityForm to build a form. This EntityForm will be an entity reference field in the content type ShowForm. ShowForm contains the form and some other fields that give some information about what the form will be used for. Once the EntityForm is filled in, they should be redirected to the ShowForm-node that contained it so they can fill it in again (for someone else). There will be different ShowForm-nodes that all have a reference to this EntityForm, but I have to redirect them to the specific ShowForm-node they filled in the form on.

I've added an extra submit button and submit handler that submits the form and redirects them to a ShowForm-node so they can fill it in once more. The problem is that I can't find a way to redirect them to a ShowForm-node without hardcoding the id (so it's only useable for 1 ShowForm-node).

For example:


where 123 is the nodeid of the node showing the EntityForm. I'd like to be able to get the nodeid dynamically for redirecting instead of manually putting in '123'.

This is my code so far:

function extra_inschrijving_form_alter(&$form, &$form_state, $form_id){

    if ($form_id == 'generiek_inschrijvingsformulier__entityform_edit_form'){
        $form['submit2'] = $form['actions']['submit'];
        $form['submit2']['#value']='Inschrijven en ook een broer inschrijven';

function extra_inschrijving_default_wp_submit($form, &$form_state){
       //Do some stuff

      $form_state['redirect']='node/' . $node_id;

Is there a way to get the right value for this $node_id? Is it possible?

(I was thinking about adding a hidden field to the EntityForm and using rules to set it with the nodeid of ShowForm when a ShowForm-node is created, but I can't seem to acces the EntityForm's fields in rules even when I use "has field"-conditions)

  • How is the entity form attached to the node? Is it via an entity reference field? – Clive Jul 24 '16 at 19:27
  • I've made a content type (the node) that has an entity reference field to the EntityForm. – Robin De Haes Jul 24 '16 at 19:58
  • So now there are 2 existing entityform and a entityreference field on entityform A which points to entityform B? Are they pre-created? – Jimmy Ko Jul 25 '16 at 22:02
  • I've edited my question, since I think I didn't describe my problem correctly. I hope it's better now. There's only 1 EntityForm, but also a content type ShowForm that references the EntityForm. I have to find the nodeid of the ShowForm when I submit the EntityForm. – Robin De Haes Jul 26 '16 at 8:35

I've solved it like this:

I've added a hidden field to the EntityForm called parentid and set that value with the id of the ShowForm-node when the node is created. This way I can use this parentid to redirect to the correct ShowForm-node when submitting a form.

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.