Problems, need help? Have a tip or advice? Post it here.
11 posts Page 1 of 2
I need some help here.

i create a register page for extended user. It work good expt the error reporting.
if i use this code :
Code: Select all
<cms:if k_error >
<font color='red'><cms:each k_error ><cms:show item /><br /></cms:each></font>
</cms:if>

Capture.PNG
Capture.PNG (3.73 KiB) Viewed 2792 times

i want to change the error reporting. Like "Title" to "Full Name", "Extended-User Email" to "Email", etc.

So i use this code:
Code: Select all
<cms:if k_error_k_page_title>Please enter your full name!<br/></cms:if>
<cms:if k_error_extended_user_email>Please enter your email!<br/></cms:if>

if i use that code, it result nothing.



Also if i use input that have "required" tag, all the other error reporting will disapear expt the 1 that have "required" tag.

IE, i use security question :
Code: Select all
<cms:input required='1' type='text' name='human' validator='regex=/^Rival$/i' class='form-control unicase-form-control text-input' id='exampleInputEmail2' />


result :
adasdas.PNG
adasdas.PNG (1.22 KiB) Viewed 2792 times

The other error reporting disapear expt the security error reporting.


Please, help me. Thx
As soon as possible!

Touch me up : abada[dot]zulma[at]gmail[dot]com
I don't see anything wrong with the code that you show in your question, so it seems like the problem is coming from somewhere else. You might have to show more of your code for anyone to be able to help find the problem.

If you haven't done this already, try putting in a cms:dump tag to see if the error variables exist in the context where you placed the error message. When you write code that says "IF x THEN y" and you get nothing, that means that x is not true, or else the code is not being processed at all.

Code: Select all
<cms:if k_error_k_page_title>Please enter your full name!<br/><cms:else/>No Page Title Error<br/></cms:if>
<cms:if k_error_extended_user_email>Please enter your email!<br/><cms:else/>No Email Error<br/></cms:if>

Will confirm if the error message doesn't exist in that context. If you still get nothing, it means that the code is not being processed by the page at all.

I think that some other problem in your code must be unexpectedly affecting the error messages. The hard part is finding it.
here is my code : Link
As soon as possible!

Touch me up : abada[dot]zulma[at]gmail[dot]com
@GoingMarryAsap,

I downloaded your template and tested it. This is what happened.

First, I don't have the field "alamat" in my users template, so I changed it to a textarea and made it required.
Code: Select all
<cms:input required ='1' type='textarea' name='alamat' class='form-control unicase-form-control text-input' id='alamat' />

That was interesting because now I have the same problem as you, only with both required fields.
normal-inputs-before-bound.png
normal-inputs-before-bound.png (28.58 KiB) Viewed 2763 times

What seems to be happening is the regular input fields are being validated before the data-bound fields are even being checked. When I add <cms:dump/> it shows that the other errors are not even set. So this is something interesting about mixing data-bound and regular inputs.

You might have to accept that the human test gets validated first. In real-life use, it's probably not too bad a problem. Or make the 'human' field part of your users template and change it to a data-bound input on the front end.
Code: Select all
<cms:editable required='1' type='text' name='human' validator='regex=/^Rival$/i' validator_msg='regex=type Rival to prove you are human.'/>

--- and ---

<cms:input type='bound' name='human' class='form-control unicase-form-control text-input' id='human' />


Next issue:

When I change this
Code: Select all
<cms:if k_error >
<font color='red'><cms:each k_error ><cms:show item /><br /></cms:each></font>
</cms:if>

to this
Code: Select all
<font color="red">                  
<cms:if k_error_k_page_title>Please enter your full name!<br/></cms:if>
<cms:if k_error_extended_user_email>Please enter your email!<br/></cms:if>            
</font>


and remove the human testing completely, error reporting works normally.
it-works.png
it-works.png (38.86 KiB) Viewed 2763 times

If I only remove required='1' from the human testing field, then no errors show up at all. If I fill in the human field properly, then the other errors show up. I think that might be what happened to you. The problem is that it still fails the regex test, but there is no error message for it, so you see nothing.

-SO-

If you move your human testing field into the users template and/or be sure that you include all of the error messages your form might need, then the error reporting should work the way you want it to. I hope that helps.

P.S. When I was playing around with testing this form, it seems like there is a hierarchy to validation. Not all errors are necessarily reported. When certain kinds of validation fail, the form stops processing and never gets to the other errors. Maybe KK can explain more clearly about the different levels of validation. I could be completely wrong about this. :)
Thx so much for your time Tim! Appreciate it!

Now i see it. If i fill Name and Password Field correctly, and fill the Email field incoreectly, and leave the captcha field blank, the error will report only captcha error. But, if fill Name and Password Field correctly, and fill the Email field incorreectly, and fill the captcha field correctly too, the error will report Invalid Email! It is same with the other fields.

So what i got, couch will validate the captcha 1st, and then validate the otther bound field.
Now this is not a problem anymore.

I stick with
Code: Select all
<cms:each k_error ><cms:show item /></cms:each>

cos i confuse how to show error if password field with repeat password field incorrect, or password field filled and the repeat empty. :lol:

If i can ask another question, how to change the default couch error reporting mesage?
I found inside couch/addons/extended/extended-users.php :
Code: Select all
// take the opportunity to add the hidden fields
            if( $PAGE->tpl_name==$this->users_tpl ){
                $html="
                <cms:ignore>
                <cms:editable name='extended_user_css' type='message'>
                <style type=\"text/css\">
                    #k_element_extended_user_id,
                    #k_element_extended_user_email
                    { display:none; }
                </style>
                </cms:editable>
                </cms:ignore>
                <cms:editable label='Extended-User ID' name='extended_user_id' search_type='integer' type='text'>0</cms:editable>
                <cms:editable label='Email' name='extended_user_email' type='text' />
                <cms:editable label='Kata Sandi' name='extended_user_password' type='dummy_password' />
                <cms:editable label='Ulangi Password' name='extended_user_password_repeat' type='dummy_password' />
                ";
                $parser = new KParser( $html, $node->line_num, 0, '', $node->ID );
                $dom = $parser->get_DOM();

                foreach( $dom->children as $child_node ){
                    if( $child_node->type==K_NODE_TYPE_CODE ){
                       $node->children[] = $child_node;
                    }
                }
            }

and i change the label to my desire. But, i cant find the couch default error message. and its not inside lang file. I spend 12 hours finding that error message with no result :lol:
As soon as possible!

Touch me up : abada[dot]zulma[at]gmail[dot]com
I stick with
Code: Select all
<cms:each k_error ><cms:show item /></cms:each>

cos i confuse how to show error if password field with repeat password field incorrect, or password field filled and the repeat empty. :lol:


Don't give up GoingMarry! Try this. It will show each error underneath the correct field and a general error message at the top. A lot like the Couch Admin panel. You can move the error messages or change the markup to fit your design better.
Code: Select all
   <!-- Show Number of Errors on Form -->               
    <cms:if k_error >
        <cms:each k_error >
            <cms:set error_count = k_count 'global'/>
        </cms:each>
        <font color="red">
            <cms:add error_count '1'/> ERROR<cms:if error_count gt '0'>S</cms:if> ON FORM
        </font>
    </cms:if>   
            
                  
                     <div class="form-group">
                        <label class="info-title" for="exampleInputEmail2">Nama Lengkap <span>(Nama Lengkap Harus Diisi!)</span></label>
                        <cms:input type='bound' name='k_page_title' class='form-control unicase-form-control text-input' id='exampleInputEmail2' />
                                <cms:if k_error_k_page_title><font color="red"><cms:show k_error_k_page_title/></font></cms:if>
                     </div>
                     <div class="form-group">
                        <label class="info-title" for="exampleInputEmail2">Alamat Email <span>*</span></label>
                        <cms:input type='bound' name='extended_user_email' class='form-control unicase-form-control text-input' id='exampleInputEmail2' />
                                <cms:if k_error_extended_user_email><font color="red"><cms:show k_error_extended_user_email/></font></cms:if>
                     </div>
                     <div class="form-group">
                        <label class="info-title" for="exampleInputEmail2">Kata Sandi <span>*</span></label>
                        <cms:input type='bound' name='extended_user_password' class='form-control unicase-form-control text-input' id="passwordInput" />
                                <cms:if k_error_extended_user_password><font color="red"><cms:show k_error_extended_user_password/></font></cms:if>
                     </div>
                     <div class="form-group">
                        <label class="info-title" for="exampleInputEmail2">Ulangi Kata Sandi <span>*</span></label>
                        <cms:input type='bound' name='extended_user_password_repeat' class='form-control unicase-form-control text-input' id="confirmPasswordInput" />
                                <cms:if k_error_extended_user_password_repeat><font color="red"><cms:show k_error_extended_user_password_repeat/></font></cms:if>
                        <p><div class="" id="passwordStrength"></div></p>
                     </div>
                     <div class="form-group">
                        <label class="info-title" for="alamat">Alamat <span>*</span></label>
                        <cms:input type='bound' name='alamat' class='form-control unicase-form-control text-input' id='alamat' />
                                <cms:if k_error_alamat><font color="red"><cms:show k_error_alamat/></font></cms:if>
                     </div>
                     <div class="form-group">
                        <label class="info-title" for="exampleInputEmail2">Siapakah Pria Paling Ganteng? <span>(Jawabannya adalah Rival)</span></label>
                        <cms:input required='1' type='text' name='human' validator='regex=/^Rival$/i' validator_msg='required=This field is required.|regex=Type the word Rival if you are not a spam-bot.' class='form-control unicase-form-control text-input' id='exampleInputEmail2' />
                                <cms:if k_error_human><font color="red"><cms:show k_error_human/></font></cms:if>
                     </div>
                     <button type="submit" name="submit" class="btn-upper btn btn-primary checkout-page-button">Daftar</button>
                  </cms:form>
                  <!-- Form END -->

To customize the error messages, use the validator_msg parameter. You see I added it to the "human" field. You can also use it in the editable tag for your data-bound inputs. http://www.couchcms.com/docs/tags-reference/editable/
@Tim,
P.S. When I was playing around with testing this form, it seems like there is a hierarchy to validation. Not all errors are necessarily reported. When certain kinds of validation fail, the form stops processing and never gets to the other errors. Maybe KK can explain more clearly about the different levels of validation. I could be completely wrong about this. :)

In this particular case where we use databound-form to create extended-user, there is indeed an hierarchy -
1. The usual validation that is done by the form. Any errors found are reported and execution ends here.
2. If validation done in step 1 above succeeds, the k_success block executes <cms:db_persist_form /> that tries to create a native 'User' account. This 'User' object does its own validations on the name, email, password and repeat-password fields (the same as are done while creating a user from the admin-panel). Any errors found at this stage are reported.

In @GoingMarryAsap code, only the 'human' field was being validated in the point 1 above. The rest were done in point 2.

If this dichotomy is bothersome, we can do the following -
Instead of directly exposing the extended-user fields as 'bound' fields, we use plain cms:inputs in the form e.g. as follows -
Code: Select all
DisplayName:<br />
<cms:input name='title' label='User-name' type='text' required='1' validator='title_ready|min_len=4|max_len=255' /><br />

Email Address:<br />
<cms:input name='email' label='E-Mail' type='text' required='1' validator='email' /><br />
   
Password:<br />
<cms:input name='password' label='Password' type='text' required='1' validator='min_len=5|max_len=64' /><br />

Repeat Password:<br />
<cms:input name='repeat_password' label='Repeat Password' type='text' required='1' validator='matches_field=password' /><br />

Captcha:<br />
<cms:input name='human' label='Captcha' required='1' type='text' validator='regex=/^Rival$/i' /><br />

<input type="submit" name="submit" value="Create account"/>   

In the code above we are using only normal form fields (none is 'bound'). The important point to note here is that for the name, email, password and repeat-password fields (i.e. the fields that were originally bound) we have attached the same validations as would be done by the 'User' object internally. This way we do all the validations via the form itself ('Point 1').

Now upon successful form submission, we pass these values explicitly to cms:db_persist_form as follows -
Code: Select all
<cms:if k_success >        

    <cms:db_persist_form
        ...
        k_page_title = frm_title
        extended_user_email = frm_email
        extended_user_password = frm_password
        extended_user_password_repeat = frm_repeat_password
    />                   
    ...
    ...

This way we can have all validations, validation messages, labels etc. at one place (in the form itself). The 'point 2' validation will still occur but since we have already validated all values. it will never throw any error of its own.

For someone comparing the original sample code that accompanies extended-users, here is this version of the code -
Code: Select all
<cms:form 
    masterpage=k_user_template
    mode='create'
    enctype='multipart/form-data'
    method='post'
    anchor='0'
    >

    <cms:if k_success >       

        <cms:check_spam email=frm_email />           

        <cms:db_persist_form
            _invalidate_cache='0'
            k_page_name = "<cms:random_name />"
            k_publish_date = '0000-00-00 00:00:00'
           
            k_page_title = frm_title
            extended_user_email = frm_email
            extended_user_password = frm_password
            extended_user_password_repeat = frm_repeat_password
        />                   

        <cms:if k_success >
           
            <cms:send_mail from="<cms:php>echo K_EMAIL_FROM;</cms:php>" to=frm_email subject='New Account Confirmation' debug='1'>
                Please click the following link to activate your account:
                <cms:activation_link   frm_email   />

                Thanks,
                Website Name
            </cms:send_mail>                       
                                   
            <cms:set_flash name='success_msg' value='1' />
            <cms:redirect k_page_link />
        </cms:if>
    </cms:if>

    <cms:if k_error >
        <font color='red'><cms:each k_error ><cms:show item /><br /></cms:each></font>
    </cms:if>       

    DisplayName:<br />
    <cms:input name='title' label='User-name' type='text' required='1' validator='title_ready|min_len=4|max_len=255' /><br />
   
    Email Address:<br />
    <cms:input name='email' label='E-Mail' type='text' required='1' validator='email' /><br />
       
    Password:<br />
    <cms:input name='password' label='Password' type='text' required='1' validator='min_len=5|max_len=64' /><br />
   
    Repeat Password:<br />
    <cms:input name='repeat_password' label='Repeat Password' type='text' required='1' validator='matches_field=password' /><br />

   
    <input type="submit" name="submit" value="Create account"/>       

</cms:form>

Hope it helps.
Thx for helping me KK & Tim!

Now i can confirm this solved :lol: (omg im so happy! finally after 3 days working on this user registration)
Capture.PNG
Capture.PNG (13.75 KiB) Viewed 2740 times


Now i can work for login page, lost password and user profile!

I cant wait to test this app online 8-)

Thx again Mateys!
As soon as possible!

Touch me up : abada[dot]zulma[at]gmail[dot]com
I want to ask how can this technique be applied to profile.php :)
thanks in advance
@orbital, exactly the same technique can be applied to profile.php (or any DBF for that matter) - instead of using 'bound' inputs, use normal inputs and then in the success condition directly pass on the submitted values to cms:db_persist_form.

In your case, the fields used in profile.php are the same as those used in register.php being discussed here. So it should be pretty easy to adapt the code given above.

Please try and let us know if you have any trouble doing it :)
11 posts Page 1 of 2
cron