cancel
Showing results for 
Search instead for 
Did you mean: 

Web script extract specific content from file

anand_patel18
Champ in-the-making
Champ in-the-making
Hi,

I'm trying to get a process going where I submit a HTML form that has been filled out and the web script extracts the form content and creates, then saves it to a text file. Then after it has been submitted the user may look at the filled out form so I want to create another web script that extracts the content out of the text file and put it back in the HTML form. I've get the first script working just trying to get the second part working.

Also am I going about this the right way? I pretty much need to create an e-form that needs to be filled out by users. I 'm trying to achieve a save as draft function for the form, also once the form has been submitted it needs to be able to be read by other users (and edited) in the same HTML form.



Thanks,

Anand
3 REPLIES 3

invictus9
Champ in-the-making
Champ in-the-making
You might consider saving the form result as an XML file. For instance, there is a standard for XFORMs which is essentially captures a snapshot of the form.

With an XML file in place, you can use Freemarker Template Language (FTL) as part of your web script to use the data from the XML file and display it in the way you want. You can use different web scripts (hence, different FTL files) to show the file in different ways.

anand_patel18
Champ in-the-making
Champ in-the-making
Awesome Thank you,

I've got my head around what I need to do, could someone please help me out with the code, Im new to javascript, this is what I've got for the script so far to save it as a text file.

employeename = "";
Grade = "";
currentPM = "";
currentMD = "";
Month = "";
Day = "" ;
Year = "";
PEselfPA = "" ;
PEselfFA ="" ;
PEselfC ="" ;
PEselfCT ="" ;

// locate file attributes
for each (field in formdata.fields)
{
  if (field.name == "employeename")
  {
    employeename = field.value;
  }
  else if (field.name == "Grade")
  {
    Grade = field.value;
  }
  else if (field.name == "currentPM")
  {
    currentPM = field.value;
  }
  else if (field.name == "currentMD")
  {
    currentMD = field.value;
  }
  else if (field.name == "Month")
  {
    Month = field.value;
  }
  else if (field.name == "Day")
  {
    Day = field.value;
  }
  else if (field.name == "Year")
  {
    Year = field.value;
  }
  else if (field.name == "PEselfPA")
  {
    PEselfPA = field.value;
  }
  else if (field.name == "PEselfFA")
  {
    PEselfFA = field.value;
  }
  else if (field.name == "PEselfC")
  {
    PEselfC = field.value;
  }
  else if (field.name == "PEselfCT")
  {
    PEselfCT = field.value;
  }

}

//
var doc = userhome.createFile(employeename + ".html");
doc.addAspect("cm:versionable");
doc.content = "employeename = " + employeename + "\n" +
"Grade = " + Grade + "\n" +
"currentPM = " + currentPM + "\n" +
"currentMD = " + currentMD + "\n" +
"Date = " + Day + " " + Month + " " + Year + "\n" +
"PEselfPA = " + PEselfPA + "\n" +
"PEselfFA = " +  PEselfFA + "\n" +
"PEselfC = " + PEselfC + "\n" +
"PEselfCT = " + PEselfCT;

I do I save it as a XML file and save it in a structured way so I can extract the values out? Also could someone please help me with the code to extract the values out of a xml file. If some one cold please just help me with one field value then I can get my head around the rest.

anand_patel18
Champ in-the-making
Champ in-the-making
Awesome Thank you,

I've got my head around what I need to do, could someone please help me out with the code, Im new to javascript, this is what I've got for the script so far to save it as a text file.

employeename = "";
Grade = "";
currentPM = "";
currentMD = "";
Month = "";
Day = "" ;
Year = "";
PEselfPA = "" ;
PEselfFA ="" ;
PEselfC ="" ;
PEselfCT ="" ;

// locate file attributes
for each (field in formdata.fields)
{
  if (field.name == "employeename")
  {
    employeename = field.value;
  }
  else if (field.name == "Grade")
  {
    Grade = field.value;
  }
  else if (field.name == "currentPM")
  {
    currentPM = field.value;
  }
  else if (field.name == "currentMD")
  {
    currentMD = field.value;
  }
  else if (field.name == "Month")
  {
    Month = field.value;
  }
  else if (field.name == "Day")
  {
    Day = field.value;
  }
  else if (field.name == "Year")
  {
    Year = field.value;
  }
  else if (field.name == "PEselfPA")
  {
    PEselfPA = field.value;
  }
  else if (field.name == "PEselfFA")
  {
    PEselfFA = field.value;
  }
  else if (field.name == "PEselfC")
  {
    PEselfC = field.value;
  }
  else if (field.name == "PEselfCT")
  {
    PEselfCT = field.value;
  }

}

//
var doc = userhome.createFile(employeename + ".html");
doc.addAspect("cm:versionable");
doc.content = "employeename = " + employeename + "\n" +
"Grade = " + Grade + "\n" +
"currentPM = " + currentPM + "\n" +
"currentMD = " + currentMD + "\n" +
"Date = " + Day + " " + Month + " " + Year + "\n" +
"PEselfPA = " + PEselfPA + "\n" +
"PEselfFA = " +  PEselfFA + "\n" +
"PEselfC = " + PEselfC + "\n" +
"PEselfCT = " + PEselfCT;

How do I save it as a XML file and save it in a structured way so I can extract the values out? Also could someone please help me with the code to extract the values out of a xml file. If some one could please help me with extracting one field value then I can get my head around the rest.