Solved

ajax form in form

Posted on 2011-03-06
3
238 Views
Last Modified: 2012-06-27
Hi,

I'm using a form that enables users to select an image, the image is automatically submitted in the background (AJAX) to the server and resized and shown to the user, see: http://www.zurb.com/playground/ajax_upload

However, I would like to use this form/functionality within another form. Currently I'm using CSS to absolutely place the Ajax form over the other form. But this is not ideal because when server side checks of the form fail, the form error is shown above the form and the absolute position of the AJAX form isn't correct.

Any ideas?
0
Comment
Question by:Dennie
  • 2
3 Comments
 
LVL 50

Expert Comment

by:Steve Bink
Comment Utility
Put the AJAX form inside the normal form and use javascript to control the values before the normal form is submitted, or blank them inside the AJAX return functions.  That will keep the image from being uploaded twice.  Make sure the AJAX form is using input="button" and the onclick event, not input="submit".
0
 

Author Comment

by:Dennie
Comment Utility
do you have an example?
0
 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
Comment Utility
I was going to make one for you, but my work load has not allowed me the opportunity.  The concept is pretty simple, assuming you are already familiar with AJAX and javascript.

If you have a single form, all of the controls will be submitted when a user clicks the submit button.  Any controls not populated, however, will not be populated on the server side either.  For the "main" form's submit button, attach an onclick event that de-populates the controls you do not want to submit.  The AJAX form's submit button should already be configured in such a way that it does not submit the form, but instead calls the AJAX initiation functions/methods you have defined.

An alternative method, which I described in my last post, is to have the AJAX return-handling functions clear the controls.  When you click the submit button on the AJAX portion of the form, it calls a javascript function to fire off an XMLHTTPRequest.  That request can have a function reference to call when the response is returned from the server.  That function should handle any useful return it receives, then clear the values of all the appropriate controls, such as the file control.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to count occurrences of each item in an array.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now