Skip to content

Commit e96d6cb

Browse files
committed
Added: __WinHttpHTML5FormAttribs() internal function to allow HTML5 input attributes ("formaction", "formenctype", "formmethod").
1 parent 11a3ae0 commit e96d6cb

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed

WinHttp.au3

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,8 +1096,8 @@ EndFunc
10961096
; In that case first form with that name is filled.
10971097
; +As for fields, If [["name:FieldName"]] option is used all the fields except last with that name are removed from the form. Last one is filled with specified [[$sDta]] data.
10981098
; +This function can be used to fill forms with up to 40 fields at once.
1099-
; +"Submit" control you want to keep (click) set to True. If no such control is set then the first one found in the form is "clicked"
1100-
; and the other removed from the submited form. "Checkbox" and "Button" input types are removed from the submitted form unless explicitly set. Same goes for "Radio" with exception that
1099+
; +"Submit" control you want to keep (click) set to True. If no such control is set then the first one found in the form is "clicked". You can also use [["type:submit", zero_based_index_of_the_submit]] to "click" if no id or name is available.
1100+
; All other "submit" controls are removed from the submited form. "Checkbox" and "Button" input types are removed from the submitted form unless explicitly set. Same goes for "Radio" with exception that
11011101
; only one such control can be set, the rest are removed. These controls are set by their values. Wrong value makes them invalid and therefore not part of the submited data.
11021102
; +All other non-set fields are left default.
11031103
; +Last (superfluous) [[$sAdditionalData]] argument can be used to pass authorization credentials in form [["[CRED:username:password]"]], magic string to ignore certificate errors in form [["[IGNORE_CERT_ERRORS]"]], change output type to extended array with [["[RETURN_ARRAY]"]] moniker, and/or HTTP request header data to add.
@@ -1213,6 +1213,8 @@ Func _WinHttpSimpleFormFill(ByRef $hInternet, $sActionPage = Default, $sFormId =
12131213
$fSend = True
12141214
$aInput = StringRegExp($sForm, "(?si)<\h*(?:input|textarea|label|fieldset|legend|select|optgroup|option|button)\h*(.*?)/*\h*>", 3)
12151215
If @error Then Return SetError(2, 0, "") ; invalid form
1216+
; HTML5 allows for "formaction", "formenctype", "formmethod" submit-control attributes to be set. If such control is "clicked" then form's attributes needs updating/correcting
1217+
__WinHttpHTML5FormAttribs($aDtas, $aFlds, $iNumParams, $aInput, $sAction, $sEnctype, $sMethod)
12161218
; Workout correct URL, scheme, etc...
12171219
__WinHttpNormalizeActionURL($sActionPage, $sAction, $iScheme, $sNewURL, $sEnctype, $sMethod)
12181220
If $fVarForm And Not $sNewURL Then Return SetError(5, 0, "") ; "action" must have URL specified
@@ -2030,6 +2032,70 @@ Func __WinHttpNormalizeActionURL($sActionPage, ByRef $sAction, ByRef $iScheme, B
20302032
If $sMethod = "GET" Then $sEnctype = ""
20312033
EndFunc
20322034

2035+
Func __WinHttpHTML5FormAttribs($aDtas, $aFlds, $iNumParams, ByRef $aInput, ByRef $sAction, ByRef $sEnctype, ByRef $sMethod)
2036+
; Clicking "submit" is done using:
2037+
; "type:submit", zero_based_index_of_the_submit_button
2038+
; "name:whatever", True
2039+
; "id:whatever", True
2040+
; "whatever", True ;<- same as "id:whatever"
2041+
Local $aSpl, $iSubmitHTML5 = 0, $iInpSubm
2042+
For $k = 1 To $iNumParams
2043+
$aSpl = StringSplit($aFlds[$k], ":", 2)
2044+
If $aSpl[0] = "type" And $aSpl[1] = "submit" Then
2045+
Local $iSubmIndex = $aDtas[$k], $iSubmCur = 0
2046+
For $i = 0 To UBound($aInput) - 1 ; for all input elements
2047+
If __WinHttpAttribVal($aInput[$i], "type") = "submit" Then
2048+
If $iSubmCur = $iSubmIndex Then
2049+
$iSubmitHTML5 = 1
2050+
$iInpSubm = $i
2051+
Else
2052+
$aInput[$i] = "" ; remove any other submit control
2053+
EndIf
2054+
$iSubmCur += 1
2055+
EndIf
2056+
Next
2057+
ElseIf $aSpl[0] = "name" Then
2058+
Local $sInpNme = $aSpl[1]
2059+
For $i = 0 To UBound($aInput) - 1 ; for all input elements
2060+
If __WinHttpAttribVal($aInput[$i], "type") = "submit" Then
2061+
If __WinHttpAttribVal($aInput[$i], "name") = $sInpNme And $aDtas[$k] = True Then
2062+
ConsoleWrite($sInpNme & @CRLF)
2063+
$iSubmitHTML5 = 1
2064+
$iInpSubm = $i
2065+
ExitLoop
2066+
EndIf
2067+
EndIf
2068+
Next
2069+
If $iSubmitHTML5 Then ExitLoop
2070+
Else ; id
2071+
Local $sInpId
2072+
If @error Then
2073+
$sInpId = $aSpl[0]
2074+
ElseIf $aSpl[0] = "id" Then
2075+
$sInpId = $aSpl[1]
2076+
EndIf
2077+
For $i = 0 To UBound($aInput) - 1 ; for all input elements
2078+
If __WinHttpAttribVal($aInput[$i], "type") = "submit" Then
2079+
If __WinHttpAttribVal($aInput[$i], "id") = $sInpId And $aDtas[$k] = True Then
2080+
$iSubmitHTML5 = 1
2081+
$iInpSubm = $i
2082+
ExitLoop
2083+
EndIf
2084+
EndIf
2085+
Next
2086+
If $iSubmitHTML5 Then ExitLoop
2087+
EndIf
2088+
Next
2089+
If $iSubmitHTML5 Then
2090+
Local $sAttr = __WinHttpAttribVal($aInput[$iInpSubm], "formaction")
2091+
If $sAttr Then $sAction = $sAttr
2092+
$sAttr = __WinHttpAttribVal($aInput[$iInpSubm], "formenctype")
2093+
If $sAttr Then $sEnctype = $sAttr
2094+
$sAttr = __WinHttpAttribVal($aInput[$iInpSubm], "formmethod")
2095+
If $sAttr Then $sMethod = $sAttr
2096+
EndIf
2097+
EndFunc
2098+
20332099
Func __WinHttpFinalizeCtrls($sSubmit, $sRadio, $sCheckBox, $sButton, ByRef $sAddData, $sGrSep, $sBound = "")
20342100
If $sSubmit Then ; If no submit is specified
20352101
Local $aSubmit = StringSplit($sSubmit, $sGrSep, 3)

0 commit comments

Comments
 (0)