Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Post data to form via html5
Started by akhtarx5 Dec 24 2018 06:18 PM

- - - - -
3 replies to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

akhtarx5

[GLOBAL: userInfoPane.html]
akhtarx5
  • Enthusiast

  • 63 posts
  • Corona SDK

How can i post some data to a php form,  from the html5 build online

 

 

name
lastname
email

thankyou

<!DOCTYPE html>

    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Add Record Form</title>
    </head>
    <body>
    <form action="insert.php" method="post">
        <p>
            <label for="firstName">First Name:</label>
            <input type="text" name="firstname" id="firstName">
        </p>
        <p>
            <label for="lastName">Last Name:</label>
            <input type="text" name="lastname" id="lastName">
        </p>
        <p>
            <label for="emailAddress">Email Address:</label>
            <input type="text" name="email" id="emailAddress">
        </p>
        <input type="submit" value="Submit">
    </form>
    </body>
    </html>



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,263 posts
  • Enterprise

You would use the network.request() API. See: http://docs.coronalabs.com/api/library/network/request.html#http-post-with-custom-headers

 

Instead of this line:

local body = "color=red&size=small"

change it to something like (assuming you have variables named firstName, lastName, and emailAddress):

local function urlencode( str )    if (str) then
        str = string.gsub (str, "\n", "\r\n")
        str = string.gsub (str, "([^%w ])",
        function( c ) return string.format ("%%%02X", string.byte( c ) ) end)
        str = string.gsub (str, " ", "+")
    end
    return str    
end

local body = "firstname=" .. urlencode(firstName) .. "&lastname=" .. urlencode(lastName) .. "&email=" .. urlencode(emailAddress)

You should always URL encode parameters being sent to a web form. Then on the network.request() call, just change out the URL.

 

Rob



[TOPIC: post.html]
#3

akhtarx5

[GLOBAL: userInfoPane.html]
akhtarx5
  • Enthusiast

  • 63 posts
  • Corona SDK

thanks so much



[TOPIC: post.html]
#4

stevenjacob098

[GLOBAL: userInfoPane.html]
stevenjacob098
  • Observer

  • 3 posts
  • Corona SDK

You just know about getter and setter.




[topic_controls]
[/topic_controls]