1

Case :

I do have a Article-share content type , it does contain a node reference to type "Article" , now this is my scenario :

  • user selects a node of type Article
  • he redirects to node/add/Article share
  • now in this form I want the selected coupon shows up in the form automatically so the user wont need to fill this field again

enter image description here

Some more deails:

  • I have a content type called "Article-Share".
  • This type has a reference field to Node type "Article".
  • I want my content creation form for type "Article Share" to use wildcards to automatically fill "Article Link".

Any suggestions how I can do so?

0

3 Answers 3

0

You will need a module for that but it's easy :

the scenario is this : on screen 1 , you've got a form which contains a select list , when user submits this form , will redirects to a content creation form , the important thing is that the coupon id must be passed to it .

so the solution :

you will have a submission function for your first screen form

function first_screen_form_submit($form, &$form_state) {
  //enter some codes here to get nid of selected coupon
  //.
  //.
  $form_state['redirect'] = 'node/add/coupon-share/'. $nid;
  drupal_redirect_form($form_state);//this will redirects you to form and passes the nid
}

now you must alter the node creation form :

//Implement hook_form_BASE_FORM_ID_alter()     
function YourModuleName_form_node_form_alter(){
  if(isset($form['type']) && isset($form['#node'])) {
    $type = $form['#node']->type;
    switch($type) :
        case 'coupon-share':
          $passedNid = arg(3);
          $passedNode = node_load($passedNid);
          //now you have the coupon node available here and can fill your field with it
          //.
          //.
          breake;
  }
}
0

I have solve this problem by jquery.

jQuery(document).ready(function(){
  var urlVar =  window.location.pathname.split('/');
  if(urlVar[4]=='coupon-share' && urlVar[5]!=''){
    jQuery("#edit-field-user-coupon-link-und").val(urlVar[5]);
  }
}); 
0

This sounds very much like you want the Entityreference prepopulate module.

"Allow prepopulating any Entity reference field via URL"

From the README.txt:

Usage
=====
In order to pre-populate an entity reference field you have to supply the
parameter in the URL.

The structure is
node/add/article?[field_ref]=[id]

Where [field_ref] is the name of the entity reference field and [id] is
the id of the entity being referenced.

Examples:
node/add/article?field_foo=1
node/add/page?field_bar=1,2,3

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