forum.coppermine-gallery.net
Support => cpg1.4.x Support => Older/other versions => cpg1.4 miscellaneous => Topic started by: noeinstein on September 15, 2008, 01:38:31 pm
-
Hi, i am working on a ’Easy Keyword insert MOD v3’ for coppermine 1.4.x. I am almost there but have run into a problem. With this code i am able to read the keywords from the database and display 1 checkbox for every keyword, but only the last keyword selected is going into the database. I don’t understand why.
I would be very greatful if somebody could help me with this, I have spent days trying to figure this out.
The code:
// Ok, go with "Easy keyword insert MOD v2"
//mod here
// The text Keyword form <---- modded input function. Takes the text label for the box, the input name, the maximum length for text boxes,
// and the number of iterations.
function keyword_box_input($text, $name, $max_length, $iterations, $default='') {
global $CONFIG;
$ordinal = '';
if (($text == '') and ($iterations == '')) {
echo " <input type=\"hidden\" name=\"$name\" value=\"$default\" />\n";
return;
}
// Begin loop
for ($counter=0; $counter<$iterations; $counter++) {
// Create a numbering system when necessary.
if ($text == '') {
$cardinal = $counter + 1;
$ordinal = "".$cardinal.". ";
}
// Hop stop here ! Add request of keyword_select.php to get the keyword list
$query = "SELECT * FROM {$CONFIG['TABLE_PREFIX']}dict ORDER BY keyword";
$result = cpg_db_query($query);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$keywordIds[] = $row["keyId"];
$keywords[] = $row["keyword"];
}
$form = "";
foreach ($keywords as $keyword) {
$form.= '<input type="checkbox" name="keywords" value="'.$keyword.'">'.$keyword.'<br></input>';
}
// Return at the mod
// Create the keyword box.
echo <<< EOT
<tr>
<td width="40%" class="tableb" valign="top">
Kategorier :
</td>
<td width="60%" class="tableb" valign="top">
<div align="left">
<label>
$form
</label>
</div>
</td>
</tr>
EOT;
}
}
// We have incoming placement data. Let's capture it.
$album = (int)$_POST['album'];
$title = addslashes($_POST['title']);
$caption = addslashes($_POST['caption']);
$keywords = addslashes($_POST['keywords']);
$user1 = addslashes($_POST['user1']);
$user2 = addslashes($_POST['user2']);
$user3 = addslashes($_POST['user3']);
$user4 = addslashes($_POST['user4']);
// Create thumbnail and intermediate image and add the image into the DB
$result = add_picture($album, $filepath, $picture_name, 0,$title, $caption, $keywords, $user1, $user2, $user3, $user4, $category, $raw_ip, $hdr_ip, $movie_wd, $movie_ht);
-
You need
$form.= '<input type="checkbox" name="keywords[]" value="'.$keyword.'">'.$keyword.'<br></input>';
So that the browser treats it as an array and you need this
$keywords = array_map('addslashes', $_POST['keywords']);
$keywords = implode(',', $keywords);
so that the server treats it as an array.
-
Hi, and thank you very much for your reply.
But I have tried to change this lines and now all that goes into the database is 'Array', no keywords :(.
I also noticed another bug with this mod, The first keyword is checked/unchecked everytime one of the other checkboxes is checked/unchecked.
Appreciate a little more help.
Noeinstein
-
Sorry that i don't know much php.
I found this line in upload.php:
array($lang_upload_php['keywords'], 'keywords', 5, 255, 1,(isset($iptc['Keywords'])) ? implode(' ',$iptc['Keywords']): ''),
Does this do something like this line you wrote?
$keywords = implode(',', $keywords);
-
Sorry for another post. This time i will try to post all relevant code conserning keywords and maybe someone can tell me where I go wrong.
This is from the original upload.php.
// The function for text areas on forms. Takes the label, field name, and maximum length as arguments.
function text_area_input($text, $name, $max_length,$default='') {
// Create the text area.
echo <<<EOT
<tr>
<td class="tableb" valign="top">
$text
</td>
<td class="tableb" valign="top">
<textarea name="$name" rows="5" cols="40" class="textinput" style="width: 100%;" onKeyDown="textCounter(this, $max_length);" onKeyUp="textCounter(this, $max_length);">$default</textarea>
</td>
</tr>
EOT;
}
This is the mod i am trying to change:
// Ok, go with "Easy keyword insert MOD v2"
//mod here
// The text Keyword form <---- modded input function. Takes the text label for the box, the input name, the maximum length for text boxes,
// and the number of iterations.
function keyword_box_input($text, $name, $max_length, $iterations, $default='') {
global $CONFIG;
$ordinal = '';
if (($text == '') and ($iterations == '')) {
echo " <input type=\"hidden\" name=\"$name\" value=\"$default\" />\n";
return;
}
// Begin loop
for ($counter=0; $counter<$iterations; $counter++) {
// Create a numbering system when necessary.
if ($text == '') {
$cardinal = $counter + 1;
$ordinal = "".$cardinal.". ";
}
// Hop stop here ! Add request of keyword_select.php to get the keyword list
$query = "SELECT * FROM {$CONFIG['TABLE_PREFIX']}dict ORDER BY keyword";
$result = cpg_db_query($query);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$keywordIds[] = $row["keyId"];
$keywords[] = $row["keyword"];
}
$form = "";
foreach ($keywords as $keyword) {
$form.= '<input type="checkbox" name="keywords[]" value="'.$keyword.'">'.$keyword.'<br></input>';
}
// Return at the mod
// Create the keyword box.
echo <<< EOT
<tr>
<td width="40%" class="tableb" valign="top">
Kategorier :
</td>
<td width="60%" class="tableb" valign="top">
<div align="left">
<label>
$form
</label>
</div>
</td>
</tr>
EOT;
}
$keywords = addslashes(implode(',', $_POST['keywords']));
}
This is from the original mod:
// If the type is keyword input
case 5 :
// Call the text area function.
keyword_box_input($element[0], $element[1], $element[3], (isset($element[4])) ? $element[4] : '');
break;
This section is also changed by the original mod:
// Declare an array containing the various upload form box definitions.
$captionLabel = $lang_upload_php['description'];
if ($CONFIG['show_bbcode_help']) {$captionLabel .= ' '. cpg_display_help('f=index.html&base=64&h='.urlencode(base64_encode(serialize($lang_bbcode_help_title))).'&t='.urlencode(base64_encode(serialize($lang_bbcode_help))),470,245);}
$form_array = array(
sprintf($lang_upload_php['max_fsize'], $CONFIG['max_upl_size']),
array($lang_upload_php['album'], 'album', 2),
array('MAX_FILE_SIZE', $max_file_size, 4),
array($lang_upload_php['picture'], 'userpicture', 1, 1),
array($lang_upload_php['pic_title'], 'title', 0, 255, 1),
array($captionLabel, 'caption', 3, $CONFIG['max_img_desc_length']),
array($lang_upload_php['keywords'], 'keywords', 5, 255, 1),
array('event', 'picture', 4)
);
Here I changed a line according to yuor post:
// We have incoming placement data. Let's capture it.
$album = (int)$_POST['album'];
$title = addslashes($_POST['title']);
$caption = addslashes($_POST['caption']);
$keywords = array_map('addslashes', $_POST['keywords']);
$user1 = addslashes($_POST['user1']);
$user2 = addslashes($_POST['user2']);
$user3 = addslashes($_POST['user3']);
$user4 = addslashes($_POST['user4']);
// Create thumbnail and intermediate image and add the image into the DB
$result = add_picture($album, $filepath, $picture_name, 0,$title, $caption, $keywords, $user1, $user2, $user3, $user4, $category, $raw_ip, $hdr_ip, $movie_wd, $movie_ht);
Last quote, this changed by original mod
$form_array = array(
array($lang_upload_php['album'], 'album', 2),
array($lang_upload_php['pic_title'], 'title', 0, 255, 1, $title),
array($captionLabel, 'caption', 3, $CONFIG['max_img_desc_length'], (isset($iptc['Caption'])) ? $iptc['Caption'] : ''),
array($lang_upload_php['keywords'], 'keywords', 5, 255, 1,(isset($iptc['Keywords'])) ? implode(' ',$iptc['Keywords']): ''),
array('control', 'phase_2', 4),
array('unique_ID', $_POST['unique_ID'], 4),
);
I hope soemone can help me and that others will find this mod useful when it works the way it is supposed to
Regards Noeinstein
-
Sorry, but this line is at the wrong place when I quoted.
$keywords = addslashes(implode(',', $_POST['keywords']));
are places under
$keywords = array_map('addslashes', $_POST['keywords']);
Just me that tried a lot of things to see if I could get this to work
-
$keywords = addslashes(implode(',', $_POST['keywords']));
Remove that line.