JS inside php syntax problem!

Hai folks,

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.

:rolleyes:

Look at the output of your code. It’ll look like this:

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

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

funcation

+1 vote for renaming function to funcation #GetTheFunk

btw, for your reference

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


<?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>

Thanks dan, but still getting an error :smiley:

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

You seem to be novice on string concatenation in PHP :stuck_out_tongue:


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!!

wel sad raju :slight_smile:
i want to review the string concat lessons today it self :slight_smile:

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

If you are using this:


<?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 :smiley:

now all working after your correction.