On-Rev Webpage variable posting
Devin Asay
devin_asay at byu.edu
Tue Oct 19 13:09:39 EDT 2010
On Oct 19, 2010, at 10:31 AM, Rick Harrison wrote:
> Hi Devin,
>
> Yes, I don't want to use cookies.
>
> I tried the hidden inputs technique without success.
> I'm not sure why it didn't work. Do you have an example
> of hidden inputs so I could see what I might be doing wrong?
Rick,
Here's a simple example I put together for my class:
http://chum.dev.on-rev.com/teacher/makeReport.irev
This file uses a GET method to send data to a second file, configReport.irev. The second file in turn POSTs to a third file, displayReport.irev. File 2 has to pass along a value from File 1 to file 3, and uses a hidden input to do the job. The only reason I used GET in one form and POST in the other was to show my class an example of using each one. You can use all GETs or all POSTs if you want.
Here's the relevant section from makeReport.irev:
<p>
Select the Report Area:
</p>
<form action="configReport.irev" method="get" name="choosetable">
<p>
<select name="choice">
<option label="People" value="people"/>People
<option label="Departments" value="department"/>Departments
</select>
</p>
<p>
<input name="Go" type="submit" />
</p>
Here is the relevant stuff from configReport.irev. The "choice" input is hidden, and passes the value along from the form in makeReport.irev.
<?rev
set the errormode to "inline" -- this is useful for debugging
function q pString
return quote & pString & quote
end q
put $_GET["choice"] into tWhich
put "<p>Configure your " & tWhich & " report:</p>" & return
put "<div>" & return
put "<form method=" & q("post") & " action=" & q("displayReport.irev") & ">" & return
put "<p>Include the following information:</p>" & return
if tWhich is "people" then
put "<p><input name=" & q("dept") & " type=" & q("checkbox") & " value=" & q("yes") & " />Department </p>" & return
put "<p><input name=" & q("phone") & " type=" & q("checkbox") & " value=" & q("yes") & " />Phone Number </p>" & return
put "<p><input name=" & q("office") & " type=" & q("checkbox") & " value=" & q("yes") & " />Office </p>" & return
else if tWhich is "department" then
put "<p><input name=" & q("supervisor") & " type=" & q("checkbox") & " value=" & q("yes") & " />Supervisor </p>" & return
put "<p><input name=" & q("phone") & " type=" & q("checkbox") & " value=" & q("yes") & " />Dept. Phone Number </p>" & return
put "<p><input name=" & q("office") & " type=" & q("checkbox") & " value=" & q("yes") & " />Office </p>" & return
end if
put "<input name=" & q("choice") & " type=" & q("hidden") & " value=" & q(tWhich) & " />" & return
put "<p><input name=" & q("submit") & " type=" & q("submit") & " value=" & q("Create Report") & " />"
put "</form>"
put "</div>"
?>
Finally, here is the relevant excerpt from displayReport.irev, with database login info sanitized:
<?rev
set the errormode to "inline"
function q pString
return quote & pString & quote
end q
put $_POST["choice"] into tWhich
if tWhich is "people" then
put $_POST["dept"] into tIncludeDept
put $_POST["phone"] into tIncludePhone
put $_POST["office"] into tIncludeOffice
put "SELECT fname,lname" into tQuery
put "<th>First name</th><th>Last name</th>" into tHeader
if tIncludeDept <> empty then
put comma & "dept" after tQuery
put "<th>Department</th>" after tHeader
end if
if tIncludePhone <> empty then
put comma & "phone" after tQuery
put "<th>Phone</th>" after tHeader
end if
if tIncludeOffice <> empty then
put comma & "office" after tQuery
put "<th>Office</th>" after tHeader
end if
else if tWhich is "department" then
put $_POST["supervisor"] into tIncludeSuper
put $_POST["phone"] into tIncludePhone
put $_POST["office"] into tIncludeOffice
put "SELECT name" into tQuery
put "<th>Dept name</th>" into tHeader
if tIncludeSuper <> empty then
put comma & "supervisor" after tQuery
put "<th>Supervisor</th>" after tHeader
end if
if tIncludePhone <> empty then
put comma & "phone" after tQuery
put "<th>Phone</th>" after tHeader
end if
if tIncludeOffice <> empty then
put comma & "office" after tQuery
put "<th>Office</th>" after tHeader
end if
end if
put " FROM " & tWhich after tQuery
# create database connection
put tQuery & "<br />" --debugging
put revOpenDatabase("mysql","my.server.com","acmeco",\
"username","password") into tConnID
put revDataFromQuery(,,tConnID,tQuery) into tReport
revCloseDatabase tConnID
put "<table border='1' cellpadding='4'>" & return
put "<tr>" & tHeader & "</tr>" & return
set the itemDelimiter to tab
repeat for each line tLine in tReport
replace tab with "</td><td>" in tLine
put "<tr><td>" & tLine & "</td></tr>" & return after tFormattedRept
end repeat
put tFormattedRept
put "</table>"
?>
Hope you find this helpful.
Regards,
Devin
Devin Asay
Humanities Technology and Research Support Center
Brigham Young University
More information about the use-livecode
mailing list