1

I have Html form like this :

<form action="https:..." method="post">
    <input name=".." value=".." type="hidden"/>
    <input name=".." value=".." type="hidden"/>
    <input name=".." value=".." type="hidden">
    <input name=".." value="nil" type="hidden"/>
    <input name=".." value=".." type="hidden"/>
    <input name=".." value=".." type="hidden"/>
    <input name=".." value=".." type="hidden">
    <input type=".." value="PPP" style="background: #3aaf42; border: none; color: #fff; text-align: center; width: 100px; padding: 5px; margin: -15px 0 0 -50px; display: block; top: 50%; border-radius: 3px; position: absolute; left: 50%;\"/>
</form>

This form I want to display in UIWebView

Im try to put it on URL

let myURL = URL(string: "<form...")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)

But can't, help me please

3
  • Must be use webView.loadHTMLString("<form...", baseURL: nil) Commented May 6, 2018 at 8:34
  • @a.masri It does not help, because it have many "" and xCode show error Commented May 6, 2018 at 8:37
  • I'm add answer see her Commented May 6, 2018 at 8:54

1 Answer 1

2

try this

1) Edit string same this

If you use the swift 4 version or above you can use this

        var myHtml  = """
<form action="https:..." method="post">
        <input name=".." value=".." type="hidden"/>
        <input name=".." value=".." type="hidden"/>
        <input name=".." value=".." type="hidden">
        <input name=".." value="nil" type="hidden"/>
        <input name=".." value=".." type="hidden"/>
        <input name=".." value=".." type="hidden"/>
        <input name=".." value=".." type="hidden">
        <input type=".." value="PPP" style="background: #3aaf42; border: none; color: #fff; text-align: center; width: 100px; padding: 5px; margin: -15px 0 0 -50px; display: block; top: 50%; border-radius: 3px; position: absolute; left: 50%;\"/>
        </form>
"""

If you use less than swift 4 you can use this

    var myHtml  = "<form action=\"https:...\" method=\"post\">" +
     "<input name=\"..\" value=\"..\" type=\"hidden\"/>" +
    "<input name=\"..\" value=\"..\" type=\"hidden\"/>" +
    "<input name=\"..\" value=\"..\" type=\"hidden\">" +
    "<input name=\"..\" value=\"nil\" type=\"hidden\"/>" +
    "<input name=\"..\" value=\"..\" type=\"hidden\"/>" +
    "<input name=\"..\" value=\"..\" type=\"hidden\"/>" +
    "<input name=\"..\" value=\"..\" type=\"hidden\">" +
    "<input type=\"..\" value=\"PPP\" style=\"background: #3aaf42; border: none; color: #fff; text-align: center; width: 100px; padding: 5px; margin: -15px 0 0 -50px; display: block; top: 50%; border-radius: 3px; position: absolute; left: 50%;\\\"/>"

2) You should use

 webView.loadHTMLString(myHtml, baseURL: nil)

Not this, These are used to request url

let myURL = URL(string: "<form...")
 let myRequest = URLRequest(url: myURL!)
 webView.load(myRequest)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.