I am developing a website which needs to contain functionality in which the user has to enter multiple pieces of data that end up being one large document. Imagine that I am designing a system for resume generation, where a resume is like 5+ pages long. The user logs into the site and then has to enter in all the information his/her resume would contain, and at the end of the process there is a “generate” button, in which the user gets a link to a PDF.
Instead of using one huge form, I setup the system in three parts, kinda like this
www.mysite.com/user-name/resume/1
<FORM> enter some info </FORM>
www.mysite.com/user-name/resume/2
<FORM> enter some more info </FORM>
www.mysite.com/user-name/resume/3
enter final information
Finally, you would get redirected to
http://www.mysite.com/user-name/mypdf
which has the link to the pdf (or displays the pdf)
I am storing all my information in MongoDB because it is so awesome, but given this system, I have the following questions about design.
1) Since the resume data gets saved in the form of 3 different form posts, I need to call save three different times to MongoDB (is there another way?). Right now, the best way I can think of to correlate all of the pieces of the resume is by inserting a UUID into the session between posts and saving this UUID with every piece of the resume in the database. That way, when it is time to generate, I just query the DB for
db.resumes.find({‘docid’ : uuid’}) and I can get all the pieces, and construct the resume
Question: Is saving this UUID in the session the best way to resolve this issue when you have multiple pieces of correlated data coming in different form posts. If more clarification is needed I understand.
I have no clue where to do the redirects because I am using ajax. I am used to handling re-directs in Django views, but I am not using Django Forms or Models for this system. My question is, how do I handle the following redirects:
http://www.mysite.com/user-name/resume/1 -> http://www.mysite.com/user-name/resume/2 -> http://www.mysite.com/user-name/resume/3 -> http://www.mysite.com/user-name/mypdf
Currently, I make sure all of the post data is correct, send it to the server via ajax, and if I was able to successful save this data to MongoDB, I use this:
$(location).attr(‘href’,”www.mysite.com/user-name/resume/1/”);
I KNOW this is the wrong way to handle the redirects, because it just appends to the current URL (But it works, so…). As far as I can tell, I the redirect needs to be done client side, but I am not sure what the best way to do this is.
Thanks
If you already use jquery then I would recommend to have only one form with all fields and use a plugin to split it into multiple sub-forms. I use stepy for that. Or you can implement the similar functionality yourself.
Having only one form you can use a regular POST request to send the data to the server and get the redirect response.