Welcome, Guest

Validierung aus Query
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: Validierung aus Query

Validierung aus Query 2 years, 4 months ago #10881

Ich habe die Validierung von Dateiendungen schon etwas modifiziert um
bestimmte Zahlenkombinationen zu validieren.

Nun meine Frage:
Ist es möglich die zu validierenden Zahlen auch aus der DB zu bekommen?

Mein Ansatz sieht so aus:

Das ganze ist eine Funktion, die ich unter Validierungs Skripte angelegt habe.
//Auslesen der Codes aus der db

$this->execPieceByName('ff_InitLib'); 
$valcodes = ff_select("select code from #__utr");
$validation = '';
if ($valcodes)
    foreach ($valcodes as $valcode) 
        $validation .= "$valcode->code,";
return $validation;


// Validierung 

//$this->execPieceByName('ff_InitLib'); 

function ff_validate_code(element, message)
{
    if(element.value != '')
    {
      dbcodes_string = $validation;
     //dbcodes_string = '1234,1111'; //So funktioniert das.

        dbcodes = dbcodes_string.split(',');
        code = element.value.substring(element.value.length-4,element.value.length); //

        code = element.value;


        for(p=0;p<dbcodes.length;p++) {
            if (code == dbcodes[p])
              return '';
        }

        if (message=='') message = 'Please check the file '+element.value+'!\nThe .' + ext + ' is an invalid file type!\n' + 'Only doc,pdf,zip or ogd files are allowed for upload!\n\n'
        ff_validationFocus(element.name);
        return message;
    }
    return'';
} // ff_validate_code


Leider bekomme ich die SQL Abfrage nicht übergeben. Vielleicht habe ich auch noch ein dickes NeuJahrsBrett vorm Kopf.
  • lu74
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Karma: 0

Re:Validierung aus Query 2 years, 4 months ago #10895

Also nach etlichen weiteren Versuchen und diversen Ansätzen stehe ich nun doch im Wald, den ich vor lauter Bäumen nicht mehr sehe.

Was ich aufbauen will:

ich habe ein formular mit
1. einem text input (begrenzt auf 4 zeichen)
2. zwei radio buttons (noch nicht wichtig)
3. einen Submit Button

Jetzt soll im input feld eine vierstellige zahl eingeben werden können, deren validierungs string aus der oben beschrieben db tabelle stammt.

dazu habe ich folgendes in die formular initialisierung gebaut
// Daten aus der DB laden und leere JS Arrays erstellen
<?php
echo 'var validations = new Array();';
echo 'var dbcodes_string = new Array();';

$db = JFactory::getDBO();
$db->setQuery("select code from #__utr");
$entries = $db->loadObjectList();

// Daten ins Array schreiben

foreach($entries As $valcode){
echo "validations.push('$valcode->code".","."');"."\n";
}
?>


function ff_ValTest_init()
{
} // ff_ValTest_init


Dann habe ich eine neue Validierungsfunktion gebaut (abgewandelt aus der Dateiendungsprüfung für den Upload)
function ff_validate_code(element, message)
{

    if(element.value != '')
    {

dbcodes_string = dbcodes_string.push(validations);
//dbcodes_string = '1234,1111,5678';  //das HIER funktioniert!!!
        dbcode = dbcodes_string.split(',');
        code = element.value.substring(element.value.length-4,element.value.length); //

        code = element.value;


        for(p = 0;p < 5;p++) {
            if (code == dbcode[p])
              return '';
        }

        if (message=='') message = 'Code NICHT vorhanden!\n\n'
        ff_validationFocus(element.name);
        return message;
    }
    // return '';
    if (message=='') message = 'Bitte Code eintragen!\n\n'
    ff_validationFocus(element.name);
    return message;
} // ff_validate_code



Im Quellcode sehe ich folgendes:
var validations = new Array();var dbcodes_string = new Array();validations.push('1111,');
validations.push('1234,');
validations.push('5678,');
function ff_ValTest_init()
{}

// und bei der validierungs funktion
function ff_validate_code(element,message)
{if(element.value!='')
{dbcodes_string=dbcodes_string.push(validations);dbcode=dbcodes_string.split(',');code=element.value.substring(element.value.length-4,element.value.length);code=element.value;for(p=0;p<5;p++){if(code==dbcode[p])
return '';}if(message=='')message='Code NICHT vorhanden!\n\n'
ff_validationFocus(element.name);return message;}if(message=='')message='Bitte Code eintragen!\n\n'
ff_validationFocus(element.name);return message;}



Nun habe ich die Befürchtung das ich die Var nicht richtig verarbeite.
Da meine Java Script Kenntnisse an seine Grenzen stossen, besonders bei der Verarbeitung un Übergabe der Varibalen, muss ich hier noch mals nach Hilfe fragen.

Besten Dank für jeden Tip.
  • lu74
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Karma: 0
  • Page:
  • 1
Moderators: TheMuffinMan, ForumSupport
Time to create page: 0.29 seconds

Facebook Discount - 40% Off!

Fans of our Facebook page here are entitled to get a 1-year-subscription for the price of a 6-months!

Steps to take:

  • Become a fan on Facebook (Like) here
  • Purchase a 6-months-subscription from here
  • Write a quick email to This email address is being protected from spambots. You need JavaScript enabled to view it. with your username and prove of your like and we'll upgrade to the 1-year-subscription

Joomla!® Forms Discount - 40% Off!

Already purchased a forms extension from a different vendor but your requirements changed and now you need a forms extension that is capable of more than just the standards? We help you to keep the costs for a change under control: Get a 40% discount on our professional membership plan! -- meaning timely unlimited access to all current and future commercial extensions, breezingforms themes & apps and Joomla!® templates at crosstec.de, including 1 year of support -- without any website limitations -- Just prove that you previously purchased another forms extension for Joomla!® from a different vendor and you are qualified.

Steps to take:

  • Purchase a 1-year-subscription from here
  • Write a quick email to This email address is being protected from spambots. You need JavaScript enabled to view it. with your username and prove of the purchase for the other form vendor and we'll upgrade to the professional-subscription

About

Crosstec GmbH & Co. KG

Bergisch-Gladbacher-Str. 829

51069 Cologne, Germany

Imprint