views:

42

answers:

2

Hello again stackoverflow...

Once again I have a troublesome problem. I have a page where I am using jQuery tabs to divide up three update forms. (Two really, one is a cfgrid so it doesn't really count.) Basically, when you submit the first form tab it is fine. However, if you submit the last form, it submits and refreshes the page but nothing was updated.

I've determined it has something to do with identifying which form is being submitted.

Note: These forms are being submitted to same page they are on so I am using this method:

<cfif isdefined("form.submit")>
//database stuff etc
</cfif>

I am submitting the forms by doing this at the end:

<input type="submit" name="submit" id="button"  value="Save Changes" onclick = "form.submit()" />

After determining it had something to with identifying which form is being submitted, I changed the button to be:

<input type="submit" name="submit" id="button"  value="Save Changes" onclick = "document.forms["form3"].submit()" />

I'm not sure if this is the most efficient way to do this...and I'm not sure how to specific that form3 is being submitted in the coldfusion part...I tried:

<cfif isdefined("form3.submit")>

but this doesn't work. It does not follow through the code.

Note: I'm using coldfusion 8. Also, using CFAJAX tags are limited because our ITS department didn't set up coldfusion correctly on the server...and they don't believe me. Thus I'm kind forced to do it in this ...weird way. It only support cfgrid for some weird reason...

A: 

Hah, I figured it out! You have to make the submit names different on each form.

<input type="submit" name="submitDoc" id="button"  value="Save Changes" onclick = "document.forms["form3"].submit()" />

I just changed the submit name to submitDoc

<cfif isdefined("form.submitDoc")>

Works!

Bri
Note, you don't need the `onclick` event here, since `type="submit"` with submit the parent form. Also the `id` of every element *must* be unique. (If you want to act on multiple elements, use `class` instead)
Peter Boughton
Thanks for the advice! It helped a lot! :)
Bri
+3  A: 

ColdFusion (nor any server-side language) does not know what ID your forms might have - it only knows what you submitted via input (and select/textarea/etc) fields, and puts it in the form scope.

To do what you want, you need to have forms somthing along the lines of:

<form>
    ....
    <input type="submit" name="submit1" value="Save Changes"/>
</form>

<form>
    ....
    <input type="submit" name="submit3" value="Save Changes"/>
</form>

Then on the CF side you check which form it is with:

<cfif StructKeyExists(Form,'Submit1')>
...
</cfif>

or

<cfif StructKeyExists(Form,'Submit3')>
...
</cfif>
Peter Boughton