Form Submit - submit button doesn't get included in Form data
See original GitHub issueI have an issue when attempting to submit a form where the value for the submit button itself isn’t sent. This is an issue because it is a website that I don’t control and is requiring that form data. Here is the important bits of the HTML of the form being submitted, along with the code I’m using:
HTML
<form action="/login" method="post" id="login">
<fieldset>
<dl>
<dt><label for="username">Username:</label></dt>
<dd><input type="text" name="username" id="username" /></dd>
</dl>
<dl>
<dt><label for="password">Password:</label></dt>
<dd><input type="password" id="password" name="password" /></dd>
</dl>
<dl>
<dt> </dt>
<dd><input type="submit" name="login" value="Login"></dd>
</dl>
</fieldset>
</form>
C#
var formData = new Dictionary<string, string>
{
{ "username", "Admin" },
{ "password", "password" }
};
var form = this.Document.QuerySelector<IHtmlFormElement>('#login');
var submitted = await form.SubmitAsync(formData);
I’ve narrowed the issue down to this line returning false. It looks like it is expecting the submit element to equal the form that the submit is inside, which doesn’t make sense to me: https://github.com/AngleSharp/AngleSharp/blob/9da30e34c2c5cffd814d22f0e122db6bda968dd5/src/AngleSharp/Html/InputTypes/SubmitInputType.cs#L21
I’m not sure what the intent of Boolean IsAppendingData(IHtmlElement submitter)
is, but I pulled down your source and put it into my solution and modified the line to compare form-to-form rather than form-to-input, as so, which fixed the issue:
return Object.ReferenceEquals(submitter, Input.Form);
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top GitHub Comments
I’ve encountered this same problem. Having read the aforementioned distinction regarding the difference between a JavaScript
form.submit()
and a JavaScriptbutton.click()
I think one important detail is being overlooked which is that when JavaScript is disabled the browser does send the submit button name and value. Though AngleSharp doesn’t support JavaScript, it seems to me that API members such asIHtmlInputElement.DoClick()
strongly suggest its mimicking non-JavaScript browser behavior. Regardless of what spec may be implemented, I think this practical reality provides good reason to modify AngleSharp’s behavior accordingly. Not that my anectodical situation should dictate the whole, but for me this prevented me from adopting AngleSharp in my most recent project. Do you think this could be revisted?I’ve run into this problem as well, but it looks like the workarounds are not necessary anymore since this is now possible out of the box:
Which results in the button name + value being part of the submitted data.