Vous êtes sur la page 1sur 10

Ring Documentation, Release 1.

The Response
#!c:\ring\bin\ring.exe -cgi
Load "weblib.ring"
Import System.Web
New Page
{
boxstart()
text( "Post Result" )
newline()
boxend()
divstart([ :style = styleFloatLeft()+styleWidth("200px") ])
newline()
text( "Number1 : " + aPageVars["Number1"] )
newline() newline()
text( "Number2 : " + aPageVars["Number2"] )
newline() newline()
text( "Sum : " + (0 + aPageVars["Number1"] + aPageVars["Number2"] ) )
newline()
divend()
}

Screen Shot:

48.6. HTTP POST Example 355


Ring Documentation, Release 1.5

48.7 Upload Files

The Page User Interface


#!c:\ring\bin\ring.exe -cgi
Load "weblib.ring"
Import System.Web
New page
{
boxstart()
text( "Upload File" )
newline()
boxend()
for x = 1 to 3 newline() next
formupload("ex9.ring")
text( "Customer Name : " )
textbox([ :name = "custname" ])
newline() newline()
divstart([ :style = styleFloatLeft() + styleWidth("90px") ])
uploadfile("file") newline() newline()
uploadfile("file2") newline() newline()
submit([ :value = "Send" ])
divend()
formend()
}

Screen Shot:

48.7. Upload Files 356


Ring Documentation, Release 1.5

The Response
#!c:\ring\bin\ring.exe -cgi
Load "weblib.ring"
Import System.Web

cUploadPath = "C:/Apache2.2/htdocs/ringapp/upload/"
cUploadFolder = "/ringapp/upload/"

New page
{
boxstart()
text( "Upload Result" )
newline()
boxend()
newline()
divstart([ :style= styleFloatLeft() + styleWidth("100px") ])
text( "Name : " + aPageVars["custname"] )
newline()
divend()
if aPageVars["file"] != char(13)
getuploadedfile(self,"file")
ok
if aPageVars["file2"] != char(13)
getuploadedfile(self,"file2")
ok
}

Func getuploadedfile oObj,cFile


# here we use object.property
# instead of object { } to avoid executing braceend method
cFileName = cUploadPath + oObj.getfilename(aPageVars,cFile)

48.7. Upload Files 357


Ring Documentation, Release 1.5

write(cFileName,aPageVars[cFile])
system("chmod a+x "+cFileName)
oObj.newline()
oObj.text( "File "+cFileName+ " Uploaded ..." )
oObj.newline()
imageURL = cUploadFolder+oObj.getfilename(aPageVars,cFile)
oObj.link([ :url = imageURL, :title = "Download" ])
oObj.newline()
oObj.image( [ :url = imageURL , :alt = :image ] )
oObj.newline()

Screen Shot:

48.7. Upload Files 358


Ring Documentation, Release 1.5

48.8 Cookies

The Page User Interface


#!c:\ring\bin\ring.exe -cgi
Load "weblib.ring"

48.8. Cookies 359


Ring Documentation, Release 1.5

Import System.Web

New page
{
boxstart()
text( "Cookie Test" )
newline()
boxend()
newline()
link([ :url = "ex11.ring", :title = "Use Cookies" ])
cookie("custname","Mahmoud Fayed")
cookie("custage",28)
}

Screen Shot:

The Response
#!c:\ring\bin\ring.exe -cgi
Load "weblib.ring"
Import System.Web

New Page
{
boxstart()
text( "Cookies Values" )
newline()
boxend()
link([ :url = "ex10.ring", :title = "back" ])
newline()
divstart([:style="float:left;width:200px"])
text( "Name : " + aPageVars["custname"] )
newline()
text( "Age : " + aPageVars["custage"] )
newline()
divend()
}

Screen Shot:

48.8. Cookies 360


Ring Documentation, Release 1.5

48.9 URL Encode

The Page User Interface


#!c:\ring\bin\ring.exe -cgi
Load "weblib.ring"
Import System.Web

New Page
{
boxstart()
text( "URLEncode" )
newline()
boxend()
link([ :url = "ex5.ring?Name="+URLEncode("-*{Mahmoud}*-")+
"&Address=Egypt&Phone=123456&Age=28&Notes=Programmer",
:title = "Test URL Encode" ])
}

Screen Shot:

Screen Shot:

48.9. URL Encode 361


Ring Documentation, Release 1.5

48.10 Templates

Using Templates we can write Ring code inside HTML files


Syntax:
<%= Ring Expression %>
<% Ring Statements %>

The HTML Code


<h1>Listing Numbers</h1>
<table>
<tr>
<th> <%= myheader.cColumn1 %> </th>
<th> <%= myheader.cColumn2 %> </th>
<th></th>
<th></th>
<th></th>
</tr>
<% for x in aNumbers %>
<tr>
<td> <%= x.nValue %> </td>
<td> <%= x.nSquare %> </td>
</tr>
<% next %>
</table>

The Ring Code


#!c:\ring\bin\ring.exe -cgi
Load "weblib.ring"
Import System.Web

New NumbersController { start() }

48.10. Templates 362


Ring Documentation, Release 1.5

Class NumbersController

MyHeader aNumbers

Func Start

MyHeader = New Header


{
cColumn1 = "Number" cColumn2 = "Square"
}

aNumbers = list(20)

for x = 1 to len(aNumbers)
aNumbers[x] = new number
{
nValue = x nSquare = x*x
}
next

cTemp = Template("mynumbers.html",self)

New Page
{
boxstart()
text( "Test Templates" )
newline()
boxend()
html(cTemp)
}

Class Header cColumn1 cColumn2


Class Number nValue nSquare

Screen Shot:

48.10. Templates 363


Ring Documentation, Release 1.5

48.11 HTML Special Characters

The text() function display HTML special characters.


If you want to write html code, use the html() function.

48.11. HTML Special Characters 364

Vous aimerez peut-être aussi