Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

add multiple links in one form

Quote Reply
add multiple links in one form
Hello,

I would like my users to be able to add multiple links in one form and choose categories using selection. I have modified the add.pm and some template files and almost got there. Users first choose how many links to add, then a add form with that number of entries will be displayed. The problem I have is the not_null check by db->add.

After submission, I put all input links in a hash ref and then add each link into database through a loop. However, if some link in the middle of the hash gets a blank field that should be not_null, and the db->add returns a error and a add_error page is returned, you can not just simple go back to correct the error and resubmit because there are links that have already been added to the database. If you resubmit, you will get duplicate links. My question is

Should I check the completeness of submission using my own code before calling db->add?

Or is there any db method to test not_null before actually db->add?

Or is there any better strategy for this?

Thank you in advance.

Long
Quote Reply
Re: [long327] add multiple links in one form In reply to
Thank you for reading.

I have figured out a way of doing it. I just add those links that are OK into the database and then display the successfully added, with those that are problematic in a form letting the user to correct and resubmit them.

Long
Quote Reply
Re: [long327] add multiple links in one form In reply to
In Reply To:
I have figured out a way of doing it.

Can you be more specific? This would be a nice feature.

Thanks Smile

------------------------------------------
Quote Reply
Re: [long327] add multiple links in one form In reply to
I would suggest in your loop consider each "link" a separate add. You capture the success/error code on each insert, and trap them.

If one fails, move that hash to an "error" hash, then after the insert, present the page with "The following links were successfully added", and below that, "The following links had problems, correct them, and resubmit."

You can return a loop array, and the template parser would do all the work.


PUGDOG´┐Ż Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [DogTags] add multiple links in one form In reply to
In Reply To:
In Reply To:
I have figured out a way of doing it.

Can you be more specific? This would be a nice feature.

Thanks Smile


Basically, I just generate a form so users can fill in multiple links. Once the form is submitted the program check for errors such as empty field for title, URL etc. and add those links without problem into database. The next page will combine the success and error page, and display links already added to the db and error links in a form so the user can correct the errors and resubmit.

Later I thought it may be better to just provide a text area and ask users to paste tab delimited text containing multiple links (or read from a user's file) into the box and the program will parse the input and add to the db. This will save users a lot of pain filling out individual boxes. But the problem is the category. Users have to copy exact category phrases from my site and paste into their files. Although I can provide a file showing category ID matched to category name so users can just use ID number for category in their file, I hesitate to do this because I don't want to expose my whole directory to my users.