Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Category specific Add Link problems (multiple include_form.html)

Quote Reply
Category specific Add Link problems (multiple include_form.html)
Problems with multiple Add Link forms.

I am trying to impliment multiple Add Link forms such that users must
choose a category to Add their link to BEFORE being shown an Add Link form.
I am restricting the category dropdown menu to the categories below the
category that the user has chosen.

I have tried using the many examples found throughout the boards, nothing
seems to quite fit what I am trying to do, or the example doesn't work.

What I am doing is passing a Category ID to add.cgi. So when calling
add.cgi I can display a different Add Form for each main category.
When calling add.cgi with no parameter, it displays the add.html page
asking you to "Select A Category for your Link". The hyperlinks
on this page link to add.cgi?ID=1, add.cgi?ID=2, add.cgi?ID=3, etc...

The problem is dealing with ID as a parameter when submitting form.

Problem: Errors (for req form fields) display on a separate page.
Errors should diplay above the form allowing corrections to be made.
I fix this by adding a hidden form field "ID" with a value of "<%ID%>".
Now errors for missing data show above form like they should, but I
now get an error when submitting the form:
Failed to execute query: 'INSERT INTO lsql_Links (ID,Contact_Name,isPopular,
Status,Contact_Email,ExpiryDate,Mod_Date,State,Title,Votes,Add_Date,isChanged,
Hits,URL,ExpiryCounted,Rating,isNew,LinkOwner,isValidated,Description,Timestmp,
Longitude,ExpiryNotify,Music_Style,Zip,Location,Latitude)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW(),?,?,?,?,?,?)':
Duplicate entry '3' for key 1

It says "Duplicate ID 3". Well, it is because I just added a hidden
field (ID=3), so I get duplicate error. I almost understand.
It is like when submitting the form, "ID" should be "unset" or cleared,
but when checking parameter data (required fields) ID needs to be set,
or else Errors show on a separate page, and I am back to the beginning.

I have gone back and forth, and round and round on this one.
I tried using a differnt parameter name than ID (add.cgi?incat=1),
which results same as setting hidden field ID to "" and the errors
show on a different page (but links do get added, no dup entry error).

So, in add.html I have:


Code:

<div id="content">

<div
class="crumb"><%Links::Utils::format_title($main_title_loop,
separator => $crumb_separator, no_escape_separator =>
$no_escape_crumb_separator, include_home => 1, link_type =>
2)%></div>
<%if $ID ==''%>
No incat specified
<%set split = Links::Utils::column_split($main_categories_loop.length, $home_category_cols)~%>
<h2>Select a Category for your link.</h2>
<div id="box" class="clear">
<%main_categories%>
<%loop main_categories_loop%>
<%~set splitmod = $row_num % $split%>
<%~if row_num == 1 or splitmod == 1 or split == 1%><dl><%endif%>
<p class="category"><a href="<%config.db_cgi_url%>/add.cgi?ID=<%ID%>"><%Full_Name%></a>
<%if Description%><div id="desc"><%Description%></div><%endif%></p>
<%~if row_num == $main_categories_loop.length or splitmod == 0%></dl><%endif%>
<%~endloop%>
</div>

<%else%>
<h2>Submit your site to the <%cat_name ($ID) %> category</h2>
<p>Please completely fill out the form...</p>

<form action="<%config.db_cgi_url%>/add.cgi" enctype="multipart/form-data" method="post">
<%if $ID == 1%>
<%include include_form1.html%>
<%else%>
<%include include_form.html%>
<%endif%>
<div class="formsubmit">
<%-- <input type="hidden" name="ID" value="" /> <%-- Adds link, but req input param errors display on diff pg --%> --%>
<input type="hidden" name="ID" value="<%ID%>" /> <%-- Dup entry error, but errors display on same pg as form --%>
<input type="submit" name="add" value="Add Link" class="submit" />
</div>
</form>
<%endif%>
</div>


In include_form.html, I have

Code:
<div class="row<%unless category_loop_selected%> required<%endunless%> clear">
<label for="CatLinks.CategoryID" class="name">Category:<%unless category_loop_selected%> <span>*</span><%endunless%></label>
<div class="value<%if category_loop_selected%> wrappedtext<%endif%>">
<%if category_loop_selected%>
<%if category_loop.length > 1%>
<ul><%loop category_loop%><li><%Full_Name%><input type="hidden" name="CatLinks.CategoryID" value="<%escape_html ID%>" /></li><%endloop%></ul>
<%else%>
<%loop category_loop%><%Full_Name%><input type="hidden" name="CatLinks.CategoryID" value="<%escape_html ID%>" /><%endloop%>
<%endif%>
<%else%>
<%~set num_subcats = count_subcats($ID)%>
<%if num_subcats == 0%>
<b><%cat_name($ID)%></b>
<input type="hidden" name="CatLinks.CategoryID" value="<%escape_html ID%>" />
<%else%>
<%~set catid = $ID%>
<select id="CatLinks.CategoryID" name="CatLinks.CategoryID">
<%loop category_loop%>

<%if $CatRoot == $catid%>
<option value="<%escape_html ID%>"<%if selected%> selected="selected"<%endif%>><%'&nbsp;&nbsp;' x $CatDepth%><%Name%></option>
<%endif%>

<%endloop%>
</select>
<%endif%>
<%endif%>
</div>
</div>

Please help. I have spent way too much time on this.
Thank you for any assistance.

Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] Category specific Add Link problems (multiple include_form.html) In reply to
It's late, and I'm not sure I fully get what you are trying to do (or rather how you are doing it).

But what jumps out at me, is that how the category.CategoryID is handled, is a bit complicated, and by using "ID" to hold and/or pass the parameter, you are confusing the Links table which uses "ID" as the parameter.

If everything is working, except for the insert link code, change your "ID" parameter to something else like Category_ID, and see if that fixes it.


PUGDOG´┐Ż Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Category specific Add Link problems (multiple include_form.html) In reply to
Thanks pugdog.

I have it working almost perfectly using a different argument name than ID or CategoryID.
It is very confusing how it works. I will post my results here when I have time.

To see what I am trying to do, signup to supportmusicians.com and have a look.

Chris

RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] Category specific Add Link problems (multiple include_form.html) In reply to
Did you ever get this working? I've just upgraded and found that my add form is broken.