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:
<form method="post" action="$path" ENCTYPE="multipart/form-data">
replace with:
<form method="post" action="$path" ENCTYPE="multipart/form-data" name="myform" onsubmit="return chkForm();">
before this line, add above:
</script>
this code:
function chkForm()
{
if(document.myform.XXX.value == "")
{
alert("INSERT MESSAGE FOR UPLOADER HERE");
document.myform.keywords.focus();
return false;
}
}
description:
XXX can be:
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 }
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:
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é
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;
Read the instructions more carefully.
Quote from: alfisti.net on March 31, 2008, 09:03:32 AM
function chkForm()
{
if(document.myform.XXX.value == "")
{
alert("INSERT MESSAGE FOR UPLOADER HERE");
document.myform.keywords.focus();
return false;
}
}
description:
XXX can be:
title
caption
keywords
user1
user2
user3
user4
What you want is
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.
Thanks for the heads up, this worked a treat.
Mick
Does that mean that your other open thread (http://forum.coppermine-gallery.net/index.php/topic,56174.0.html) is solved?
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?
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;
}