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
Subject Author Views Date
Thread Category specific Add Link problems (multiple include_form.html) rgbworld 3364 Mar 11, 2006, 3:24 PM
Thread Re: [rgbworld] Category specific Add Link problems (multiple include_form.html)
pugdog 3296 Mar 12, 2006, 11:21 PM
Thread Re: [pugdog] Category specific Add Link problems (multiple include_form.html)
rgbworld 3263 Mar 13, 2006, 12:16 AM
Post Re: [rgbworld] Category specific Add Link problems (multiple include_form.html)
afinlr 3109 Mar 27, 2007, 10:55 AM