1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Auto Validator

Discussion in 'XenForo Development Discussions' started by ragtek, Jan 12, 2011.

  1. ragtek

    ragtek Guest

    How is the js AUto Validator working?

    That's my implemention:
    public function actionValidateField()
    $field $this->_getFieldValidationInputParams();

    $data = array(
    'name'  =>  'invited_mail',
    'value' =>  $field['value']

    <form action="{xen:link 'invites/invite'}" method="post" class="xenForm AutoValidator"
    	data-fieldValidatorUrl="{xen:link invites/validate-field}"
    	<xen:if is="{$errors}">
    		<div class="errorPanel">
    			<h3 class="errorHeading">{xen:phrase please_correct_following_errors}:</h3>
    			<div class="baseHtml errors">
    				<xen:foreach loop="$errors" value="$error">
    					<li>{xen:raw $error}</li>
    	<dl class="ctrlUnit">
    		<dt><label for="ctrl_name">Name:</label></dt>
    			<input type="text" name="username" class="textCtrl OptOut" id="ctrl_name" autofocus="true" />
    			<p class="explain">Name for the e-mail</p>
    	<dl class="ctrlUnit">
    		<dt><label for="ctrl_mail">{xen:phrase mail}:</label></dt>
    			<input type="text" name="mail" class="textCtrl" id="ctrl_mail" autofocus="true" autocomplete="off" />
    			<p class="explain">Name for the e-mail</p>
    FireBug tells me, that i'm getting this error(with an false mailadress):
    {"error":{"email":"Please enter a valid email."},"templateHtml":"\n\n\n<div class=\"errorOverlay\">\n\t<a class=\"close OverlayCloser\"><\/a>\n\t\n\t\t<h2 class=\"heading\">The following error occurred:<\/h2>\n\t\t\n\t\t<div class=\"baseHtml\">\n\t\t\n\t\t\t<label for=\"ctrl_email\" class=\"OverlayCloser\">Please enter a valid email.<\/label>\n\t\t\n\t\t<\/div>\n\t\n<\/div>"}

    If the mailadress is valid, i'm getting:
    {"_redirectStatus":"ok","_redirectTarget":"\/xf\/upload\/","_redirectMessage":"The value 'mike@ragtek.org' was successfully validated against field 'invited_mail'."}
    BUT i can't see any message in the frontend:(
  2. ragtek

    ragtek Guest

    Problem solved:)

    The id have to be "email" and not mail.
    But i don't know why^^
  3. tenants

    tenants Well-Known Member

    I belive the validation is done against the datawriter (old thread, but I'm looking at this area at the moment)

    So if you look XenForo_Controller:: _validateField, it uses "$writer = XenForo_DataWriter::create($dataWriterName);"

    For instance, the registraion form uses the "User" datawritter to validate against, so if you look at the User datawriter, it uses the parameter: "email" (as you found ;) )

    protected function _getFields()
            return array(
                'xf_user' => array(
                        => array('type' => self::TYPE_STRING, 'maxLength' => 120, 'verification' => array('$this', '_verifyEmail'), 'requiredError' => 'please_enter_valid_email'),
    You probably know more about this than me now, but thought I would add this just in case it's useful to anyone else

    (but you were using a datawriter above, I've still no idea how the message in the front end is used)
  4. Chris D

    Chris D XenForo Developer Staff Member

    That's actually really useful :)

    I'll be doing a lot of stuff with field validators soon so this has helped me understand it a bit better.
  5. tenants

    tenants Well-Known Member

    I'm still trying to get my head around it, but within that datawriter you'll have:

    'verification' => array('$this', '_verifyEmail')

    the function _verifyEmail is also found in the XenForo_DataWriter_User and tells you what it verifies against
  6. tenants

    tenants Well-Known Member

    yep, I'm now having the same issue as Ragtek

    I'm forcing the email field to have a different name (it has to in my case), on validation, if the email format is incorrect, the datawriter returns the response :

    {"error":{"email":"Please enter a valid email."}

    This is good so far, but now the message needs to be displayed to the user

    ... time to look at the JavaScript behind this

Share This Page