check form parameters

  • Thread starter MATTHEW REUBEN MARGOLIS
  • Start date
M

MATTHEW REUBEN MARGOLIS

What would be the best way to check if a user enters a value into a form
using ruby cgi?

I have some code that should only run if the user is uploading a file
but nil tests and key tests don't seem to prevent the code from
executing even if they don't upload anything.

two things I have tried(that didn't work) can be found below. Perhaps I
am missing something obvious?

if cgi.has_key?('upload')
#stuff to do if there is an image to upload
end

unless cgi.params['upload'].first.nil?
#stuff to do if there is an image to upload
end


Here is the form itself
--------------------
<FORM ENCTYPE="multipart/form-data" action="imageadmin.rb" method="post">
<%imageArray.length.times do |count|%>
<img src="<%=imageArray[count]%>">
<BR />
Comment:<input type="text" name="comment"
value="<%=commentArray[count]%>">
<BR />
Number:<input type="text" name="order"
value="<%=imageArray[count][0..2] %>">
<BR />
Delete:<input type="checkbox" name="delete"
value="<%=imageArray[count]%>">
<BR />
<%end%>
<BR />
<BR />
<input type="file" name="upload">
Comment:<input type="text" name="uploadcomment" value="">

<BR />
<input type="submit" value="Submit">
</FORM>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top