Ignore:
Timestamp:
09/07/17 17:57:31 (3 years ago)
Author:
ak19
Message:

Bugfix to depositor: commas in metadata entered through the depositor were not being preserved, as commas were used to split the many fields (of form cgi params) on in depositoraction.cpp. Now depositor.dm escapes the commas with URL encoding in the metadatafields section of the depositor step1 form, while depositoraction.cpp decodes the URL-encoded commas again.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/macros/deposit.dm

    r29403 r31951  
    194194        \}
    195195       
    196         var inputObj; 
     196        var inputObj;
    197197        if (metadataField.type=="text") \{
    198198            inputObj = document.createElement("input");
     
    221221
    222222function check\_submit (gotopage) \{
     223
     224  // escape any commas in the metadata fields in order to preserve them
     225  // preserve any commas in the metadata fields by escaping them here
     226  // so that meta values containing commas don't end up split at comma by depositoraction.cpp
     227
     228  // Get just the part of form containing metadata input elements
     229  // as we don't want to modify any other part of the form
     230  var formContainer = document.getElementById('formcontainer');
     231  // https://stackoverflow.com/questions/25302684/getting-all-child-input-elements-within-a-div
     232  var inputNodes = formContainer.getElementsByTagName('input');
     233  for(var i = 0; i < inputNodes.length; i++) \{
     234    var inputNode = inputNodes[i];
     235    if(inputNode.type == 'text') \{
     236      if(inputNode.value) \{
     237        var val = inputNode.value;
     238    // To replace all occurrences in a string, and not just the 1st, need to do a global
     239    // substitution. See https://www.w3schools.com/jsref/jsref_replace.asp
     240        inputNode.value = val.replace(/,/g, "%2C");
     241      \}
     242    \}
     243  \}
     244
     245  // Proceed as usual from here on to submit the modified form
     246
    223247  var form = document.depositorform;
    224248  form.p.value = gotopage;
Note: See TracChangeset for help on using the changeset viewer.