SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    JS inside php syntax problem!

    Hai folks,

    PHP Code:
    print "<form action=\"" $protocol "://" $_SERVER['HTTP_HOST'] . ":" $port "/login/\" 
    method=POST" 
    "onsubmit=return validate('user','pass');" ">"
    my problem is : js funcation validate() not working.

    But the function is correctly working if i put it in a plain html form.


  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Look at the output of your code. It'll look like this:

    Code:
    <form action="http://www.example.com:80/login/" method=POSTonsubmit=return validate('user','pass');>
    You should see the spacing problem, as well as the missing quotes around the method and onsubmit values.

    You seem to split up then concatenate literal strings completely arbitrarily. Everything after $port can be inside a single set of quotes.

    PHP Code:
    echo '<form action="' $protocol '://' $_SERVER['HTTP_HOST'] . ':' $port '/login/" method="POST" onsubmit="return validate('user','pass');">'

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    funcation
    +1 vote for renaming function to funcation #GetTheFunk

  4. #4
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    Look at the output of your code. It'll look like this:

    Code:
    <form action="http://www.example.com:80/login/" method=POSTonsubmit=return validate('user','pass');>
    You should see the spacing problem, as well as the missing quotes around the method and onsubmit values.

    You seem to split up then concatenate literal strings completely arbitrarily. Everything after $port can be inside a single set of quotes.

    PHP Code:
    echo '<form action="' $protocol '://' $_SERVER['HTTP_HOST'] . ':' $port '/login/" method="POST" onsubmit="return validate('user','pass');">'
    Thanks dan, but still getting an error

    PHP Code:
    echo '<form action="' $protocol '://' $_SERVER['HTTP_HOST'] . ':' $port '/login/" method="POST" onsubmit="return validate('user','pass');">'

    Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/public_html/testrun/index.php on line 75

  5. #5
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    btw, for your reference

    here is the entire original code i am trying to use for my project.

    PHP Code:
    <?php
    #Login Configuration

    #cPanel
    $protocol 'http';
    $port 2082;

    #Secure cPanel
    #$protocol = 'https';
    #$port = 2083;

    #WHM
    #$protocol = 'http';
    #$port = 2086;

    #Secure WHM
    #$protocol = 'https';
    #$port = 2087;

    #Webmail
    #$protocol = 'http';
    #$port = 2095;

    #Secure Webmail
    #$protocol = 'https';
    #$port = 2096;
    ?>

    <html>
    <h1>[Web Hosting Company Name Here]</h1>

    <b>cPanel Login </b><br>

    <?php
    if ($_GET['failed'] == "1") {
    ?>
    <font color=#FF0000>Your login attempt failed!</font>
    <?php
    }
    print 
    "<form action=\"" $protocol "://" $_SERVER['HTTP_HOST'] . ":" $port "/login/\" 
    method=POST>"
    ;
    ?>
    User: <input type="text" name="user"><br>
    Pass: <input type="password" name="pass"><br>
    <?php
    print "<input type=hidden name=failurl value=\"http://" .  $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . "?failed=1\">";
    ?>
    <input type="hidden" name="login_theme" value="default">
    <input type="submit" value="Login">
    </form><br>
    <a href="cpanel-login.phps">Source</a><br>
    Note: This examples requires cPanel 9.4.1 or later!
    The login theme option requests cPanel 11.1.0 or later!
    </html>

  6. #6
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You seem to be novice on string concatenation in PHP :P
    PHP Code:
    echo '<form action="' $protocol '://' $_SERVER['HTTP_HOST'] . ':' $port '/login/" method="POST" onsubmit="return validate(\'user\',\pass\');">'
    See the difference single quotes inside single quotes and double quotes:
    return validate(\'user\',\pass\');
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  7. #7
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Raju Gautam View Post
    You seem to be novice on string concatenation in PHP :P
    PHP Code:
    echo '<form action="' $protocol '://' $_SERVER['HTTP_HOST'] . ':' $port '/login/" method="POST" onsubmit="return validate(\'user\',\pass\');">'
    See the difference single quotes inside single quotes and double quotes:
    return validate(\'user\',\pass\');
    wel sad raju
    i want to review the string concat lessons today it self

    btw, now no syntax error, but the js funcation not firing
    as i sad, when i call the funcation in a plain html form, it was working charm. so nothing wrong with the js part.

  8. #8
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Raju Gautam View Post
    You seem to be novice on string concatenation in PHP :P
    PHP Code:
    echo '<form action="' $protocol '://' $_SERVER['HTTP_HOST'] . ':' $port '/login/" method="POST" onsubmit="return validate(\'user\',\pass\');">'
    See the difference single quotes inside single quotes and double quotes:
    return validate(\'user\',\pass\');
    oops, working!
    you had a typo raju near psss in your first code.

    Thanks folks (dan, cups, raju). problem solved!!

  9. #9
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are using this:
    PHP Code:
    <?php
    #Login Configuration

    #cPanel
    $protocol 'http';
    $port 2082;

    #Secure cPanel
    #$protocol = 'https';
    #$port = 2083;

    #WHM
    #$protocol = 'http';
    #$port = 2086;

    #Secure WHM
    #$protocol = 'https';
    #$port = 2087;

    #Webmail
    #$protocol = 'http';
    #$port = 2095;

    #Secure Webmail
    #$protocol = 'https';
    #$port = 2096;
    ?>

    <html>
    <h1>[Web Hosting Company Name Here]</h1>

    <b>cPanel Login </b><br>

    <?php
    if ($_GET['failed'] == "1") {
    ?>
    <font color=#FF0000>Your login attempt failed!</font>
    <?php
    }
    print 
    "<form action=\"" $protocol "://" $_SERVER['HTTP_HOST'] . ":" $port "/login/\" 
    method=POST>"
    ;
    ?>
    User: <input type="text" name="user"><br>
    Pass: <input type="password" name="pass"><br>
    <?php
    print "<input type=hidden name=failurl value=\"http://" .  $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . "?failed=1\">";
    ?>
    <input type="hidden" name="login_theme" value="default">
    <input type="submit" value="Login">
    </form><br>
    <a href="cpanel-login.phps">Source</a><br>
    Note: This examples requires cPanel 9.4.1 or later!
    The login theme option requests cPanel 11.1.0 or later!
    </html>
    There I cannot see the javascript function defined anywhere. Even your modified form tag is not implemented here. So if you can give us the complete file then only we can help you I think.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  10. #10
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Raju Gautam View Post
    If you are using this:
    PHP Code:
    <?php
    #Login Configuration

    #cPanel
    $protocol 'http';
    $port 2082;

    #Secure cPanel
    #$protocol = 'https';
    #$port = 2083;

    #WHM
    #$protocol = 'http';
    #$port = 2086;

    #Secure WHM
    #$protocol = 'https';
    #$port = 2087;

    #Webmail
    #$protocol = 'http';
    #$port = 2095;

    #Secure Webmail
    #$protocol = 'https';
    #$port = 2096;
    ?>

    <html>
    <h1>[Web Hosting Company Name Here]</h1>

    <b>cPanel Login </b><br>

    <?php
    if ($_GET['failed'] == "1") {
    ?>
    <font color=#FF0000>Your login attempt failed!</font>
    <?php
    }
    print 
    "<form action=\"" $protocol "://" $_SERVER['HTTP_HOST'] . ":" $port "/login/\" 
    method=POST>"
    ;
    ?>
    User: <input type="text" name="user"><br>
    Pass: <input type="password" name="pass"><br>
    <?php
    print "<input type=hidden name=failurl value=\"http://" .  $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . "?failed=1\">";
    ?>
    <input type="hidden" name="login_theme" value="default">
    <input type="submit" value="Login">
    </form><br>
    <a href="cpanel-login.phps">Source</a><br>
    Note: This examples requires cPanel 9.4.1 or later!
    The login theme option requests cPanel 11.1.0 or later!
    </html>
    There I cannot see the javascript function defined anywhere. Even your modified form tag is not implemented here. So if you can give us the complete file then only we can help you I think.
    Hai raju,
    this is the thing,
    i want my clients to to be able to login from my reseller webhosting home page in to cpenel directly. so i am using the cpanel custom login example and put that in my login page, but i need to validate the fields. so i need to put a js funcation inside the cpanel provided example. thats why all this

    now all working after your correction.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •