[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby CGI and blank form fields

Matthew Margolis

1/30/2005 5:39:00 AM

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>
----------------------------


Thank you,
Matthew Margolis



2 Answers

Matthew Margolis

1/30/2005 11:56:00 AM

0

Please ignore this message. I sent it to the list almost two days ago
and for some reason delivery was delayed a day. I have figured out my
problem.

Thank you,
Matthew Margolis

Matthew Margolis wrote:

> 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>
> ----------------------------
>
>
> Thank you,
> Matthew Margolis
>
>



Martin DeMello

1/30/2005 12:16:00 PM

0

Matthew Margolis <mrmargolis@wisc.edu> wrote:
> Please ignore this message. I sent it to the list almost two days ago
> and for some reason delivery was delayed a day. I have figured out my
> problem.

Why not post the solution, so that the next person googling for the
issue will have a pointer.

martin