forum.coppermine-gallery.net

No Support => Modifications/Add-Ons/Hacks => Mods: Uploading => Topic started by: alfisti.net on March 31, 2008, 09:03:32 am

Title: How to create required upload image fields!
Post by: alfisti.net on March 31, 2008, 09:03:32 am
credit: http://forum.coppermine-gallery.net/index.php/topic,20965.0.html (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é
Title: Re: How to create required upload image fields!
Post by: crdm 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;
Title: Re: How to create required upload image fields!
Post by: Nibbler 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.
Title: Re: How to create required upload image fields!
Post by: crdm on November 12, 2008, 12:22:57 pm
Thanks for the heads up, this worked a treat.

Mick
Title: Re: How to create required upload image fields!
Post by: Joachim Müller on November 13, 2008, 07:45:16 am
Does that mean that your other open thread (http://forum.coppermine-gallery.net/index.php/topic,56174.0.html) is solved?
Title: Re: How to create required upload image fields!
Post by: traceywashere 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;
}