InStr Function to retrieve data

Discussion in 'C#' started by red_fiesta, Nov 14, 2006.

  1. #1
    if i have the string

    strName=request.form("strName")

    where strName is <form name="cv" action="validate/validate.asp" method="post">
    <input type="hidden" value="winebottles.jpg" name="downloadFile" /></form>

    and i need to retrieve the value of downloadFile.

    I was thinking of using an inStr function..

    ie..


    <% 
    		
    dim formUsed, pageN,strCheck, initalcheck
    
    		strCheck="name=""downloadFile""
    		
    		initalcheck=InStr(Request.form("strName"),strCheck)
    
    
    	if initalcheck > 0 then 
    	formUsed=InStr(request.form("strName"), strCheck)
    	
    	pageN = mid(Request.form("strName"), formUsed)%>
    
    <%=pageN%>
    Code (markup):
    I need to send the inStr to a certain place and need to get the file name which vary in length as it is a name...

    please help
     
    red_fiesta, Nov 14, 2006 IP
  2. frankcow

    frankcow Well-Known Member

    Messages:
    4,859
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    180
    #2
    why not just use: request.form("downloadFile") ?
     
    frankcow, Nov 14, 2006 IP
  3. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    the thing is the text has come from an editor, so i cant just use request.form

    thats what i was saying if you request the text from the previous page it will return

    <form name="cv" action="validate/validate.asp" method="post">
    <input type="hidden" value="winebottles.jpg" name="downloadFile" /> as the value of the posted text

    so i need to do an instr and look for downloadFile to see if a file has been attached, if it has then i need to get the value...

    is that any clearer?

    thanks...
     
    red_fiesta, Nov 14, 2006 IP
  4. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Ok, so

    there is a wysiwyg editor where people add text, the html of this will then be saved in the database...

    also in this wysiwyg editor is the ability to add forms. so on the next page all this text that may include a form will be saved in the database as html so that this page can then be shown later...

    so i need to look at what is been posted from the user

    if i use

    initalcheck=InStr(Request.form("strName"),"<form")

    and initalcheck > 0 then i know that a form has been use


    if i use

    initalcheck=InStr(Request.form("strName"),"downloadFile")


    and initalcheck > 0 then i know that a downloadable file has been used


    so what i now need to do is get the value from the page

    where the code coming from the editor is

    <form name="cv" action="validate/validate.asp" method="post">
    <input type="hidden" value="winebottles.jpg" name="downloadFile" /></form>



    thats why i was trying to use an inStr to find the word download file and move to the name of the value and then store it...

    any clearer?
     
    red_fiesta, Nov 14, 2006 IP
  5. Garve

    Garve Peon

    Messages:
    62
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Sounds a wierd and wonderful way to do things, but I'm sure you've got a good reason!

    You need to do an instr search for ' value=" ', then find the next double quote which will be at the end of the file name, and then use the vbscript Mid function.

    Eg
    'find start of the text value
    valuestart = instr(strName,"value")

    'now we have the position of the v in value, we need to get instr to search for a double quote which is more than 6 characters further on
    valueend = instr(valuestart,strname,"""")
    'note I had to double up the double quotes to get this to work

    'now we should have the start and end positions of the file name we can do
    thefilename = mid(strname,valuestart,valueend)



    Note - I haven't tested this, and you'll probably find you need to adjust the numbers - eg it might be

    valueend = instr(valuestart,strname,"""")+1


    cheers

    Garve
     
    Garve, Nov 15, 2006 IP
  6. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    sFormText = getVal(sFormText )

    function getVal(sText)
    if instr(sText,"<form") then
    arText = Split(sText,"<")
    for x = 0 to UBound(arText)
    sText = replace(arText(x),"<","")
    sText = Replace(sText,"/>","")
    if instr(sText,"downloadfile") > 0 then
    exit for
    end if
    next
    end if
    getVal = Mid(sText,instr(sText,"value="""),len(stext))
    getVal = Replace(getVal,"value=""","")
    getVal = Replace(getVal,"""","")
    getVal = Replace(getVal, "name=downloadfile","")
    end function

    Response.Write sFormText

    did the trick!
     
    red_fiesta, Nov 15, 2006 IP