Giter Club home page Giter Club logo

Comments (19)

SWEz11 avatar SWEz11 commented on July 16, 2024 1

Thank you daveh for all your support:)!

from php-signup-login.

SWEz11 avatar SWEz11 commented on July 16, 2024

And i make it in validation.js:
validation

.addField("#name", [
    {
        rule: "required"
    },
    {
        rule: "name"
    },
    {
        validator: (value) => () => {
            return fetch("validate-name.php?email=" + encodeURIComponent(value))
                   .then(function(response) {
                       return response.json();
                   })
                   .then(function(json) {
                       return json.available;
                   });
        },
        errorMessage: "Name already taken"
    }
])

But it won't work

from php-signup-login.

daveh avatar daveh commented on July 16, 2024

In what way doesn't it work? Do you get any error messages? Try debugging the code by inserting debugging statements to print out the values of the variables at different stages

from php-signup-login.

SWEz11 avatar SWEz11 commented on July 16, 2024

Hello daveh,

Thank you for response!

It seems like just the validate-name.php be skipped when the button be pressed in register window. No errors. Did I need connect the validate-name.php with process-signup or something like that? Or need write specific code for name checking? Thanks:)

from php-signup-login.

daveh avatar daveh commented on July 16, 2024

In your JavaScript, you're passing the name value in the query string with an index of "email":

return fetch("validate-name.php?email=" + encodeURIComponent(value))

but then getting this on the server with an index of name: $_GET["name"]

Try changing them so they match, e.g.

return fetch("validate-name.php?name=" + encodeURIComponent(value))

from php-signup-login.

SWEz11 avatar SWEz11 commented on July 16, 2024

I already do it, but still didn't work

from php-signup-login.

daveh avatar daveh commented on July 16, 2024

Check the browser console to see what JS requests are being made, and if there are any errors

from php-signup-login.

SWEz11 avatar SWEz11 commented on July 16, 2024

That's I've got when I pressed signup button
image From console I've got nothing

from php-signup-login.

daveh avatar daveh commented on July 16, 2024

From that it looks like the JavaScript validation isn't running when you submit the form. Check the code that attaches the validation to the form, it could be that.

from php-signup-login.

SWEz11 avatar SWEz11 commented on July 16, 2024

It seem the validation is attached, but from now when I go to the signup.html page it show error in console:
image
A somehow the code didn't change in website

This code from vs studio:

const validation = new JustValidate("#signup");

validation
    .addField("#name", [
        {
            rule: "required"
        },
        {
            rule: "name"
        },
        {
            validator: (value) => () => {
                return fetch("validate-name.php?name=" + encodeURIComponent(value))
                        .then(function(response) {
                        console.log("Server Response:", response);  // Add this line
                        return response.json();
                        })
                       .then(function(json) {
                           return json.available;
                       });
            },
            errorMessage: "Name already taken"
        }
    ])
    .addField("#email", [
        {
            rule: "required"
        },
        {
            rule: "email"
        },
        {
            validator: (value) => () => {
                return fetch("validate-email.php?email=" + encodeURIComponent(value))
                       .then(function(response) {
                           return response.json();
                       })
                       .then(function(json) {
                           return json.available;
                       });
            },
            errorMessage: "email already taken"
        }
    ])
    .addField("#password", [
        {
            rule: "required"
        },
        {
            rule: "password"
        }
    ])
    .addField("#password_confirmation", [
        {
            validator: (value, fields) => {
                return value === fields["#password"].elem.value;
            },
            errorMessage: "Passwords should match"
        }
    ])
    .onSuccess((event) => {
        document.getElementById("signup").submit();
    });

And what code I see in chrome:

const validation = new JustValidate("#signup");

validation
    .addField("#name", [
        {
            rule: "required"
        }
    ])
    .addField("#email", [
        {
            rule: "required"
        },
        {
            rule: "email"
        },
        {
            validator: (value) => () => {
                return fetch("validate-email.php?email=" + encodeURIComponent(value))
                       .then(function(response) {
                           return response.json();
                       })
                       .then(function(json) {
                           return json.available;
                       });
            },
            errorMessage: "email already taken"
        }
    ])
    .addField("#password", [
        {
            rule: "required"
        },
        {
            rule: "password"
        }
    ])
    .addField("#password_confirmation", [
        {
            validator: (value, fields) => {
                return value === fields["#password"].elem.value;
            },
            errorMessage: "Passwords should match"
        }
    ])
    .onSuccess((event) => {
        document.getElementById("signup").submit();
    });

But I don't know it make a sence.
But the error can be solution

from php-signup-login.

daveh avatar daveh commented on July 16, 2024

If JustValidate is not defined, then it looks like that library isn't being loaded. Check the network console to see if there is an error when requesting that file, or make sure you're loading that file before your own one.

from php-signup-login.

SWEz11 avatar SWEz11 commented on July 16, 2024

I added this line in signup.html:
<script src="https://unpkg.com/[email protected]/dist/js/just-validate.min.js"></script>
And now in network console show this:
image

Now it seems the validation.js is working but show the just-validate.min.js been failed it when you pressed on the just-validate.min.js text it in next page show this:
image
It can be the version problem but I don't know how to get normal link with normal version ( I get it from ChatGPT)

But when you enter already create name it still allow to signup

from php-signup-login.

daveh avatar daveh commented on July 16, 2024

You can get it from the official website:

<script src="https://unpkg.com/just-validate@latest/dist/just-validate.production.min.js"></script>

from php-signup-login.

SWEz11 avatar SWEz11 commented on July 16, 2024

Yea it work with js!
image
But still allow to use already taken name
image

from php-signup-login.

daveh avatar daveh commented on July 16, 2024

Try debugging by seeing what value is being returned from the script that checks the email address and returns a value to the JavaScript

from php-signup-login.

SWEz11 avatar SWEz11 commented on July 16, 2024

Now I tried in localhost Host and it seems the website signup.html see validation normally because in website Host it just validation look like this .addField("#name", [ { rule: "required" } ])

instead looking like this:
.addField("#name", [ { rule: "required" }, { rule: "name" }, { validator: (value) => () => { return fetch("validate-name.php?name=" + encodeURIComponent(value)) .then(function(response) { console.log("Server Response:", response); // Add this line return response.json(); }) .then(function(json) { return json.available; }); }, errorMessage: "Name already taken" } ])

In local host I'm getting signup.html console error:
Uncaught Error: Rule should be one of these types: required, email, minLength, maxLength, password, number, integer, maxNumber, minNumber, strongPassword, customRegexp, minFilesCount, maxFilesCount, files. Provided value: name at just-validate.production.min.js:1:18898 at Array.forEach (<anonymous>) at Object.addField (just-validate.production.min.js:1:18676) at validation.js:4:6

And I cant press signup button:
image

validation.js 4 line: 
` .addField("#name", [`.

PS: In both places (LocalHost , Website Host):
Read the validate-name.php: because when I enter websitename.com/path/path2/validate-name.php?name=5353

I'm getting this: 

image

from php-signup-login.

daveh avatar daveh commented on July 16, 2024

Perhaps the syntax has changed in a more recent version of JustValidate - the documentation is here.

from php-signup-login.

SWEz11 avatar SWEz11 commented on July 16, 2024

It work:)! But small problem: How why when I press the signup button without writting email address in email area. It just say email already exits if I didn't not write anything
image

from php-signup-login.

daveh avatar daveh commented on July 16, 2024

Try debugging the script that checks the emails by running the PHP code directly with an empty string for the email address. You can run the PHP script directly by requesting it in the browser's address bar, passing the email in the query string. You can print out debugging statements to see what values the various statements in the PHP are returning, to see where the issue is.

from php-signup-login.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.