Search code examples
delphiindy

The easiest way to get default form values in a HTML form from a page source retrieved via Indy?


I want to modify my profile information on a site and I'm using Indy for this. My question is: when I GET (via Indy) the contents of the profile page, that page will have a form with all the previous filled info checked/completed. If I want to change that info, I have to POST (via Indy) all the previous (unchanged) values and the changed ones, otherwise, if I POST only the values I want to change, the unchanged ones will be registered as empty and thus get nulled off my profile. My question is, is there an easy way to get the prefilled values from the HTML of the form so I can them re-post (and modify where needed) them?


Solution

  • You can use https://github.com/Zeus64/alcinoe string component for this, it's very simple, you need to use :

    function  ALFastTagReplace(const SourceString, TagStart, TagEnd: AnsiString;
                               ReplaceExtendedProc: TALHandleTagExtendedfunct;
                               StripParamQuotes: Boolean;
                               ExtData: Pointer;
                               Const flags: TReplaceFlags=[rfreplaceall];
                               const TagReplaceProcResult: Boolean = False): AnsiString; overload;
    

    example :

     ALFastTagReplace(MyHtmlString, // Const SourceString, 
                      '<input' // TagStart, 
                       '>', // TagEnd: AnsiString;
                       function(const TagString: AnsiString;
                                       TagParams: TALStrings;
                                       ExtData: pointer;
                                       Var Handled: Boolean;
                                       Const SourceString: AnsiString;
                                       Var TagPosition, TagLength: integer): AnsiString;
                       begin
                         Myprefilledvalues.add(TagString + '=' + TagParams.values['value'])
                       end,
                       true, // StripParamQuotes 
                       nil); // ExtData