Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Required field!!?  (Read 7617 times)

0 Members and 1 Guest are viewing this topic.

BT-loader

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 102
Required field!!?
« 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"?
« Last Edit: August 26, 2005, 09:19:30 am by GauGau »
Logged
:: BT-loader ::
"The one and only..."

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Required field!!?
« Reply #1 on: August 21, 2005, 08:46:23 am »

add some JavaScript gimmick that checks the form when it gets submitted.
Edit upload.php, find
Code: [Select]
<form method="post" action="$path" ENCTYPE="multipart/form-data">and replace with
Code: [Select]
<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
Code: [Select]
    </script>and add before it (in a new line)
Code: [Select]
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.
Logged

BT-loader

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 102
Re: Required field!!?
« Reply #2 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
Code: [Select]
// 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>

              
Logged
:: BT-loader ::
"The one and only..."

Nibbler

  • Guest
Re: Required field!!?
« Reply #3 on: August 24, 2005, 07:16:05 pm »

There's a curly bracket missing to end the function.
Logged

BT-loader

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 102
Re: Required field!!?
« Reply #4 on: August 24, 2005, 07:19:11 pm »

There's a curly bracket missing to end the function.
I´m sorry, but i can´t see where to add it.
Logged
:: BT-loader ::
"The one and only..."

Nibbler

  • Guest
Re: Required field!!?
« Reply #5 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;
   }
}
Logged

BT-loader

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 102
Re: Required field!!?
« Reply #6 on: August 25, 2005, 06:45:06 am »

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.  :)
Logged
:: BT-loader ::
"The one and only..."
Pages: [1]   Go Up
 

Page created in 0.02 seconds with 20 queries.