Click in page directly send to server? (wodSFTP / wodSFTP.NET / wodSFTPdll)
I would like my app to have a built-in webserver and for that I'm going to use the wodWebServer component (in VB6).
The app will dynamicly build a webpage and serve that via the component.
However I would to have within my webpage, several checkboxes (or something else) were as the user click in them (which changes their value) that this is directly send to the webserver so that this can change some internal vars within my app (and that a refresh of the page is forced).
Is this possible? If yes how?
dirk
Re: Click in page directly send to server?
Hi Dirk,
Yes, that's possible. However, you will need to use some scripting language (i.e. JavaScript) in order to handle clicks on page controls which will initiate Post (and page refresh), since server isn't aware of changes until user posts a request.
Once clicked on CheckBox, you initiate POST, process user's request and send back the appropriate (changed) web page where specified checkbox is actually checked.
Hope this helps.
Regards,
Damba
Re: Click in page directly send to server?
Do you have some type of example that shows how those POSTS are handled?
Also is there an easy way to use username/password authentication with the component?
Re: Click in page directly send to server?
Dirk,
Here is an example of using one checkbox which triggers Post (thru JavaScript) and checks it if unchecked (and vice-versa):
[code]Dim response As String
If req = /page.htm Then
If user.Request.Posted.Count > 0 Then
If user.Request.Posted.Exists( C1 ) Then
response = response & <html><body>
response = response & <form name= check1 method= POST action= page.htm >
response = response & <p><input type= checkbox name= C1 onclick= mySubmit(); CHECKED></p>
response = response & </form></body>
response = response & <script type= text/javascript language= javascript >
response = response & function mySubmit()
response = response & {
response = response & document.forms(0).submit();
response = response & }
response = response & </script></html>
End If
Else
response = response & <html><body>
response = response & <form name= check1 method= POST action= page.htm >
response = response & <p><input type= checkbox name= C1 onclick= mySubmit(); ></p>
response = response & </form></body>
response = response & <script type= text/javascript language= javascript >
response = response & function mySubmit()
response = response & {
response = response & document.forms(0).submit();
response = response & }
response = response & </script></html>
End If
End If
user.response.Body = response
user.response.StatusCode = OK
user.response.Send[/code]
As for Authentication, you can simply set Authentication property to authRequired, and AuthenticationType to Basic, and server will require your users to log in. Once provided, UserAuthenticate event is raised, and you can allow or deny user access.
Hope this helps.
Regards,
Damba
Re: Click in page directly send to server?
Thanks for the example.
So when the checkbox is checked (C1) then I can see that C1 is on.
However if I have several of those boxes, then I want to know which one was clicked and aspecialy also set to 'off'.
If I have C1/C2/C3/C4 on a page and C4 is checked, and the user unchecks it then I don't get that info.
As for the authentication part, does the component offer some options to give different rights to different users? Something like user.AuthenticationLevel, were I can set this and then use within my app?
Re: Click in page directly send to server?
Dirk,
This is only a simple example. You can also assign a value attribute to your checkBox and check it thru Posted vars. But it's up to you to process the request and deliver the response.
If you on the other hand don't want to actually perform a POST each time you click on a checkbox, you could use for example AJAX. That would allow you to only refresh certain parts of the page.
As for AuthenticationLevel, this isn't something that we can really implement. However, you can implement it from your point. You can check Users credentials at any time, and decide what you want to do (either allow or not, or send him an error page).
Hope this helps.
Regards,
Damba
Re: Click in page directly send to server?
So using the tag option like I can do for the SSH server component isn't possible?
I can have a class defined SSHTagClass, and within that I have 3 PUBLIC vars.
Then when I get a new connection on the SSH server I can do
user.tag = new sshtagclass
Can you elaborate on the AJAX thing?
Re: Click in page directly send to server?
Dirk,
Tag property (if that's what you're reffering to) is also available in wodWebServer for User, Request and Response objects, so you can use them for what ever purpose.
As for AJAX, you can find more information here as well as basic samples: http://www.w3schools.com/Ajax/default.asp
Regards,
Damba