Jump to content

Submitting forms to and from php using image submit


reyna12

Recommended Posts

It works fine with a normal submit button, but it doesn't appear to be doing anything when i use the image, the cologin page remains blank. Any ideas?


cplogin.php

[code]<?php
  if(!$_POST['login']) {
  exit;
  }
  // Change Domain from form page, <input name="domain" type="hidden" value="utilityservers.net">
  $domain = $_POST['domain'];;
 
  // States that the variable user will be what the user type in to username field
  $user = $_POST['user'];
 
  // States that the variable pass will be what the user type in to password field
  $pass = $_POST['pass'];
 
  // If the user added their domain name to username this will remove it
  $user = str_replace("@$domain","",$user);
 
  switch($logintype){ // You could set this form to log in to others but it is not needed
  case "cpanel": // What to log in to
  $port = "2082"; // Port Number Cpanel Is On
$prefix = "http://"; // Protocol, http or https
$user = $user; // Username is set to username typed in
  break;
  default:
  $port = "2082"; // Port Number Cpanel Is On
$prefix = "http://"; // Protocol, http or https
$user = $user; // Username is set to username typed in
  break;
  }
?>
<html>
<body onLoad="setTimeout('document.forms[0].submit();',10)">
<form action="<?php echo "".$prefix."".$domain.":".$port."/login/"; ?>" method="post">
<input type="hidden" name="user" value="<?php echo $user; ?>">
<input type="hidden" name="pass" value="<?php echo $pass; ?>">
</form>
</body>
</html>
[/code]

The Form:

[code]   <form action="cplogin.php" method="post">
  <input name="domain" type="hidden" value="utilityservers.net">
  <input type="hidden" name="logintype" value="cpanel">

            <table width="171" border="0" cellspacing="1" cellpadding="1">

              <tr>

                <td width="171" height="20" class="sideboxheader"><div align="center">Client  Login </div></td>

              </tr>

              <tr>

                <td class="logintablefor"><table width="100%" border="0" cellspacing="0" cellpadding="0">

                    <tr>

                      <td width="34%">Username:</td>

                      <td width="66%"><input name="user" type="text" size="15" /></td>

                    </tr>

                </table></td>

              </tr>

              <tr>

                <td class="logintablefor"><table width="100%" border="0" cellspacing="0" cellpadding="0">

                    <tr>

                      <td width="34%">Password:</td>

                      <td width="66%"><input name="pass" type="password" size="15" /></td>

                    </tr>

                </table></td>

              </tr>

              <tr>

                <td><div align="center">

                  <label>

                  <input type="image" src="imgs/loginbutton.gif" />

                  </label>

                  <img src="imgs/spacer.gif" width="3" height="8" />

                    <label></label>

                    <a href="javascript:hideshowCommon(document.getElementById('forgotpassword'),'toggle0')"><img src="imgs/forgottenpass.gif" width="98" height="20" border="0" /></a></div></td>

              </tr>

            </table>

          </form>[/code]
I bet you are using MSIE as your browser. MSIE adds the x and y coordinate to the submitted name.

Put this line at the start of your script to see what is being sent to your script:
[code]<?php
echo '<pre>' . print_r($_POST,true) . '</pre>';
?>[/code]

Be sure you test the script with Firefox also, since, I believe it returns a different value.

Ken
I have tested in both ie7 and firefox, not working with either but heres the script with that code added

IE7

[code]
Array
(
    [domain] => utilityservers.net
    [logintype] => cpanel
    [user] => utility
    [pass] => *******
    [x] => 22
    [y] => 16
)
[/code]

Firefox: Same as above just different x,y

[code]
    [x] => 30
    [y] => 17
[/code]
your problem seems to be this statement:
[code]if(!$_POST['login']) {
  exit;
  }[/code]
--you don't seem to have a form name by that name.
--since ted_chou12  suggestion of naming your image tag that name still didn't work, I'd do a test for a different varaible in that statement, like  $_POST['pass'].  Alternately you could just create a hidden field with that value:
[code]<input type="hidden" name="login" value="true">[/code]
naming the login image shows the new xy variables, login_x and login_y, any suggestions on what i can do with them

Array
(
    [domain] => utilityservers.net
    [logintype] => cpanel
    [user] => utility
    [pass] => *********
    [login_x] => 10
    [login_y] => 14
)

login_x and login_y represent the x and y co-ordinates referenced to the upper-left corner of the image clicked.  If either of them is non-zero it means your login image was clicked ...

if ($_POST['login_x']!="") { ... etc

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.