B4J Question How to use mailto in a Webview

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi All,

I have defined a webview and load a form with fields, send and clear button. Javaobject is used to load the html code.

When clicking on the clear button, the fields are cleared (after data has been entered) as expected, but when clicking on send (which executes mailto) nothing happens.

Q: How to send an email via mailto within a form in the webview.

Testproject attached.
 

Attachments

  • b4jhowtowebview.zip
    1.9 KB · Views: 300

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Why is the JavaScript code required here?
2. I think that it will be better to move the html to a file and then read it from the file.
3. You can use double quotes instead of chr(34).
4. You can handle the LocationChanged event. It will include all of the form data. You will need to parse it and url decode it (StringUtils):
B4X:
Sub Process_Globals
   Dim CAPPTITLE As String    = "B4JHowToWebView"
   Dim CAPPVERSION As String    = "v20140207"
   Dim CAPPCOPYRIGHT As String = "Copyright (c) 2014 by Robert W.B. Linn, Pinneberg, Germany, www.rwblinn.de"

   Private fx As JFX
   Private MainForm As Form
   Private wvwMain As WebView
   Private lblAbout As Label
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("B4JHowToWebView")
   MainForm.Resizable = False             ' Toolbox like window
   MainForm.SetFormStyle("UTILITY")         ' Must be set prior show
   MainForm.Show
   MainForm.Title = CAPPTITLE
   '
   AppInit
   
End Sub

Sub AppInit
   ' Set about label at the bottom pane
   lblAbout.Text = CAPPTITLE & " " & CAPPVERSION & ", " & CAPPCOPYRIGHT
   '
   loadForm
End Sub

Sub loadForm
   Dim sb As StringBuilder
   sb.Initialize
   sb.Append("<body>" & CRLF)
   sb.Append("<H1>Feedback to Rob</H1><HR>")
   sb.Append("<form action=""mailto:robert@rwblinn.de"" method=""get"" enctype=""text/plain"">")
   sb.Append("  <p>Name: <input type=""text"" name=""name"" value=""YourName"" /></p>")
   sb.Append("  <p>Email: <input type=""text"" name=""email"" value=""your@email"" /></p>")
   sb.Append("  <p>Comments:<br />")
   sb.Append("  <textarea cols=""30"" rows=""10"" name=""comments""></textarea></p>")
   sb.Append("  <p><input type=""submit"" name=""submit"" value=""Send"" />")
   sb.Append("  <input type=""reset"" name=""reset"" value=""Clear Form"" /></p>")
   sb.Append("</form> ")
   sb.Append("</body>" & CRLF)
   wvwMain.LoadHtml(sb.ToString)
End Sub

Sub wvwMain_LocationChanged (Location As String)
   Log(Location)
End Sub
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi Erel,

thanks for the hints. It shows again the flexibility of B4J - very good.

Have extended LocationChanged using DecodeURL and use fx.showexternaldocument to sent the form:

B4X:
Sub wvwMain_LocationChanged (Location As String)
  Dim suLocation As StringUtils
  Dim strDecodeUrl As String
  strDecodeUrl = suLocation.decodeUrl(Location, "UTF8")
  fx.ShowExternalDocument(strDecodeUrl)
End Sub
 
Upvote 0
Top