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: How to create required upload image fields!  (Read 11695 times)

0 Members and 1 Guest are viewing this topic.

alfisti.net

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 38
    • http://alfisti.net
How to create required upload image fields!
« on: March 31, 2008, 09:03:32 am »

credit: http://forum.coppermine-gallery.net/index.php/topic,20965.0.html a post from GauGau (Joachim Müller).
I needed a little bit time to understand how to use this for other upload fields, so I think a manual can be helpful. I created a new thread because this works also in version 1.4. (@admins: I hope this OK)

To mandatory image upload fields you have to to the following.

open upload.php

find:
Code: [Select]
<form method="post" action="$path" ENCTYPE="multipart/form-data">
replace with:
Code: [Select]
<form method="post" action="$path" ENCTYPE="multipart/form-data" name="myform" onsubmit="return chkForm();">
before this line, add above:
Code: [Select]
</script>
this code:
Code: [Select]
function chkForm()
{
   if(document.myform.XXX.value == "")
   {
      alert("INSERT MESSAGE FOR UPLOADER HERE");
      document.myform.keywords.focus();
      return false;
   }
}

description:
XXX can be:
Code: [Select]
title
caption
keywords
user1
user2
user3
user4

Change "INSERT MESSAGE FOR UPLOADER" in eg.: "You have to fill out the title"

If you need more than 1 required field add the following before the last }
Code: [Select]
   if(document.myform.title.value == "")
   {
      alert("ATTENTION: You have to fill out the title field");
      document.myform.keywords.focus();
      return false;
   }

So it should like this:
Code: [Select]
function chkForm()
{
   if(document.myform.title.value == "")
   {
      alert("Attention: Image must have a title");
      document.myform.keywords.focus();
      return false;
   }

   if(document.myform.caption.value == "")
   {
      alert("Achtung: Image must have a description");
      document.myform.keywords.focus();
      return false;
   }

}

André
Logged

crdm

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 36
Re: How to create required upload image fields!
« Reply #1 on: November 10, 2008, 12:35:35 pm »

Andre

I have tried this, and it does not work,

Can you take a look at the extract and tell me what I'm doing wrong

// 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" type="text/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.Aircraft Registration:, Aircraft Mdel:,Airport Photo Taken:, Photogrpaher: .value == "")
   {
      alert("INSERT MESSAGE FOR UPLOADER HERE");
      document.myform.keywords.focus();
      return false;
   }
}

    </script>
    <form method="post" action="$path" ENCTYPE="multipart/form-data" name="myform" onsubmit="return chkForm();">
EOT;
Logged

Nibbler

  • Guest
Re: How to create required upload image fields!
« Reply #2 on: November 10, 2008, 01:45:58 pm »

Read the instructions more carefully.

Code: [Select]
function chkForm()
{
   if(document.myform.XXX.value == "")
   {
      alert("INSERT MESSAGE FOR UPLOADER HERE");
      document.myform.keywords.focus();
      return false;
   }
}

description:
XXX can be:
Code: [Select]
title
caption
keywords
user1
user2
user3
user4

What you want is

Code: [Select]
function chkForm()
{
   if(document.myform.user1.value == "")
   {
      alert("Attention: You must enter aircraft registration");
      document.myform.user1.focus();
      return false;
   }

   if(document.myform.user2.value == "")
   {
      alert("Attention: You must enter aircraft model");
      document.myform.user2.focus();
      return false;
   }

   if(document.myform.user3.value == "")
   {
       alert("Attention: You must enter the airport");
      document.myform.user3.focus();
      return false;
   }

   if(document.myform.user4.value == "")
   {
       alert("Attention: You must enter photographer name");
      document.myform.user4.focus();
      return false;
   }
}

This will only make them required if javascript is enabled of course.
Logged

crdm

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 36
Re: How to create required upload image fields!
« Reply #3 on: November 12, 2008, 12:22:57 pm »

Thanks for the heads up, this worked a treat.

Mick
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47844
  • aka "GauGau"
    • gaugau.de
Re: How to create required upload image fields!
« Reply #4 on: November 13, 2008, 07:45:16 am »

Does that mean that your other open thread is solved?
Logged

traceywashere

  • Coppermine newbie
  • Offline Offline
  • Posts: 2
Re: How to create required upload image fields!
« Reply #5 on: January 01, 2009, 12:55:10 am »

I applied this mod .. and i'm getting slightly strange behavior ...

if a required field isn't filled in, it gives the warning, but then submits the form anyway

did i put the code in the wrong place?

Code: [Select]
function open_form($path) {

    echo <<<EOT
    <script language="javascript" type="text/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.title.value == "")
   {
      alert("You must fill in Dogs name!");
      document.myform.keywords.focus();
      return false;
   }    
   if(document.myform.user1.value == "")
   {
      alert("You must fill in Call Name!");
      document.myform.keywords.focus();
      return false;
   }
   if(document.myform.user2.value == "")
   {
      alert("You must fill in Registered Name!");
      document.myform.keywords.focus();
      return false;
   }
   if(document.myform.user3.value == "")
   {
      alert("You must fill in DOB & Age!");
      document.myform.keywords.focus();
      return false;
   }
   if(document.myform.user4.value == "")
   {
      alert("You must fill in Owners name & email address!");
      document.myform.keywords.focus();
      return false;
   }
}

    </script>
    <form method="post" action="$path" ENCTYPE="multipart/form-data" name="myform" onsubmit="return chkForm();">
EOT;
}
Logged
Pages: [1]   Go Up
 

Page created in 0.024 seconds with 19 queries.