Forum Moderators: open

Message Too Old, No Replies

submitting 2 forms from one page

submit one form to a custom script, one to autoresponder - from same page

         

jacosta000

8:44 pm on Oct 21, 2008 (gmt 0)

10+ Year Member



Hello,

I have 2 forms on one html page. The main form is supposed to be submitted to our email autoresponder (IContact) and the secondary form is supposed to be submitted to a custom php page I created.

Both forms have pretty much the same fields. I created a function that runs when the onSubmit event is triggered for the main form. In that function, I set the values of the secondary form fields to be the same as the main form like this:
"document.mainForm.name.value=document.secondaryForm.name.value;"

At the end of the function, I do a "document.secondaryForm.submit();", which is supposed to submit the secondary form's values to a php page I created that writes the values to a text file(delimited by tabs). Once the form is submitted, I return true(if everything validates correctly), which should submit the main form. Unfortunately, I can get the secondary form to submit to my custom php page ONLY if the main form is not set to submit to anywhere.

I was under the impression that I could submit the seconary form programatically, and still have the main form submit if the onSubmit event's function returned true. It seems I may be mistaken and that only one form may be submitted from a page? If that's the case, then is there a way to actually get this to work (maybe some snazzy ajax magic?)?

Any help I can get on this would be greatly appreciated.

Thanks!

Demaestro

8:51 pm on Oct 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Instead of doing it that way would it make sense for you to post the same form to 2 different places?

If so you can do that with Ajax.

jacosta000

8:56 pm on Oct 21, 2008 (gmt 0)

10+ Year Member



that would probably be worthwhile. Can you point me to any ajax resources that explain this? Unfortunately, I am not very familiar with ajax.

So do you know if submitting a form through an onSubmit event function of another form even works? I'm wondering if maybe I'm just doing it wrong. I guess I could understand why it won't work AND why it should.

Demaestro

9:19 pm on Oct 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The way it works is you use a submit button to submit the form to one location and you use the onSubmit command in the form tag to submit it a second time.

<form id="order_form" METHOD="POST" ACTION="http://example.com/POST1" onsubmit="Spry.Utils.submitForm('order_form', '',{method:'post', url:'http://example.com/POST2', async:false});"

<input type="text" name="formField" value="" />

<input type="submit" value="Submit" />
</form>

This form will submit to http://example.com/POST1 as defined in the ACTION attribute and it will post to http://example.com/POST2 as defined in onSubmit.

This example is using the Adobe Spry Ajax library which is still in a pre-release but is stable and I have been using it with great results.

You can get it here:
[labs.adobe.com...]

If you have any question let me know.

[edited by: Demaestro at 9:20 pm (utc) on Oct. 21, 2008]

jacosta000

2:28 pm on Oct 22, 2008 (gmt 0)

10+ Year Member



thanks for the response. That is exactly what I'm trying to do. I just got Dreamweaver CS4 and I'm very new to Spry, but apparently Dreamweaver is supposed to automate this stuff. Unfortunately, I don't see anything in Dreamweaver about a Spry form submit. The code you provided doesn't work, but I'm assuming I need to point to a framework file or 2. An example on the Adobe site pointed to SpryData.js and SpryUtils.js. Do I need both of these?

jacosta000

3:52 pm on Oct 22, 2008 (gmt 0)

10+ Year Member



ok, so apparently I'm missing something...
the form posts to the url specified by the action attribute, but it's not being posted to the url referenced in the Spry call. Any thoughts?

Here's the form tag I'm using:
<form id="formContact" name="formContact" method="post" action="http://app.icontact.com/icp/signup.php" onsubmit="Spry.Utils.submitForm('formContact', '',{method: 'post', url:'http://www.myDomain.com/processForm.php', async:false});">

and I'm referencing these two js files:
<script src="/js/spry/SpryData.js" type="text/javascript"></script>
<script src="/js/spry/SpryDOMUtils.js" type="text/javascript"></script>

The spry demo at [labs.adobe.com...] has an example that submits a form and references SpryData.js and SpryUtils.js. I could not find SpryUtils.js with all of my other spry files that were installed with Dreamweaver, so I figured SpryDOMUtils.js would work instead.

Any idea where I'm going wrong?

Thanks!