允许URL中的保留字符

时间:2011-06-15 10:25:25

标签: php drupal

我正在函数中创建一个URL,在hook_form_alter的实现中使用它来添加一个新按钮(我试图解决这个问题:Drupal - Creating 'add another' buttons on node edit forms that will retain node relationships):

hook_form_alter的相关部分:

  if ($form_id === 'image_node_form') {         
        $form['buttons']['submit_again'] = array(
        '#type' => 'submit',
        '#value' => t('TEST'),
        '#weight' => 41,
        '#submit' => array('node_form_submit', 'add_another_node_form_submit'),
      );
  }

使用该功能:

function add_another_node_form_submit($form, &$form_state) {
    $refnode = $form['field_gallery'][0]['nid']['#default_value'];
    $refnode = 'node/add/image/'.$refnode.'?destination='.$_REQUEST['destination'];
    unset($_REQUEST['destination'], $_REQUEST['edit']['destination']);
    $form_state['redirect'] = $refnode;  
}

修改后的表格:

<form action="/node/add/image/189?destination=marketplace%252Fproperties%252Ftest"  accept-charset="UTF-8" method="post" id="node-form" enctype="multipart/form-data"> 
<div> 
<div class="node-form"> 
  <div class="standard"> 
<input type="hidden" name="changed" id="edit-changed" value=""  /> 
<input type="hidden" name="form_build_id" id="form-9869451ca1d3c9b91806442e39026622" value="form-9869451ca1d3c9b91806442e39026622"  /> 
<input type="hidden" name="form_token" id="edit-image-node-form-form-token" value="5b0ddf4a6a9bc7f54a61c666230169bf"  /> 
<input type="hidden" name="form_id" id="edit-image-node-form" value="image_node_form"  /> 
<input type="hidden" name="flag_friend_control" id="edit-flag-friend-control" value=""  /> 
<div class="form-item" id="edit-field-gallery-0-nid-wrapper"> 
 <label for="edit-field-gallery-0-nid">Marketplace item: </label> 
 test
</div> 
<div  id="edit-field-image-0-ahah-wrapper"><div class="form-item" id="edit-field-image-0-upload-wrapper"> 
 <label for="edit-field-image-0-upload">Image: <span class="form-required" title="This field is required.">*</span></label> 
 <div class="filefield-element clear-block"><div class="widget-edit"><input type="hidden" name="field_image[0][fid]" id="edit-field-image-0-fid" value="0"  /> 
<input type="hidden" name="field_image[0][list]" id="edit-field-image-0-list" value="1"  /> 
<div class="form-item" id="edit-field-image-0-upload-wrapper"> 
 <div class="filefield-upload clear-block"><input type="file" name="files[field_image_0]"  class="form-file" id="edit-field-image-0-upload" size="22" /> 
<input type="submit" name="op" id="edit-field-image-0-filefield-upload" value="Upload"  class="form-submit" /> 
</div> 
 <div class="description">Maximum file size: <em>2 MB</em><br />Allowed extensions: <em>png gif jpg jpeg</em></div> 
</div> 
</div></div> 
</div> 
</div><div class="form-item" id="edit-title-wrapper"> 
 <label for="edit-title">Caption: <span class="form-required" title="This field is required.">*</span></label> 
 <input type="text" maxlength="255" name="title" id="edit-title" size="60" value="" class="form-text required" /> 
</div> 
<fieldset class=" collapsible collapsed"><legend>Comment settings</legend><div class="form-radios"><div class="form-item" id="edit-comment-0-wrapper"> 
 <label class="option" for="edit-comment-0"><input type="radio" id="edit-comment-0" name="comment" value="0"  checked="checked"  class="form-radio" /> Disabled</label> 
</div> 
<div class="form-item" id="edit-comment-1-wrapper"> 
 <label class="option" for="edit-comment-1"><input type="radio" id="edit-comment-1" name="comment" value="1"   class="form-radio" /> Read only</label> 
</div> 
<div class="form-item" id="edit-comment-2-wrapper"> 
 <label class="option" for="edit-comment-2"><input type="radio" id="edit-comment-2" name="comment" value="2"   class="form-radio" /> Read/Write</label> 
</div> 
</div></fieldset> 
  </div> 
  <div class="admin"> 
    <div class="authored"> 
    </div> 
    <div class="options"> 
    </div> 
  </div> 
<input type="submit" name="op" id="edit-submit" value="Save"  class="form-submit" /> 
<input type="submit" name="op" id="edit-preview" value="Preview"  class="form-submit" /> 
<input type="submit" name="op" id="edit-submit-again" value="TEST"  class="form-submit" /> 
</div> 

</div></form> 

提交时,网址会显示(例如):

/node/add/image/214%3Fdestination%3Dmarketplace%25252Fproperties%25252Ftest-0

如何停止保留字符'?'并且''destination ='中的'='被转换为十六进制实体?

1 个答案:

答案 0 :(得分:0)

是的,这是因为$ form_state ['redirect']需要使用数组:

https://drupal.stackexchange.com/questions/2436/how-do-i-include-and-in-a-form-redirection