Building the contact us form
I referenced both the sweetalert and skeleton banano libraries and created the attached form using the abstract designer.
1. Add a container SKContainer, enlarge the container size
2. Add a row SKRow, drag it inside the container, name it R1
3. Add a column, SKColumn, name it R1C1, drag it inside R1 and resize appropriately
4. Add a label, SKLabel, change size to H2 and change text to Contact Us
5. Add text boxes, txtFullName, txtEmail, txtTelephone, a text area, txtMessage, a check box chkRobot and a button.
6. Each time you add a component, drag and place it inside R1C1 in the sequence of appearance.
7. Save view, generate members.
Now, when the button send is clicked, the details entered should be checked and if everything is complete, the PHP script should execute. For this we use
CallInlinePHP
Here everything is required. A sub called Required has been created to get each element text value and check if its blank. If there is something blank, required will be true. Next the checkbox
I am not a robot should be checked.
Sub btnSend_Click (event As BANanoEvent)
Dim bRequired As Boolean = Required(Array("txtfullname","txtemail","txttelephone","txtmessage"))
If bRequired Then
Dialog.Initialize(Me, "RequiredFields", "RequiredFields")
Dialog.Title = "Contact Us"
Dialog.Content = "All the fields are required!"
Dialog.ShowCancelButton = False
Dialog.Show
Return
End If
Dim robot As Boolean = chkRobot.checked
If robot = False Then
Dialog.Initialize(Me, "RequiredFields", "RequiredFields")
Dialog.Title = "Contact Us"
Dialog.Content = "You need to confirm that you are not a robot!"
Dialog.ShowCancelButton = False
Dialog.Show
Return
End If
'use php to send the email
Dim sname As String = txtFullName.text
Dim semail As String = txtEmail.text
Dim sphone As String = txtTelephone.text
Dim smsg As String = txtMessage.text
Dim nmsg As String = $"Full Name: ${sname}\r\nEmail Address: ${semail}\r\nTelephone: ${sphone}\r\nMessage:\r\n${smsg}"$
Dim se As Map = CreateMap("from":"<fromemail>", _
"to":"<toemail>", _
"cc":"<ccemail>", _
"subject":"Contact Us:" & sname, _
"msg":nmsg)
BANano.CallInlinePHP("SendEmail", se, "contactus")
End Sub
In the instances that our validation is broken, we want a sweet alert to show up. As we are not sending HTML content, we needed to have break-lines in each msg item specified. For that we used \r\n.
Come on, change the <fromemail>, <toemail> and <ccemail> to be the emails that you want to send the contact details to.
The next step is trapping the result of the Inline PHP call.
Sub BANano_CallInlinePHPResult(Success As Boolean, UniqueID As String, Result As String)
If Success Then
Dim resm As Map = Json2Map(Result)
Dim response As String = resm.Get("response")
Select Case response
Case "failure"
Dialog.Initialize(Me, "RequiredFields", "RequiredFields")
Dialog.Title = "Contact Us"
Dialog.Content = "There was an error sending the contact us details!"
Dialog.ShowCancelButton = False
Dialog.Show
Case Else
Dialog.Initialize(Me, "RequiredFields", "RequiredFields")
Dialog.Title = "Contact Us"
Dialog.Content = "The email was sent successfully!"
Dialog.ShowCancelButton = False
Dialog.Show
End Select
End If
End Sub
We did not use the wait methodology for this, so we need a trapper. As per php code above, on success we return success or failure.
So the result returned here is a JSON string {"response":"success"} or {"response":"failure"}. To get what we need we convert this to a map with a helper method (see example) and then get the response. Based on the response, we show the appropriate method.
Note: As the sending method might take time, it would be better to show a loader here.