Forum

Thread tagged as: Problem, Forms, Members

Perch Members / Shop check_email not working

I'm using the form below for shop members to update their name and email address. Obviously if they enter an email address that already exists in the database it won't be updated. I've added the helper attribute to the email form input (line 20) and an error message which should tell the user what's going on (line 23).

When I test by entering an address that's already in the database, the form submits and displays the <perch:success> content. But the email address hasn't been changed of course.

Any ideas for getting the error message working would be appreciated.

My template code is:

<perch:form id="profile" method="post" app="perch_members" class="standard-styles">

    <!-- Hidden inputs at the beginning of the form -->
    <perch:input type="hidden" id="token" />

    <div class="form-group">
        <perch:label for="first_name">First Name</perch:label>
        <perch:input type="text" id="first_name" required="true" label="First name" class="form-control" />
        <perch:error for="first_name" type="required">Please enter your first name</perch:error>
    </div>

    <div class="form-group">
        <perch:label for="last_name">Last name</perch:label>
        <perch:input type="text" id="last_name" required="true" label="Last name" class="form-control" />
        <perch:error for="last_name" type="required">Please enter your last name</perch:error>
    </div>

    <div class="form-group">
        <perch:label for="email">Email</perch:label>
        <perch:input type="email" id="email" required="true" placeholder="you@company.com" helper="PerchMembers_Members::check_email" class="form-control" />
        <perch:error for="email" type="required">Please enter your email address</perch:error>
        <perch:error for="email" type="format">Please check a your email address is correct</perch:error>
        <perch:error for="email" type="helper">That email address is already in use, please use another</perch:error>
    </div>

    <perch:input type="submit" value="Update Details" class="btn btn-primary" />

    <perch:success>
        <div class="alert alert-info">
            <p>Your personal details have been successfully updated</p>
        </div>

        <div class="standard-bottom-margin">
            <a href="/members/account" class="btn btn-default">Back To Your Account</a>
        </div>
    </perch:success>

</perch:form>
<perch:showall />

Perch showall content is:

ID    Value
perch_page_path /members/edit-personal-details.php
first_name  Martin Test Two
last_name   Jewiss
token   55ba260266d1c6fa562c1a6b1bf266b1b419fc75
memberID    18
memberAuthType  native
memberAuthID    18
memberEmail martin3@withverse.uk
memberPassword  $P$B7iw.9oDZwsoMkmbg7x63DREvvOROd0
memberStatus    active
memberCreated   2017-04-05 17:04:58
memberExpires   
tags    

Array
(
)

sessionID   0910733006457a9136eeec7aecd3a901a80ca9aa
email   martin3@withverse.uk
status  active
expires 
auth_id 18
id  18
perch_namespace perch:forms

And diagnostics are:


Perch: 2.8.34, PHP: 5.6.9-1+deb.sury.org~trusty+2, MySQL: 5.5.49, with PDO Server OS: Linux, apache2handler Installed apps: content (2.8.34), assets (2.8.34), categories (2.8.34), jw_activity_log (1.0.0), perch_shop_orders (1.0.10), perch_shop_products (1.0.10), perch_shop (1.0.10), perch_members (1.5) App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_members', 'perch_shop', ); PERCH_LOGINPATH: /perch PERCH_PATH: /vagrant/www/kingsdownwater/public_html/perch PERCH_CORE: /vagrant/www/kingsdownwater/public_html/perch/core PERCH_RESFILEPATH: /vagrant/www/kingsdownwater/public_html/perch/resources Image manipulation: PHP limits: Max upload 2M, Max POST 8M, Memory: 128M, Total max file upload: 2M F1: 6a33f95eca3667f9e0c39bf5ca2980fe Resource folder writeable: Yes HTTP_HOST: kingsdownwater.dev DOCUMENT_ROOT: /vagrant/www/kingsdownwater/public_html REQUEST_URI: /perch/core/settings/diagnostics/ SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
Martin Jewiss

Martin Jewiss 0 points

  • 4 years ago

Update: I've tried disabling the html5 native validation. The email_chech still does not throw an error when it should.

Drew McLellan

Drew McLellan 2638 points
Perch Support

All that helper does is check that the email address isn't in use by another member. It doesn't stop the user updating their own email address, or from submitting the form without changing their email address.

Understood.

So is there a way I can get the form to display an error message saying that the email address can't be updated if it is already in use by a different member?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Would there be any reason why your member might not have a password?

No, they'll always have a password Drew.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you show me the debug output when you get the success message?

Here's the debug output when the success message is shown Drew. FYI martin3@withverse.uk is the current email address. The address I entered and wanted to update to is martin@mpjdesign.ltd.uk

ID: Value
perch_page_path:    /members/edit-personal-details.php
first_name: Martin
last_name:  Jewiss
token:  210e7cf74ec2c7f768915bf19bdd96fe310b6085
memberID:   18
memberAuthType: native
memberAuthID:   18
memberEmail:    martin3@withverse.uk
memberPassword: $P$B7iw.9oDZwsoMkmbg7x63DREvvOROd0
memberStatus    :  active
memberCreated:  2017-04-05 17:04:58
memberExpires:  
tags:   

Array
(
)

sessionID:  1c45222a77506841ccc41b03de9185c33b621749
email:  martin3@withverse.uk
status: active
expires:    
auth_id:    18
id: 18
perch_namespace:    perch:forms
Drew McLellan

Drew McLellan 2638 points
Perch Support

That looks like the output from <perch:showall /> to me. Can you show me the debug output?

Sorry Drew, my mistake. It's been a long few days with not much sleep...

Here's the debug output:

Debug Message
[1] SELECT * FROM perch2_members_sessions WHERE sessionID='19b306ddcc42fe92fb84e7461d350fe93b341ad1' AND sessionHttpFootprint='0561fa21b3306555294bbaffcc8af5361e8cf678' AND sessionExpires>'2017-04-06 11:25:24' LIMIT 1
User is logged in
[1] SELECT * FROM perch2_pages WHERE pagePath='/members/edit-personal-details.php' LIMIT 1
[1] SELECT * FROM perch2_shop_cart WHERE cartID=76
[1] SELECT * FROM perch2_shop_cart WHERE cartID=76
[29] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[0] SELECT COUNT(*) FROM perch2_members WHERE memberPassword IS NOT NULL AND memberEmail='martin@mpjdesign.com' AND memberID!=18
[1] SELECT * FROM perch2_members WHERE memberID='18' LIMIT 1
[4] SELECT COUNT(*) FROM perch2_members WHERE memberEmail='martin@mpjdesign.com' AND memberID!=18
UPDATE perch2_members SET memberProperties='{\"first_name\":\"Martin\",\"last_name\":\"Jewiss\",\"token\":\"99271c3e06c41a254f0c23bbce330d04d43ba4dd\"}' WHERE memberID='18'
No ids to log.
[0] SELECT t.tag FROM perch2_members_tags t, perch2_members_member_tags mt WHERE t.tagID=mt.tagID AND mt.memberID='18' AND (mt.tagExpires IS NULL OR mt.tagExpires>'2017-04-06 11:25:00')
INSERT INTO perch2_members_sessions(sessionID,sessionExpires,sessionHttpFootprint,memberID,sessionData) VALUES('1c45222a77506841ccc41b03de9185c33b621749','2017-04-06 13:25:24','0561fa21b3306555294bbaffcc8af5361e8cf678','18','{\"first_name\":\"Martin\",\"last_name\":\"Jewiss\",\"token\":\"210e7cf74ec2c7f768915bf19bdd96fe310b6085\",\"memberID\":\"18\",\"memberAuthType\":\"native\",\"memberAuthID\":\"18\",\"memberEmail\":\"martin3@withverse.uk\",\"memberPassword\":\"$P$B7iw.9oDZwsoMkmbg7x63DREvvOROd0\",\"memberStatus\":\"active\",\"memberCreated\":\"2017-04-05 17:04:58\",\"memberExpires\":null,\"tags\":[]}')
DELETE FROM perch2_members_sessions WHERE sessionExpires < '2017-04-06 11:25:24'
DELETE FROM perch2_members_sessions WHERE sessionID='19b306ddcc42fe92fb84e7461d350fe93b341ad1'
[1] SELECT * FROM perch2_members_sessions WHERE sessionID='1c45222a77506841ccc41b03de9185c33b621749' AND sessionHttpFootprint='0561fa21b3306555294bbaffcc8af5361e8cf678' AND sessionExpires>'2017-04-06 11:25:24' LIMIT 1
User is logged in
------------------------------ here mem ------------------------------
[1] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/members/edit-personal-details.php' OR regionPage='*' ORDER BY regionPage DESC
Using template: /templates/members/forms/profile.html

Ahh, I've pieced together the solution looking at the debug output, Drew. It relates to your question about all members having passwords.

  1. The Perch Shop currently has guest checkout with the password set to __auto__.
  2. I've just tried to update the email address to martin@mpjdesign.com - same result as before with other email addresses.
  3. Looking in the perch2_members table I can see 4 rows with memberEmail = martin@mpjdesign.com that were created with the __auto__ password.
  4. Their memberPassword fields were blank for these members. I thought they would have had the auto generated password recorded.
  5. I've deleted those members from the db, tested again and the helper function works.

Thanks for your help Drew