W
Will H.
Hi,
I am having problems trying to get input from a html form and write the
form data to a text file called visitor_log.
Here's the code I have been working on:
login.rb:
#!/usr/local/ruby/bin/ruby
require "cgi"
cgi = CGI.new("html4Tr")
cgi.out{
cgi.html{
cgi.head{ "\n"+cgi.title{"Formula 1 Shop - Register"} } +
cgi.body{ "\n"+
cgi.form("post", "file.rb"){"\n"+
cgi.h1 { "Formula 1 Shop" } + "\n"+
cgi.h2 { "Register" } + "\n"+
cgi.p { "Username:" } + "\n"+
cgi.text_field("username") +"\n"+
cgi.p { "Password:" } + "\n"+
cgi.password_field("password") +"\n"+
cgi.p { "Email address:" } + "\n"+
cgi.text_field("email") +"\n"+
cgi.p { "Age:" } + "\n"+
cgi.text_field("age") +"\n"+
cgi.p { "Gender:" } + "\n"+
cgi.radio_group("gender", "Male", "Female") +"\n"+
cgi.br +
cgi.br +
cgi.submit
}
}
}
}
file.rb:
#!/usr/local/ruby/bin/ruby
require 'cgi'
cgi = CGI.new
time1 = Time.new
forename = cgi.text_field("username")
password = cgi.password_field("password")
email = cgi.text_field("email")
age = cgi.text_field("age")
gender = cgi.radio_group("gender")
open('../logs/visitor_log', 'a') { |f|
f.puts forename
f.puts password
f.puts email
f.puts age
f.puts gender
f.puts time1.inspect
}
I am having problems trying to get input from a html form and write the
form data to a text file called visitor_log.
Here's the code I have been working on:
login.rb:
#!/usr/local/ruby/bin/ruby
require "cgi"
cgi = CGI.new("html4Tr")
cgi.out{
cgi.html{
cgi.head{ "\n"+cgi.title{"Formula 1 Shop - Register"} } +
cgi.body{ "\n"+
cgi.form("post", "file.rb"){"\n"+
cgi.h1 { "Formula 1 Shop" } + "\n"+
cgi.h2 { "Register" } + "\n"+
cgi.p { "Username:" } + "\n"+
cgi.text_field("username") +"\n"+
cgi.p { "Password:" } + "\n"+
cgi.password_field("password") +"\n"+
cgi.p { "Email address:" } + "\n"+
cgi.text_field("email") +"\n"+
cgi.p { "Age:" } + "\n"+
cgi.text_field("age") +"\n"+
cgi.p { "Gender:" } + "\n"+
cgi.radio_group("gender", "Male", "Female") +"\n"+
cgi.br +
cgi.br +
cgi.submit
}
}
}
}
file.rb:
#!/usr/local/ruby/bin/ruby
require 'cgi'
cgi = CGI.new
time1 = Time.new
forename = cgi.text_field("username")
password = cgi.password_field("password")
email = cgi.text_field("email")
age = cgi.text_field("age")
gender = cgi.radio_group("gender")
open('../logs/visitor_log', 'a') { |f|
f.puts forename
f.puts password
f.puts email
f.puts age
f.puts gender
f.puts time1.inspect
}