StructkeyExists with form id

45 views
Skip to first unread message

Chris Pfeffer

unread,
Dec 10, 2009, 9:37:08 AM12/10/09
to Railo
Can anyone verify this for me?  When I run the following code, the structKeyExists never runs.  Remove the jquery stuff, still doesn't run.  Once I remove id="myForm", it runs.  Any ideas?

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://jquery.malsup.com/form/jquery.form.js?2.36"></script>

<cfsetting enablecfoutputonly=true>
<cfoutput>
   
    <script type="text/javascript">
        // wait for the DOM to be loaded
        $(document).ready(function() {
            // bind 'myForm' and provide a simple callback function
            $('##myForm').ajaxForm(function() {
                var el = $('input[type=file]').val();
                $('##message').html("File name:" + " " + el + " " + "uploaded")
                //alert("You have successfully upload:" + el);
            });
        });
    </script>

<div id="message"></div>

<cfif structKeyExists(form, "submit_btn")>
    CF Check
</cfif>

<form id="myForm" enctype="multipart/form-data" method="post">
<input type="file" name="myFileUpload" /><br />
<input type="submit" value="Upload File" id="submit_btn" />
</form>
</cfoutput>

<cfsetting enablecfoutputonly=false>

Todd Rafferty

unread,
Dec 10, 2009, 9:45:38 AM12/10/09
to ra...@googlegroups.com
It's not going to. You're not submitting the page. The form plug-in is creating an iframe and doing everything behind the scene. The calling page has no reference of anything being submitted since it's all being submitted via a hidden iframe, you have to use jQuery to "add to the existing dom" - like you did with $('#message').

~Todd Rafferty ** Volunteer Railo Open Source Community Manager ** http://getrailo.org/

Todd Rafferty

unread,
Dec 10, 2009, 9:47:16 AM12/10/09
to ra...@googlegroups.com

And, even after removing jQuery, you need to provide an action for your form.

Example:
<form id="myForm" action="#cgi.script_name#" enctype="multipart/form-data" method="post">


~Todd Rafferty ** Volunteer Railo Open Source Community Manager ** http://getrailo.org/



Chris Pfeffer

unread,
Dec 10, 2009, 9:47:53 AM12/10/09
to ra...@googlegroups.com
Right, but if I do this:


<cfif structKeyExists(form, "submit_btn")>
    CF Check
</cfif>

<form id="myForm" enctype="multipart/form-data" method="post">
<input type="file" name="myFileUpload" /><br />
<input type="submit" value="Upload File" id="submit_btn" />
</form>

It still doesn't work.  If I remove id="myForm" it does.

Chris

On Thu, Dec 10, 2009 at 9:45 AM, Todd Rafferty <to...@getrailo.org> wrote:

--

You received this message because you are subscribed to the Google Groups "Railo" group.
To post to this group, send email to ra...@googlegroups.com.
To unsubscribe from this group, send email to railo+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/railo?hl=en.

James Allen

unread,
Dec 10, 2009, 9:54:03 AM12/10/09
to ra...@googlegroups.com

This is browser dependent I think.

 

You need a name="submit_btn" on the submit button input tag to ensure it's passed in the form scope.

 

---

James  Allen

E: ja...@jamesallen.name

Blog: http://jamesallen.name

Twitter: @CFJamesAllen (Coldfusion / Web development)

Twitter: @jamesallenuk (General)

Lead developer of http://errrrrrr.com

Randy

unread,
Dec 10, 2009, 9:52:51 AM12/10/09
to Railo
What happens if you dump out the form scope? What does it show when
you submit it? I'm pretty sure that id's don't get submitted as part
of the form submission. If you changed it to: <input type="submit"
value="Upload File" name="submit_btn" /> then your structKeyExists()
should work just fine. But you should probably do some dumps and see
what is actually getting sent.

Randy

Todd Rafferty

unread,
Dec 10, 2009, 9:54:38 AM12/10/09
to ra...@googlegroups.com
That would help too. :)  If you dump the form scope, you'll see your existing code is only passing "myFileUpload"

Chris Pfeffer

unread,
Dec 10, 2009, 10:07:49 AM12/10/09
to ra...@googlegroups.com
Adding the name="submit_btn" did the trick.  Thanks all.

Peter Boughton

unread,
Dec 10, 2009, 10:29:08 AM12/10/09
to ra...@googlegroups.com
Get Firebug!

It allows you to inspect the jQuery AJAX request and see the url/form
parameters that are sent in and the response the server sends back.
Reply all
Reply to author
Forward
0 new messages