Background
I have a HTML form that I am trying to submit using the Python Requests module.
This is the HTML for the form:
<form name="main" id="main" method="post" onSubmit="return validateForm(this);">
Javascript files involved
The validateForm() function looks like this:
function validateForm(form)
{
if (form.buttonClicked[0].value == "delete"){
deleteCount += 1;
if (deleteCount > 1){
return false;
}
if(form.allowValidateOnDelete && form.allowValidateOnDelete.value == "true")
{
deleteCount = 0;
return validate(form);
}
else
{
return true;
}
}
else{
return validate(form);
}
}
This is validate()
function trimAll(form)
{
form.forwardedToNumber.value = trim(form.forwardedToNumber.value);
}
function validate(form)
{
trimAll(form);
for (var i=0; i < form.active.length; i++) {
if (form.active[i].checked) {
if (form.active[i].value == "false") {
return true;
}
}
}
if (form.forwardedToNumber.value == "") {
alert(errorText(1000, errorText(2201)));
form.forwardedToNumber.select();
return false;
}
return true;
}
Question
How do I submit this form using Python?
I can't really submit the below example because it doesn't make sense as a URI:
session.request(
'POST',
'https://example.com/return validateForm(this);',
data={'active': 'true'}
)
How I would go about submitting a form which has a target of return function(); ?
'https://example.com/'and not'https://example.com/return validateForm(this);'judging from the code. Since there is no target, it will probably be/. Have you tried that?