1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.
  2. Better Analytics for WordPress Get It Free

please help me get past this signup.php page ?

Discussion in 'PHP' started by gether, Jul 22, 2013.

  1. #1
    [​IMG]


    [​IMG]

    <script type='text/javascript'>
     
    function formValidator(){
        // Make quick references to our fields
        var firstname = document.getElementById('firstname');
        var addr = document.getElementById('addr');
        var zip = document.getElementById('zip');
        var state = document.getElementById('state');
        var username = document.getElementById('username');
        var email = document.getElementById('email');
     
        // Check each input in the order that it appears in the form!
        if(isAlphabet(firstname, "Please enter only letters for your name")){
            if(isAlphanumeric(addr, "Numbers and Letters Only for Address")){
                if(isNumeric(zip, "Please enter a valid zip code")){
                    if(madeSelection(state, "Please Choose a State")){
                        if(lengthRestriction(username, 6, 8)){
                            if(emailValidator(email, "Please enter a valid email address")){
                                return true;
                            }
                        }
                    }
                }
            }
        }
     
     
        return false;
     
    }
     
    function notEmpty(elem, helperMsg){
        if(elem.value.length == 0){
            alert(helperMsg);
            elem.focus(); // set the focus to this input
            return false;
        }
        return true;
    }
     
    function isNumeric(elem, helperMsg){
        var numericExpression = /^[0-9]+$/;
        if(elem.value.match(numericExpression)){
            return true;
        }else{
            alert(helperMsg);
            elem.focus();
            return false;
        }
    }
     
    function isAlphabet(elem, helperMsg){
        var alphaExp = /^[a-zA-Z]+$/;
        if(elem.value.match(alphaExp)){
            return true;
        }else{
            alert(helperMsg);
            elem.focus();
            return false;
        }
    }
     
    function isAlphanumeric(elem, helperMsg){
        var alphaExp = /^[0-9a-zA-Z]+$/;
        if(elem.value.match(alphaExp)){
            return true;
        }else{
            alert(helperMsg);
            elem.focus();
            return false;
        }
    }
     
    function lengthRestriction(elem, min, max){
        var uInput = elem.value;
        if(uInput.length >= min && uInput.length <= max){
            return true;
        }else{
            alert("Please enter between " +min+ " and " +max+ " characters");
            elem.focus();
            return false;
        }
    }
     
    function madeSelection(elem, helperMsg){
        if(elem.value == "Please Choose"){
            alert(helperMsg);
            elem.focus();
            return false;
        }else{
            return true;
        }
    }
     
    function emailValidator(elem, helperMsg){
        var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
        if(elem.value.match(emailExp)){
            return true;
        }else{
            alert(helperMsg);
            elem.focus();
            return false;
        }
    }
    </script>
    
    Code (markup):
    [​IMG]

    [​IMG]

    [​IMG]
     
    gether, Jul 22, 2013 IP
  2. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,707
    Likes Received:
    48
    Best Answers:
    9
    Trophy Points:
    100
    #2
    A description of the problem, things you have tried, expected outcome, actual outcome would help!
     
    scottlpool2003, Jul 22, 2013 IP
    badmas likes this.
  3. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    721
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    115
    #3
    I see a lot of images, but you haven't actually asked a question. What do you need help with? Post actual code examples not just images as we all don't want to have to write everything from scratch.
     
    HuggyStudios, Jul 22, 2013 IP
  4. gether

    gether Greenhorn

    Messages:
    87
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #4
    i think i can improve this a better ....


    [​IMG]


    <script type='text/javascript'>
    function formValidator(){
        // Make quick references to our fields
        var firstname = document.getElementById('firstname');
        var addr = document.getElementById('addr');
        var zip = document.getElementById('zip');
        var state = document.getElementById('state');
        var username = document.getElementById('username');
        var email = document.getElementById('email');
        // Check each input in the order that it appears in the form!
        if(isAlphabet(firstname, "Please enter only letters for your name")){
            if(isAlphanumeric(addr, "Numbers and Letters Only for Address")){
                if(isNumeric(zip, "Please enter a valid zip code")){
                    if(madeSelection(state, "Please Choose a State")){
                        if(lengthRestriction(username, 6, 8)){
                            if(emailValidator(email, "Please enter a valid email address")){
                                return true;
                            }
                        }
                    }
                }
            }
        }
        return false;
    }
    function notEmpty(elem, helperMsg){
        if(elem.value.length == 0){
            alert(helperMsg);
            elem.focus(); // set the focus to this input
            return false;
        }
        return true;
    }
    function isNumeric(elem, helperMsg){
        var numericExpression = /^[0-9]+$/;
        if(elem.value.match(numericExpression)){
            return true;
        }else{
            alert(helperMsg);
            elem.focus();
            return false;
        }
    }
    function isAlphabet(elem, helperMsg){
        var alphaExp = /^[a-zA-Z]+$/;
        if(elem.value.match(alphaExp)){
            return true;
        }else{
            alert(helperMsg);
            elem.focus();
            return false;
        }
    }
    function isAlphanumeric(elem, helperMsg){
        var alphaExp = /^[0-9a-zA-Z]+$/;
        if(elem.value.match(alphaExp)){
            return true;
        }else{
            alert(helperMsg);
            elem.focus();
            return false;
        }
    }
    function lengthRestriction(elem, min, max){
        var uInput = elem.value;
        if(uInput.length >= min && uInput.length <= max){
            return true;
        }else{
            alert("Please enter between " +min+ " and " +max+ " characters");
            elem.focus();
            return false;
        }
    }
    function madeSelection(elem, helperMsg){
        if(elem.value == "Please Choose"){
            alert(helperMsg);
            elem.focus();
            return false;
        }else{
            return true;
        }
    }
    function emailValidator(elem, helperMsg){
        var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
        if(elem.value.match(emailExp)){
            return true;
        }else{
            alert(helperMsg);
            elem.focus();
            return false;
        }
    }
    </script>
    
    Code (markup):


    [​IMG]


    [​IMG]
     
    gether, Sep 18, 2013 IP
    bartolay13 likes this.
  5. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #5
    no it doesn't improve
     
    bartolay13, Sep 18, 2013 IP
  6. gether

    gether Greenhorn

    Messages:
    87
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #6
    this is a signup.php page that does a lot of things... my arrangement of code does not feel appropriate

    it has parts of a html form ...

    javascript ...

    php ....


    in that order ....

    i have a lot of things to do before i can make it work ....

    it is supposed to do form feild validation with javascript ... and it checks the mysql table for duplicate users with php code ......


    first of all i have to decide on the form ...

    [​IMG]


    then the way the code should be arranged....

    i like the form feild validation to work first ...


    
    
    <html>
        <head>
    
    
    
        <form onsubmit='return formValidator()' >
        First Name: <input type='text' id='firstname' /><br />
        Address: <input type='text' id='addr' /><br />
        Zip Code: <input type='text' id='zip' /><br />
        State: <select id='state'>
                <option>Please Choose</option>
                <option>AL</option>
                <option>CA</option>
                <option>TX</option>
                <option>WI</option>
        </select><br />
        Username(6-8 characters): <input type='text' id='username' /><br />
        Email: <input type='text' id='email' /><br />
        <input type='submit' value='Check Form' /><br />
        </form>
    
    
    
    
    
    
        <script type='text/javascript'>
    
        function formValidator(){
            // Make quick references to our fields
            var firstname = document.getElementById('firstname');
            var addr = document.getElementById('addr');
            var zip = document.getElementById('zip');
            var state = document.getElementById('state');
            var username = document.getElementById('username');
            var email = document.getElementById('email');
    
            // Check each input in the order that it appears in the form!
            if(isAlphabet(firstname, "Please enter only letters for your name")){
                if(isAlphanumeric(addr, "Numbers and Letters Only for Address")){
                    if(isNumeric(zip, "Please enter a valid zip code")){
                        if(madeSelection(state, "Please Choose a State")){
                            if(lengthRestriction(username, 6, 8)){
                                if(emailValidator(email, "Please enter a valid email address")){
                                    return true;
                                }
                            }
                        }
                    }
                }
            }
    
    
            return false;
    
        }
    
        function notEmpty(elem, helperMsg){
            if(elem.value.length == 0){
                alert(helperMsg);
                elem.focus(); // set the focus to this input
                return false;
            }
            return true;
        }
    
        function isNumeric(elem, helperMsg){
            var numericExpression = /^[0-9]+$/;
            if(elem.value.match(numericExpression)){
                return true;
            }else{
                alert(helperMsg);
                elem.focus();
                return false;
            }
        }
    
        function isAlphabet(elem, helperMsg){
            var alphaExp = /^[a-zA-Z]+$/;
            if(elem.value.match(alphaExp)){
                return true;
            }else{
                alert(helperMsg);
                elem.focus();
                return false;
            }
        }
    
        function isAlphanumeric(elem, helperMsg){
            var alphaExp = /^[0-9a-zA-Z]+$/;
            if(elem.value.match(alphaExp)){
                return true;
            }else{
                alert(helperMsg);
                elem.focus();
                return false;
            }
        }
    
        function lengthRestriction(elem, min, max){
            var uInput = elem.value;
            if(uInput.length >= min && uInput.length <= max){
                return true;
            }else{
                alert("Please enter between " +min+ " and " +max+ " characters");
                elem.focus();
                return false;
            }
        }
    
        function madeSelection(elem, helperMsg){
            if(elem.value == "Please Choose"){
                alert(helperMsg);
                elem.focus();
                return false;
            }else{
                return true;
            }
        }
    
        function emailValidator(elem, helperMsg){
            var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
            if(elem.value.match(emailExp)){
                return true;
            }else{
                alert(helperMsg);
                elem.focus();
                return false;
            }
        }
        </script>
    
    </head>
    </html>
    
    
    Code (markup):


    then check the user is already there in the table...

    check user and signup

    <?php // signup.php
    //include_once 'header.php';
    echo <<<_END
    <script>
    function checkUser(user)
    {
    if (user.value == '')
    {
    document.getElementById('info').innerHTML = ''
    return
    }
    params = "user=" + user.value
    request = new ajaxRequest()
    request.open("POST", "checkuser.php", true)
    request.setRequestHeader("Content-type",
    "application/x-www-form-urlencoded")
    request.setRequestHeader("Content-length", params.length)
    request.setRequestHeader("Connection", "close")
    request.onreadystatechange = function()
    {
    if (this.readyState == 4)
    {
    if (this.status == 200)
    {
    if (this.responseText != null)
    
    {
    document.getElementById('info').innerHTML =
    this.responseText
    }
    else alert("Ajax error: No data received")
    }
    else alert( "Ajax error: " + this.statusText)
    }
    }
    request.send(params)
    }
    function ajaxRequest()
    {
    try
    {
    var request = new XMLHttpRequest()
    }
    catch(e1)
    {
    try
    {
    request = new ActiveXObject("Msxml2.XMLHTTP")
    }
    catch(e2)
    {
    try
    {
    request = new ActiveXObject("Microsoft.XMLHTTP")
    }
    catch(e3)
    {
    request = false
    }
    }
    }
    return request
    
    }
    </script>
    <h3>Sign up Form</h3>
    _END;
    $error = $user = $pass = "";
    if (isset($_SESSION['user'])) destroySession();
    if (isset($_POST['user']))
    {
    $user = sanitizeString($_POST['user']);
    $pass = sanitizeString($_POST['pass']);
    if ($user == "" || $pass == "")
    {
    $error = "Not all fields were entered<br /><br />";
    }
    else
    
    {
    $query = "SELECT * FROM members WHERE user='$user'";
    if (mysql_num_rows(queryMysql($query)))
    {
    $error = "That username already exists<br /><br />";
    }
    else
    {
    $query = "INSERT INTO rnmembers VALUES('$user', '$pass')";
    queryMysql($query);
    }
    die("<h4>Account created</h4>Please Log in.");
    }
    }
    echo <<<_END
    <form method='post' action='signup.php'>$error
    Username <input type='text' maxlength='16' name='user' value='$user'
    onBlur='checkUser(this)'/><span id='info'></span><br />
    Password <input type='text' maxlength='16' name='pass'
    value='$pass' /><br />
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    <input type='submit' value='Signup' />
    </form>
    _END;
    ?>
    Code (markup):

    <form method='post' action='signup.php'>$error
    Username <input type='text' maxlength='16' name='user' value='$user'
    onBlur='checkUser(this)
    Code (markup):
    [​IMG]


    so javascript ajax calling a php file onblur... and that php file doing some things ... then.. on submit .... the form calling another php file ...
     
    Last edited: Sep 18, 2013
    gether, Sep 18, 2013 IP
  7. gether

    gether Greenhorn

    Messages:
    87
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #7
    [​IMG]

    [​IMG]
     
    Last edited: Sep 19, 2013
    gether, Sep 18, 2013 IP
  8. gether

    gether Greenhorn

    Messages:
    87
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #8
    i cant find the edit button .. otherwise i would have edited my earlier posts.. and posted the improved version of my concept of a nice html form ...
    which has html javascript javascript ajax php and mysql ...

    [​IMG]
     
    Last edited: Sep 21, 2013
    gether, Sep 21, 2013 IP