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.

please help me get past this signup.php page ?

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

  1. #1
    [​IMG]


    [​IMG]

    Code (Text):
    1. <script type='text/javascript'>
    2.  
    3. function formValidator(){
    4.     // Make quick references to our fields
    5.     var firstname = document.getElementById('firstname');
    6.     var addr = document.getElementById('addr');
    7.     var zip = document.getElementById('zip');
    8.     var state = document.getElementById('state');
    9.     var username = document.getElementById('username');
    10.     var email = document.getElementById('email');
    11.  
    12.     // Check each input in the order that it appears in the form!
    13.     if(isAlphabet(firstname, "Please enter only letters for your name")){
    14.         if(isAlphanumeric(addr, "Numbers and Letters Only for Address")){
    15.             if(isNumeric(zip, "Please enter a valid zip code")){
    16.                 if(madeSelection(state, "Please Choose a State")){
    17.                     if(lengthRestriction(username, 6, 8)){
    18.                         if(emailValidator(email, "Please enter a valid email address")){
    19.                             return true;
    20.                         }
    21.                     }
    22.                 }
    23.             }
    24.         }
    25.     }
    26.  
    27.  
    28.     return false;
    29.  
    30. }
    31.  
    32. function notEmpty(elem, helperMsg){
    33.     if(elem.value.length == 0){
    34.         alert(helperMsg);
    35.         elem.focus(); // set the focus to this input
    36.         return false;
    37.     }
    38.     return true;
    39. }
    40.  
    41. function isNumeric(elem, helperMsg){
    42.     var numericExpression = /^[0-9]+$/;
    43.     if(elem.value.match(numericExpression)){
    44.         return true;
    45.     }else{
    46.         alert(helperMsg);
    47.         elem.focus();
    48.         return false;
    49.     }
    50. }
    51.  
    52. function isAlphabet(elem, helperMsg){
    53.     var alphaExp = /^[a-zA-Z]+$/;
    54.     if(elem.value.match(alphaExp)){
    55.         return true;
    56.     }else{
    57.         alert(helperMsg);
    58.         elem.focus();
    59.         return false;
    60.     }
    61. }
    62.  
    63. function isAlphanumeric(elem, helperMsg){
    64.     var alphaExp = /^[0-9a-zA-Z]+$/;
    65.     if(elem.value.match(alphaExp)){
    66.         return true;
    67.     }else{
    68.         alert(helperMsg);
    69.         elem.focus();
    70.         return false;
    71.     }
    72. }
    73.  
    74. function lengthRestriction(elem, min, max){
    75.     var uInput = elem.value;
    76.     if(uInput.length >= min && uInput.length <= max){
    77.         return true;
    78.     }else{
    79.         alert("Please enter between " +min+ " and " +max+ " characters");
    80.         elem.focus();
    81.         return false;
    82.     }
    83. }
    84.  
    85. function madeSelection(elem, helperMsg){
    86.     if(elem.value == "Please Choose"){
    87.         alert(helperMsg);
    88.         elem.focus();
    89.         return false;
    90.     }else{
    91.         return true;
    92.     }
    93. }
    94.  
    95. function emailValidator(elem, helperMsg){
    96.     var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    97.     if(elem.value.match(emailExp)){
    98.         return true;
    99.     }else{
    100.         alert(helperMsg);
    101.         elem.focus();
    102.         return false;
    103.     }
    104. }
    105. </script>
    106.  
    [​IMG]

    [​IMG]

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

    scottlpool2003 Well-Known Member

    Messages:
    1,703
    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 Active Member

    Messages:
    663
    Likes Received:
    18
    Best Answers:
    21
    Trophy Points:
    90
    #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]


    Code (Text):
    1. <script type='text/javascript'>
    2. function formValidator(){
    3.     // Make quick references to our fields
    4.     var firstname = document.getElementById('firstname');
    5.     var addr = document.getElementById('addr');
    6.     var zip = document.getElementById('zip');
    7.     var state = document.getElementById('state');
    8.     var username = document.getElementById('username');
    9.     var email = document.getElementById('email');
    10.     // Check each input in the order that it appears in the form!
    11.     if(isAlphabet(firstname, "Please enter only letters for your name")){
    12.         if(isAlphanumeric(addr, "Numbers and Letters Only for Address")){
    13.             if(isNumeric(zip, "Please enter a valid zip code")){
    14.                 if(madeSelection(state, "Please Choose a State")){
    15.                     if(lengthRestriction(username, 6, 8)){
    16.                         if(emailValidator(email, "Please enter a valid email address")){
    17.                             return true;
    18.                         }
    19.                     }
    20.                 }
    21.             }
    22.         }
    23.     }
    24.     return false;
    25. }
    26. function notEmpty(elem, helperMsg){
    27.     if(elem.value.length == 0){
    28.         alert(helperMsg);
    29.         elem.focus(); // set the focus to this input
    30.         return false;
    31.     }
    32.     return true;
    33. }
    34. function isNumeric(elem, helperMsg){
    35.     var numericExpression = /^[0-9]+$/;
    36.     if(elem.value.match(numericExpression)){
    37.         return true;
    38.     }else{
    39.         alert(helperMsg);
    40.         elem.focus();
    41.         return false;
    42.     }
    43. }
    44. function isAlphabet(elem, helperMsg){
    45.     var alphaExp = /^[a-zA-Z]+$/;
    46.     if(elem.value.match(alphaExp)){
    47.         return true;
    48.     }else{
    49.         alert(helperMsg);
    50.         elem.focus();
    51.         return false;
    52.     }
    53. }
    54. function isAlphanumeric(elem, helperMsg){
    55.     var alphaExp = /^[0-9a-zA-Z]+$/;
    56.     if(elem.value.match(alphaExp)){
    57.         return true;
    58.     }else{
    59.         alert(helperMsg);
    60.         elem.focus();
    61.         return false;
    62.     }
    63. }
    64. function lengthRestriction(elem, min, max){
    65.     var uInput = elem.value;
    66.     if(uInput.length >= min && uInput.length <= max){
    67.         return true;
    68.     }else{
    69.         alert("Please enter between " +min+ " and " +max+ " characters");
    70.         elem.focus();
    71.         return false;
    72.     }
    73. }
    74. function madeSelection(elem, helperMsg){
    75.     if(elem.value == "Please Choose"){
    76.         alert(helperMsg);
    77.         elem.focus();
    78.         return false;
    79.     }else{
    80.         return true;
    81.     }
    82. }
    83. function emailValidator(elem, helperMsg){
    84.     var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    85.     if(elem.value.match(emailExp)){
    86.         return true;
    87.     }else{
    88.         alert(helperMsg);
    89.         elem.focus();
    90.         return false;
    91.     }
    92. }
    93. </script>
    94.  


    [​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 ...


    Code (Text):
    1.  
    2.  
    3. <html>
    4.     <head>
    5.  
    6.  
    7.  
    8.     <form onsubmit='return formValidator()' >
    9.     First Name: <input type='text' id='firstname' /><br />
    10.     Address: <input type='text' id='addr' /><br />
    11.     Zip Code: <input type='text' id='zip' /><br />
    12.     State: <select id='state'>
    13.             <option>Please Choose</option>
    14.             <option>AL</option>
    15.             <option>CA</option>
    16.             <option>TX</option>
    17.             <option>WI</option>
    18.     </select><br />
    19.     Username(6-8 characters): <input type='text' id='username' /><br />
    20.     Email: <input type='text' id='email' /><br />
    21.     <input type='submit' value='Check Form' /><br />
    22.     </form>
    23.  
    24.  
    25.  
    26.  
    27.  
    28.  
    29.     <script type='text/javascript'>
    30.  
    31.     function formValidator(){
    32.         // Make quick references to our fields
    33.         var firstname = document.getElementById('firstname');
    34.         var addr = document.getElementById('addr');
    35.         var zip = document.getElementById('zip');
    36.         var state = document.getElementById('state');
    37.         var username = document.getElementById('username');
    38.         var email = document.getElementById('email');
    39.  
    40.         // Check each input in the order that it appears in the form!
    41.         if(isAlphabet(firstname, "Please enter only letters for your name")){
    42.             if(isAlphanumeric(addr, "Numbers and Letters Only for Address")){
    43.                 if(isNumeric(zip, "Please enter a valid zip code")){
    44.                     if(madeSelection(state, "Please Choose a State")){
    45.                         if(lengthRestriction(username, 6, 8)){
    46.                             if(emailValidator(email, "Please enter a valid email address")){
    47.                                 return true;
    48.                             }
    49.                         }
    50.                     }
    51.                 }
    52.             }
    53.         }
    54.  
    55.  
    56.         return false;
    57.  
    58.     }
    59.  
    60.     function notEmpty(elem, helperMsg){
    61.         if(elem.value.length == 0){
    62.             alert(helperMsg);
    63.             elem.focus(); // set the focus to this input
    64.             return false;
    65.         }
    66.         return true;
    67.     }
    68.  
    69.     function isNumeric(elem, helperMsg){
    70.         var numericExpression = /^[0-9]+$/;
    71.         if(elem.value.match(numericExpression)){
    72.             return true;
    73.         }else{
    74.             alert(helperMsg);
    75.             elem.focus();
    76.             return false;
    77.         }
    78.     }
    79.  
    80.     function isAlphabet(elem, helperMsg){
    81.         var alphaExp = /^[a-zA-Z]+$/;
    82.         if(elem.value.match(alphaExp)){
    83.             return true;
    84.         }else{
    85.             alert(helperMsg);
    86.             elem.focus();
    87.             return false;
    88.         }
    89.     }
    90.  
    91.     function isAlphanumeric(elem, helperMsg){
    92.         var alphaExp = /^[0-9a-zA-Z]+$/;
    93.         if(elem.value.match(alphaExp)){
    94.             return true;
    95.         }else{
    96.             alert(helperMsg);
    97.             elem.focus();
    98.             return false;
    99.         }
    100.     }
    101.  
    102.     function lengthRestriction(elem, min, max){
    103.         var uInput = elem.value;
    104.         if(uInput.length >= min && uInput.length <= max){
    105.             return true;
    106.         }else{
    107.             alert("Please enter between " +min+ " and " +max+ " characters");
    108.             elem.focus();
    109.             return false;
    110.         }
    111.     }
    112.  
    113.     function madeSelection(elem, helperMsg){
    114.         if(elem.value == "Please Choose"){
    115.             alert(helperMsg);
    116.             elem.focus();
    117.             return false;
    118.         }else{
    119.             return true;
    120.         }
    121.     }
    122.  
    123.     function emailValidator(elem, helperMsg){
    124.         var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    125.         if(elem.value.match(emailExp)){
    126.             return true;
    127.         }else{
    128.             alert(helperMsg);
    129.             elem.focus();
    130.             return false;
    131.         }
    132.     }
    133.     </script>
    134.  
    135. </head>
    136. </html>
    137.  
    138.  


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

    check user and signup

    Code (Text):
    1. <?php // signup.php
    2. //include_once 'header.php';
    3. echo <<<_END
    4. <script>
    5. function checkUser(user)
    6. {
    7. if (user.value == '')
    8. {
    9. document.getElementById('info').innerHTML = ''
    10. return
    11. }
    12. params = "user=" + user.value
    13. request = new ajaxRequest()
    14. request.open("POST", "checkuser.php", true)
    15. request.setRequestHeader("Content-type",
    16. "application/x-www-form-urlencoded")
    17. request.setRequestHeader("Content-length", params.length)
    18. request.setRequestHeader("Connection", "close")
    19. request.onreadystatechange = function()
    20. {
    21. if (this.readyState == 4)
    22. {
    23. if (this.status == 200)
    24. {
    25. if (this.responseText != null)
    26.  
    27. {
    28. document.getElementById('info').innerHTML =
    29. this.responseText
    30. }
    31. else alert("Ajax error: No data received")
    32. }
    33. else alert( "Ajax error: " + this.statusText)
    34. }
    35. }
    36. request.send(params)
    37. }
    38. function ajaxRequest()
    39. {
    40. try
    41. {
    42. var request = new XMLHttpRequest()
    43. }
    44. catch(e1)
    45. {
    46. try
    47. {
    48. request = new ActiveXObject("Msxml2.XMLHTTP")
    49. }
    50. catch(e2)
    51. {
    52. try
    53. {
    54. request = new ActiveXObject("Microsoft.XMLHTTP")
    55. }
    56. catch(e3)
    57. {
    58. request = false
    59. }
    60. }
    61. }
    62. return request
    63.  
    64. }
    65. </script>
    66. <h3>Sign up Form</h3>
    67. _END;
    68. $error = $user = $pass = "";
    69. if (isset($_SESSION['user'])) destroySession();
    70. if (isset($_POST['user']))
    71. {
    72. $user = sanitizeString($_POST['user']);
    73. $pass = sanitizeString($_POST['pass']);
    74. if ($user == "" || $pass == "")
    75. {
    76. $error = "Not all fields were entered<br /><br />";
    77. }
    78. else
    79.  
    80. {
    81. $query = "SELECT * FROM members WHERE user='$user'";
    82. if (mysql_num_rows(queryMysql($query)))
    83. {
    84. $error = "That username already exists<br /><br />";
    85. }
    86. else
    87. {
    88. $query = "INSERT INTO rnmembers VALUES('$user', '$pass')";
    89. queryMysql($query);
    90. }
    91. die("<h4>Account created</h4>Please Log in.");
    92. }
    93. }
    94. echo <<<_END
    95. <form method='post' action='signup.php'>$error
    96. Username <input type='text' maxlength='16' name='user' value='$user'
    97. onBlur='checkUser(this)'/><span id='info'></span><br />
    98. Password <input type='text' maxlength='16' name='pass'
    99. value='$pass' /><br />
    100. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    101. <input type='submit' value='Signup' />
    102. </form>
    103. _END;
    104. ?>

    Code (Text):
    1. <form method='post' action='signup.php'>$error
    2. Username <input type='text' maxlength='16' name='user' value='$user'
    3. onBlur='checkUser(this)
    [​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