Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Utorok, 24. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  js form validation on select box

phpMyEdit Configuration     js form validation on select box
Odoslať novú tému   Odpovedať na tému    
 
JammerPro     Založený: 07.12.2006   Príspevky: 33  
Príspevok Zaslal: 2009-09-24 00:08
Návrat hore  Odpovedať s citátom     

I use a select dropdown box with the following setup:

Kód:


$opts['fdd']['job_type'] = array(
  'default'    => '',
  'input'      => '',
  'maxlen'     => 300,
  'name'       => 'Transaction',
  'options'    => 'ACPVDFL',
  'select'     => 'D',
  'size'       => 20,
  'sort'       => true,
  'values'     => array('', yes, no)
);
// MySQL column 3: string - varchar(100)
$opts['fdd']['job_type']['js']['required'] = true;


The drop down select box on the add and change pages is a blank space for Option 1, "yes" for Option 2, and "no" for Option 3. I used NULL, '', "", and 0 for values and values2 for the array to create the dropdown menu, but nothing has worked. The javascript "required" does not prevent a user from saving the form with a blank. When the blank is selected, the form is not halted by the js (javascript) "required" command above, but, instead, the form can be processed without validation.

I would like to prevent a user who does not select "yes" or "no" (who has selected the blank option) to be "required" when in the add and/or change screens.

Any help would be greatly appreciated.

On a more serious note, I am actually stunned that this question has been asked several times on this board, but has never been answered. See http://opensource.platon.sk/forum/projects/viewtopic.php?t=1&highlight=select+required which is a thread going back to early 2003. A data base program that will not validate that the user has selected an option from a drop down menu is severely impaired. Could someone please fix this most pressing problem and post some guidance to us all.

In html. this would be an easy thing to do as follows:

Try the following code:

Kód:

<script LANGUAGE="JavaScript">
<!--
function ValidateForm(form){
ErrorText= "";
if ( form.user.selectedIndex == 0 ) { alert ( "--Select a User--" ); return false;
}
if (ErrorText= "") { form.submit() }
}
-->
</script>

<br><form name="feedback" action=mailto:legal@cyberlaw.info method="post">
<select name="user">
<option value="">--Select A User</option>
<option value="John">John</option>
<option value="Joe">Joe</option>
<option value="Larry">Larry</option>
<option value="Curly">Curly</option>
<option value="Moe">Moe</option>
</select>
<input type="button" name="SubmitButton" value="Submit" onClick="ValidateForm(this.form)">
<input type="reset" value="Reset">
</form>


Please review the example again to see what I'm asking. It's really a simple question.

If a user is presented with a list of choices in a drop down box, and does not choose one, but leaves it on the default, is there some way for phpMyEdit's js to alert the user that he must make a choice? The below code makes "--select a user--" visible in the list box with a NULL value (I've tried NULL, '', "", 0, and "0", but nothing brings up the js alert or hint..)

Kód:

'values2' =>array(
''      => '--select a user--',
'john'  => 'john',
'joe'   => 'joe',
'larry' => 'larry',
'curly' => 'curly',
'moe'   => 'moe'
      )


If the user does not pick, or chooses "--select a user--", the js validation alert command (shown below) should sound out, but it doesn't work like it should.

Kód:

$opts['fdd']['job_type']['js']['required'] = true;


Thanks in advance. I know there is an answer to this out there! If it can be done with html and javascript so easily, I can't see why this issue has gone on for so long!

 
tbarmann     Založený: 22.06.2011   Príspevky: 1  
Príspevok Zaslal: 2012-04-06 22:24
Návrat hore  Odpovedať s citátom     

This is an old message, but I stumbled upon it again when trying to solve the same problem. Here is a solution.

The phpmyedit.class.php file creates the Javascript that is used to check input fields. So the class needs to be modified to change the function that checks drop down fields.

For my use, I decided that an invalid choice would be the very first one, which is index 0. In the phpmyedit.class.php at about line 886, I changed this:

Kód:
$condition = 'theForm.'.$this->cgi['prefix']['data'].$this->fds[$k].'.selectedIndex == -1';


To:

Kód:
$condition = 'theForm.'.$this->cgi['prefix']['data'].$this->fds[$k].'.selectedIndex == 0';


That seemed to fix the problem.
[/code]

 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov