['moved' from HTML/CSS board, as suggested, thanks...]
Hello,
I am building a form that collects some data about a file and throws it into a PosgreSQL database and also allows the user to upload and process the file using PHP's $_FILES...
i.e., <input type="file" name="file" id="file" size="50"/>
Action is a PHP_SELF, method is POST, check with array_key_exists, etc... anyway..... :-)
The form works just fine if all of the data is entered correctly... However, the 'onsubmit' js validation is not 'triggered' when the form's enctype="multipart/form-data" ??
Help! TIA! <smile> Aside:
- once I get it working, any validation suggestions for the file upload part of the form as I can't check the $_FILES criteria prior to the submit of course
- I previously had it working via two forms - upload, check $_FILES, AJAX to turn on the submit for the details form, details entered, submit, working as desired - but only in IE! (in non-IE browsers, the submit button for the details part of the 2nd form was turned on correctly by AJAX but simply 'ignored' when clicked...)
Cheers!:
GREG...
5 7737
The onsubmit should work. Post your code.
Of course, thank you:
(i) I put the validation javascript at the bottom, even though it is in the <head> - and may be you don't need it, as it it not getting there anyway
(ii) I gave you the lot, even though most is not relevant of course - apart from the PHP to process the form (as this is working)
(iii) the page is a *.php, necessarily
(iv) look for "DRAFT @ ..." to see which bits I am still working on (not relevant to this issue)
(v) I am not used to the formatting commands in the forum, so apologies in advance if it is a bot off kilter!
(vi) looking at it further, is it related the form tags are not totally within the table tags? (or vica versa)
--------------
-------------- -
//validate the module detail edits form contents
-
function validate_module_details_add_form()
-
{
-
-
//DRAFT @ 03/12/09 - delete these lines
-
alert('Form validation triggered...');
-
-
//check to see if MODULE ID text field was left blank
-
if(document.add_new_module_details.new_module_id.value.length == 0)
-
{
-
alert("Please enter some text for the new MODULE ID...");
-
document.add_new_module_details.new_module_id.focus(); //set the focus to this element, so the user can correct the entry
-
return false;
-
};
-
-
//check to see that the MODULE ID is numbers, letters and underscores (note - 6 characters or less 'requirement' is via form entry field size setting)
-
var AllowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_";
-
for(var i = 0; i < document.add_new_module_details.new_module_id.value.length; i++)
-
{
-
if (AllowedChars.indexOf(document.add_new_module_details.new_module_id.value.charAt(i)) == -1)
-
{
-
alert("For the new MODULE ID, only use:\n\n - letters\n\n - numbers\n\n - underscores");
-
document.add_new_module_details.new_module_id.focus(); //set the focus to this element, so the user can 'correct' the entry
-
return false;
-
};
-
};
-
-
//check to see that the MODULE ID is UNIQUE
-
var IDAlreadyUsed = false;
-
<?php
-
foreach($ary_existing_module_details_sum as $ary_row)
-
{
-
?>
-
if(document.add_new_module_details.new_module_id.value == '<?php print $ary_row['module_id']; ?>')
-
{
-
IDAlreadyUsed = true;
-
};
-
<?php
-
};
-
?>
-
if(IDAlreadyUsed == true)
-
{
-
alert(" MODULE ID\nis already in use...\n\n Please adjust...");
-
document.add_new_module_details.new_module_id.focus(); //set the focus to this element, so the user can correct the entry
-
return false;
-
};
-
-
-
//check to see if MODULE TITLE text field was left blank
-
if(document.add_new_module_details.new_module_title.value.length == 0)
-
{
-
alert("Please enter some text for the new MODULE TITLE...");
-
document.add_new_module_details.new_module_title.focus(); //set the focus to this element, so the user can correct the entry
-
return false;
-
};
-
-
//check to see that the MODULE TITLE is UNIQUE
-
var TitleAlreadyUsed = false;
-
<?php
-
foreach($ary_existing_module_details_sum as $ary_row)
-
{
-
?>
-
if(document.add_new_module_details.new_module_title.value == '<?php print $ary_row['module_title']; ?>')
-
{
-
TitleAlreadyUsed = true;
-
};
-
<?php
-
};
-
?>
-
if(TitleAlreadyUsed == true)
-
{
-
alert(" TITLE\nis already in use...\n\n Please adjust...");
-
document.add_new_module_details.new_module_title.focus(); //set the focus to this element, so the user can correct the entry
-
return false;
-
};
-
-
//check to see if new module's FILE NAME field was left blank
-
if(document.add_new_module_details.new_module_filename.value.length == 0)
-
{
-
alert("Please enter a some text for the new module's FILE NAME...");
-
document.add_new_module_details.new_module_filename.focus(); //set the focus to this element, so the user can correct the entry
-
return false;
-
};
-
-
//check to see if new module's FILE NAME field seemingly includes a file extension (assuming that it is unless shown otherwise) - NOTE THAT would be 'caught' as the peroid would lick back in the form validiation as a 'illegal character', but this way it is easier for the user to comprehend the issue and edit
-
if((document.add_new_module_details.new_module_filename.value).substr(document.add_new_module_details.new_module_filename.value.length-4,1) == '.')
-
{
-
alert("It appears that you have added a FILE EXTENSION to the new module's FILE NAME...\n\nPlease delete before resubmitting...\n\n(use the extension 'pull-down' to record this info...)");
-
document.add_new_module_details.new_module_filename.focus(); //set the focus to this element, so the user can 'correct' the entry
-
return false;
-
};
-
-
//check to see that the FILE NAME is numbers, letters and underscores (note - 50 characters or less 'requirement' is via form entry field size setting)
-
var AllowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_";
-
for(var i = 0; i < document.add_new_module_details.new_module_filename.value.length; i++)
-
{
-
if (AllowedChars.indexOf(document.add_new_module_details.new_module_filename.value.charAt(i)) == -1)
-
{
-
alert("For the new FILE NAME, only use:\n\n - letters\n\n - numbers\n\n - underscores");
-
document.add_new_module_details.new_module_filename.focus(); //set the focus to this element, so the user can correct the entry
-
return false;
-
};
-
};
-
-
//check to see that the FILE NAME is UNIQUE
-
var FileNameAlreadyUsed = false;
-
<?php
-
foreach($ary_existing_module_details_sum as $ary_row)
-
{
-
?>
-
if(document.add_new_module_details.new_module_filename.value == '<?php print $ary_row['file_name']; ?>')
-
{
-
FileNameAlreadyUsed = true;
-
};
-
<?php
-
};
-
?>
-
if(FileNameAlreadyUsed == true)
-
{
-
alert(" FILE NAME\nis already in use...\n\n Please adjust...");
-
document.add_new_module_details.new_module_filename.focus(); //set the focus to this element, so the user can correct the entry
-
return false;
-
};
-
-
//check to make sure the user has selected a FILE EXTENSION from the pulldown
-
if(document.add_new_module_details.new_module_file_extension.value == 'not_yet_selected')
-
{
-
alert("Please select the new module's FILE EXTENSION from the appropiate form 'pull-down'...");
-
document.add_new_module_details.new_module_file_extension.focus(); //set the focus to this element, so the user can correct the entry
-
return false;
-
};
-
-
//check to make sure the user has selected a MODULE GROUP from the pulldown
-
if(document.add_new_module_details.new_module_group.value == 'not_yet_selected')
-
{
-
alert("Please select the new module's MODULE GROUP from the appropiate form 'pull-down'...");
-
document.add_new_module_details.new_module_group.focus(); //set the focus to this element, so the user can correct the entry
-
return false;
-
};
-
-
//check to make sure the user has selected a MODULE CONTACT from the pulldown
-
if(document.add_new_module_details.new_module_contact_id.value == 'not_yet_selected')
-
{
-
alert("Please select the new module's MODULE CONTACT from the appropiate form 'pull-down'...");
-
document.add_new_module_details.new_module_contact_id.focus(); //set the focus to this element, so the user can correct the entry
-
return false;
-
};
-
-
//check that the DATE CREATED field is not blank
-
if(document.add_new_module_details.new_module_date_created.value.length == 0)
-
{
-
alert("Please enter the new module's DATE CREATED...");
-
document.add_new_module_details.new_module_date_created.focus(); //set the focus to this element, so the user can correct the entry
-
return false;
-
};
-
-
//check that the DATE CREATED field is in the correct format
-
if(checkValidDate(document.add_new_module_details.new_module_date_created.value) == false)
-
{
-
alert('The DATE CREATED is not in a valid date format...\n\nPlease adjust before resubmitting...');
-
document.add_new_module_details.new_module_date_created.focus(); //set the focus to this element, so the user can 'correct' the entry
-
return false;
-
};
-
-
//grab the date, add the right century, make into a js date
-
var entered_date_string = document.add_new_module_details.new_module_date_created.value;
-
if(((entered_date_string).substr(entered_date_string.length-3,1) == '/'))
-
{
-
//if the full years (i.e., 20##) are not there, add them so the js date creation works properly - with the assumption that the date is 20##
-
left = entered_date_string.substr(1,entered_date_string.length-3);
-
right = entered_date_string.substr(entered_date_string.length-2,2);
-
if(parseInt(right) < 30)
-
{
-
century = '20';
-
}
-
else
-
{
-
century = '19';
-
}
-
entered_date_string_adjusted = left + century + right;
-
}
-
else
-
{
-
entered_date_string_adjusted = entered_date_string; //i.e., already has the century included
-
}
-
-
//check that the DATE CREATED field is not in the future
-
var today = new Date();
-
-
var entered_date_converted = new Date(entered_date_string_adjusted);
-
if(entered_date_converted > today)
-
{
-
alert('The DATE CREATED is in the future...\n\nPlease adjust before resubmitting...');
-
document.add_new_module_details.new_module_date_created.focus(); //set the focus to this element, so the user can 'correct' the entry
-
return false;
-
}
-
else
-
{
-
//ensure the date on the form is this century, even though the user will not see (although the code doesn't likely need this...)
-
document.add_new_module_details.new_module_date_created.value = entered_date_string_adjusted;
-
};
-
-
//check to see if ESTIMATED COMPLETION TIME field was left blank
-
if(document.add_new_module_details.new_module_reasonable_completion_minutes.value.length == 0)
-
{
-
alert("Please enter a numeric value for the ESTIMATED COMPLETION TIME (minutes)...");
-
document.add_new_module_details.new_module_reasonable_completion_minutes.focus(); //set the focus to this element, so the user can correct the entry
-
return false;
-
};
-
-
//check to see that the ESTIMATED COMPLETION TIME is a numeric value (note - 3 characters or less 'requirement' is via form entry field size setting)
-
if(!IsNonZeroInteger(document.add_new_module_details.new_module_reasonable_completion_minutes.value))
-
{
-
alert('The ESTIMATED COMPLETION TIME (minutes) needs to be an integer value (1 to 999)');
-
document.add_new_module_details.new_module_reasonable_completion_minutes.focus(); //set the focus to this element, so the user can 'correct' the entry
-
return false;
-
};
-
-
//if the new module is indicated as 'test required', check to see the user has entered a numeric value for the number of test questions, etc
-
if(document.add_new_module_details.new_module_test_required.checked == true)
-
{
-
-
//check that the module's desired number of questions is an integer (or null)
-
if(!IsNonZeroInteger(document.add_new_module_details.new_module_number_test_questions.value))
-
{
-
alert('The desired NUMBER TEST QUESTIONS needs to be an integer value (1 to 99)');
-
document.add_new_module_details.new_module_number_test_questions.focus(); //set the focus to this element, so the user can 'correct' the entry
-
return false;
-
};
-
-
//if the 'test required' is true, then confirm that a value for number of test questions has been entered
-
if(document.add_new_module_details.new_module_number_test_questions.value == 0)
-
{
-
alert("As the module is indicated as TEST REQUIRED,\n\nplease enter the number of desired NUMBER TEST QUESTIONS");
-
document.add_new_module_details.new_module_number_test_questions.focus(); //set the focus to this element, so the user can 'correct' the entry
-
return false;
-
};
-
-
//if the number of desired test questions, if applicable, is over 50 then confirm with the user that this is correct
-
if(parseInt(document.add_new_module_details.new_module_number_test_questions.value) > 50)
-
{
-
var answer = confirm('Greater than fifty (50) desired TEST QUESTIONS was entered as the value...\n\nIs this correct?');
-
if(answer == false)
-
{
-
document.add_new_module_details.new_module_number_test_questions.focus(); //set the focus to this element, so the user can 'correct' the entry
-
return false;
-
};
-
};
-
-
};
-
-
//if the new MODULE COMMENT field is empty, confirm that this is the user's intention
-
if(document.add_new_module_details.new_module_comment.value.length == 0)
-
{
-
var answer = confirm('The new MODULE COMMENT field is blank...\n\nIs this correct?');
-
if(answer == false)
-
{
-
document.add_new_module_details.new_module_comment.focus(); //set the focus to this element, so the user can 'correct' the entry
-
return false;
-
};
-
};
-
-
//check to make sure that the file upload field has been populated
-
//DRAFT @ 03/12/09 - to write
-
-
//check to make sure that the file upload field has the letters ZIP on it's far right
-
//DRAFT @ 03/12/09 - to write
-
-
//final confirmation of the desire to add the module details, copy presented in alert box
-
var answer = confirm
-
(
-
'PLEASE CONFIRM:\nThe following new MODULE DETAILS will be added ??\n\n\n'
-
+ 'MODULE ID => ' + document.add_new_module_details.new_module_id.value + '\n\n'
-
+ 'MODULE TITLE => ' + document.add_new_module_details.new_module_title.value + '\n\n'
-
+ 'FILE NAME => ' + document.add_new_module_details.new_module_filename.value + '\n\n'
-
+ 'FILE EXTENSION => ' + document.add_new_module_details.new_module_file_extension.value + '\n\n'
-
+ 'MODULE GROUP => ' + document.add_new_module_details.new_module_group.value + '\n\n'
-
+ 'MODULE CONTACT eID => ' + document.add_new_module_details.new_module_contact_id.value + '\n\n'
-
+ 'DATE CREATED => ' + document.add_new_module_details.new_module_date_created.value + '\n\n'
-
+ 'COMPL. TIME => ' + document.add_new_module_details.new_module_reasonable_completion_minutes.value + ' mins.\n\n'
-
+ 'LIMITED ACCESS? => ' + document.add_new_module_details.new_module_limited_access.checked + '\n\n'
-
+ 'TEST REQUIRED? => ' + document.add_new_module_details.new_module_test_required.checked + '\n\n'
-
+ 'NO. QUESTIONS => ' + document.add_new_module_details.new_module_number_test_questions.value + '\n\n'
-
+ 'OPEN BOOK? => ' + document.add_new_module_details.new_module_open_book_test.checked + '\n\n'
-
+ 'COMMENT => ' + document.add_new_module_details.new_module_comment.value
-
);
-
if(answer == false)
-
{
-
document.add_new_module_details.new_module_comment.focus(); //set the focus to this element, so the user can 'correct' the entry
-
return false;
-
};
-
-
//return the 'yay', now that the various elements have been validated as OK...
-
return true;
-
-
};
You forgot the () : - <form ... onsubmit="return validate_module_details_add_form()">
in the vernacular, d'oh!
<embarrassed>
Cheers!
Don't worry: we've all been there at some point! :)
Sign in to post your reply or Sign up for a free account.
Similar topics
by: F. Da Costa |
last post by:
Hi,
I was wondering *why* there is a difference between the results of the
following two statements. On the suface they seem to do the same (or do they?)
frm => returns void
...
|
by: Paul T. RONG |
last post by:
Hello there,
This is the case:
the mde I made works alright on my machine, but there is a small problem
when I installed it on a user's machine (His machine's OS is Windows XP Pro
and it has...
|
by: Mark |
last post by:
In our web.config, we have changed the first line below to look like the
second:
OLD: <globalization requestEncoding="utf-8" responseEncoding="utf-8" />
NEW: <globalization...
|
by: MLH |
last post by:
Suppose that code running on FormB
is moving the focus around on FormA
to various textbox controls on FormA -
Which form is the current form during this process?
Is it FormA, which has the...
|
by: Mark Collard |
last post by:
I've noticed that when you add a ToolTip component to a Form (or UserControl)
the other controls on the form display a property in the property grid called
"ToolTip on toolTip1", so you can set the...
|
by: morangolds |
last post by:
Hi,
I've been having a problem with C++ Windows Forms apps not "ending"
when you close the form window. I've searched about this problem all
over the place and most searches have lead me to...
|
by: polocar |
last post by:
Hi,
suppose that you have a C# form with two buttons, that are the
classical "btnOk" and "btnCancel" (besides them, of course in
the form there can be many other controls).
When the user clicks...
|
by: boliches |
last post by:
I have a form within my database which On Open (event procedure) will make many calculations and enter the results in text boxes on the page of the form (I have 2 tabs on this particular form). My...
|
by: MrCorbeaux |
last post by:
My "Email a Webpage" form works find except when the end user receives the email, the URL is text only and not a hyperlink.
The "Email a Page" form calls the URL from the previous page using:
...
|
by: dangt85 |
last post by:
Hello,
I have the following page:
...
<style type="text/css">
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |