coppermine-gallery.com/forum

Support => Older/other versions => cpg1.3.x Support => Topic started by: BT-loader on August 20, 2005, 10:35:52 AM

Title: Required field!!?
Post by: BT-loader on August 20, 2005, 10:35:52 AM
Some of my users doesn´t write/add any "keywords" when they upload a picture and that´s not good.  :-\\
So i was wondering how i could make this field (keywords) "required"?
Title: Re: Required field!!?
Post by: Joachim Müller on August 21, 2005, 08:46:23 AM
add some JavaScript gimmick that checks the form when it gets submitted.
Edit upload.php, find<form method="post" action="$path" ENCTYPE="multipart/form-data">and replace with<form method="post" action="$path" ENCTYPE="multipart/form-data" name="myform" onsubmit="return chkForm();">Right above this section, enter the script that checks the user input - find    </script>and add before it (in a new line)function chkForm()
        {
         if(document.myform.keywords.value == "")
          {
           alert("Please enter some keywords for your upload!");
           document.myform.keywords.focus();
           return false;
          }

I haven't tested this code, but it should be something along those lines.
Title: Re: Required field!!?
Post by: BT-loader on August 24, 2005, 07:09:36 PM
I don´t think it worked cause i still could upload a image without entering any keywords.  :(
Here is the code in my upload.php
// The open_form function creates the Javascript verification code and the opening form tags.
// $path hold the form action path.
function open_form($path) {

    echo <<<EOT
    <script language="JavaScript">
    function textCounter(field, maxlimit) {
            if (field.value.length > maxlimit) // if too long...trim it!
            field.value = field.value.substring(0, maxlimit);
    }
function chkForm()
        {
         if(document.myform.keywords.value == "")
          {
           alert("Please enter some keywords for your upload!");
           document.myform.keywords.focus();
           return false;
          }
    </script>
<form method="post" action="$path" ENCTYPE="multipart/form-data" name="myform" onsubmit="return chkForm();">
    </td>


             
Title: Re: Required field!!?
Post by: Nibbler on August 24, 2005, 07:16:05 PM
There's a curly bracket missing to end the function.
Title: Re: Required field!!?
Post by: BT-loader on August 24, 2005, 07:19:11 PM
Quote from: Nibbler on August 24, 2005, 07:16:05 PM
There's a curly bracket missing to end the function.
I´m sorry, but i can´t see where to add it.
Title: Re: Required field!!?
Post by: Nibbler on August 24, 2005, 07:22:56 PM
function chkForm()
{
   if(document.myform.keywords.value == "")
   {
      alert("Please enter some keywords for your upload!");
      document.myform.keywords.focus();
      return false;
   }
}
Title: Re: Required field!!?
Post by: BT-loader on August 25, 2005, 06:45:06 AM
Quote from: Nibbler on August 24, 2005, 07:22:56 PM
function chkForm()
{
   if(document.myform.keywords.value == "")
   {
      alert("Please enter some keywords for your upload!");
      document.myform.keywords.focus();
      return false;
   }
}
It worked great, thanks.  :)