Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Form with no name submit
#1
Attached web form's code

.txt   Form with no name submit.txt (Size: 1.15 KB / Downloads: 1)

CYZ
Reply
#2
Hello carlos,

You forgot the question, but I take it that the question is how-to programmatically submit this form?

If the form would have had an id (id="login") attribute set on the form itself then you would have been able to use:
Code:
Private Sub SubmitButton_Click()
  Document.RequestFormSubmitById "login"
End Sub

But there is no id.. the alternative to select by name also is not available in your example form.
So that suggests that there's no way to do this without going down to javascript level, or is there?
Note: you can always handle these type of issues with a bit of javascript, but luckily you don't have to do that as there is an easier way to do so.

An alternative way on clicking on that submit button would be to send a "click" to the button instead of submitting the form.
Imagine your form had the id set to login as above then the following would work.
Code:
Private Sub SubmitButton_Click()
  Document.ElementClickByQuerySelector "#login > fieldset > input"
End Sub

This says, click on the html element that is of type input in a fieldset in the html element with an id set to "login".

Fine, but we don't have the id set, let's make it more general.
Code:
Private Sub SubmitButton_Click()
  Document.ElementClickByQuerySelector "form > fieldset > input"
End Sub

So now we're telling the AntView control to click on a html element of type input inside a fieldset which is in a form.
This already works if you would test it on a html file that you presented.

However.. what if html has more than one form in there that matches this selector? Can we be a bit more specific?
Turns out we can.

The following is what I suggest you use:
Code:
Private Sub SubmitButton_Click()
  Document.ElementClickByQuerySelector "form.formulario > fieldset > input"
End Sub
here we're telling the AntView control to click on a html element of type input inside a fieldset which is in a form that has a class set to "formulario".

And that.. hopefully is specific enough for your needs.

edit: see also the help on ElementClickByQuerySelector for a bit more background info.
--
Wil
Reply
#3
Hi. The subject was the question: form with no name submit

Wil: amazing. I go to test it. Anyway, your code and your explanations opens a lot of posibilities for me.
Many thanks.

Hi again,

That worked for me. In my next step, I used again your solution:
thisform.oantviewdocument_lista.ElementClickByQuerySelector(".default-btn-shortcode")

And also, worked. But, result opens in a new browser window so i loose control. (target="_blank")
Any help for that?
html: <a class="default-btn-shortcode dt-btn dt-btn-m" href="#" target="_blank"><i class="fas fa-user-lock"></i>MI OFICINA VIRTUAL</a>

CYZ
Reply
#4
Hi, maybe my last post were missing:
But, result opens in a new browser window so i loose control. (target="_blank")
I solved navigating to same URL in main document, but the new browse window remains open. Is there a better solution to avoid this?
Thanks

CYZ
Reply
#5
Hi CYZ,

Use the event OnNewWindowsRequested to block the opening of a new window by setting Args.Handled to True.
Then use navigate to browse to the URL you needed to go.

The VB6 - New Window Handling example shows you in more details, but let me copy & paste the specific code I meant as it explains more than just one technique.
Code:
Private Sub EdgeWebBrowser_OnNewWindowRequested(ByVal Args As AntViewAx2.IAntViewNewWindowRequestedEventArgs)

  ' ..

  If OptionRadio(1).Value = True Then

    Args.Handled = True

    EdgeWebBrowser.Navigate Args.URI

  End If

I just noticed you use VFP.

There is an example on how-to do this too for Fox Pro in the examples of AntView version 2.

edit: and now I see that the url is "#", so the same page. I guess that there's an onclick event attached to that url that handles whatever the link should do. It might enough to just block the click and not navigate. Not sure, we might be missing context.

--
Wil
Reply
#6
(2025-03-09, 12:39:50)wila Wrote: Hi CYZ,

Use the event OnNewWindowsRequested to block the opening of a new window by setting Args.Handled to True.
Then use navigate to browse to the URL you needed to go.

The VB6 - New Window Handling example shows you in more details, but let me copy & paste the specific code I meant as it explains more than just one technique.
Code:
Private Sub EdgeWebBrowser_OnNewWindowRequested(ByVal Args As AntViewAx2.IAntViewNewWindowRequestedEventArgs)

  ' ..

  If OptionRadio(1).Value = True Then

    Args.Handled = True

    EdgeWebBrowser.Navigate Args.URI

  End If

I just noticed you use VFP.

There is an example on how-to do this too for Fox Pro in the examples of AntView version 2.

edit: and now I see that the url is "#", so the same page. I guess that there's an onclick event attached to that url that handles whatever the link should do. It might enough to just block the click and not navigate. Not sure, we might be missing context.

--
Wil

Thanks, Wil. I will test it.

CYZ
Reply
#7
If i lock the new window with args.handled = true, navigation in EdgeWebBrowser.Navigate does not work.
However, if I allow the new window to be opened, and then use EdgeWebBrowser.Navigate to same URL, that works fine. The only issue is the new opened window... remains opened and active.

CYZ
Reply
#8
Hi,

In principle this should work, but I suspect something very specific to your website is happening here.
Without more details, it is hard to say.
The only navigate that wouldn't work in the event is a sync version.
In other words: NavigateSync doesn't work from an event whereas Navigate does.
But that's documented, so I doubt that it is your issue.

Can you contact me directly at support@antwise.com to see if we can figure out what is happening here?

--
Wil
Reply
#9
I'll send you private mail

CYZ
Reply
#10
For anybody else reading this. The issue has been resolved.

The navigation that caused the issue was indirect by triggering a javascript click event from calling ElementClickByQuerySelectorSync.

Because the synchronized method was used, the OnNewWindowRequested event was not getting triggered.
By using the ElementClickByQuerySelector method instead, things started to work as expected and the creation of the new window could now be stopped.

FWIW, we used the following in the OnNewWindowRequested event.
Code:
*** ActiveX Control Event ***
LPARAMETERS args

lcURL = ""

Args.Handled = .t.
lcURL = Args.URI
Thisform.currenturl1 = Args.URI   
Args.NewWindowDispatch (thisform.oAntview1.object)
As you can see here, the method to get the current URI and then use method navigate is not used, but instead we tell the OnNewWindowRequested event to re-use the existing AntView object for the "New Window" by assiging it to NewWindowDispatch. Both methods work with tiny differences.

If you navigate explicitly then you get to keep navigation history and the "back button" will work.
If you assign the current AntView object as the "new window" then your navigation history is gone and there will be no "back button".
Btw, the back button here is the "Back" option in the context (right click) menu.

--
Wil
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)