HTML forms + PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
danturn
Forum Newbie
Posts: 17
Joined: Wed Sep 02, 2009 10:23 am

HTML forms + PHP

Post by danturn »

Hey guys,

I'm using an HTML form to trigger PHP functions..

I'm having some issues using images for the buttons in IE although it works perfectly in chrome...

here's a bit of the code:

Code: Select all

      <td><input type= 'image' name= 'keypad' value='1' IMG SRC='images/1UP.png' BORDER=0></td>
      <td><input type= 'image' name= 'keypad' value='2' IMG SRC='images/2UP.png' BORDER=0></td>
      <td><input type= 'image' name= 'keypad' value='3' IMG SRC='images/3UP.png' BORDER=0></td>
    
if (isset($_POST['keypad']))
    {
    $keypad=$_POST['keypad'];
    $xml = "XML= <CiscoIPPhoneExecute><ExecuteItem Priority='0' URL='Key:KeyPad".$keypad."'/></CiscoIPPhoneExecute>";
    $posttxt = "/CGI/Execute";
    sendXML($xml,$posttxt);
    }
 
Basically in Chrome this works fine... if i press the 1 button it sends 1 to the $keypad variable 2 sends 2 etc.... but IE doesnt do anything on click.

Any suggestions?

Dan
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Re: HTML forms + PHP

Post by dude81 »

you need to get rid of IMG, there would be only src="somefolder/image.jpg"

This is incorrect

Code: Select all

 
<input type= 'image'  name= 'keypad' value='1'  IMG SRC='images/1UP.png' BORDER=0>
 
correct

Code: Select all

 
<input type= 'image'  name= 'keypad' value='1'  SRC='images/1UP.png' BORDER=0>
 
danturn
Forum Newbie
Posts: 17
Joined: Wed Sep 02, 2009 10:23 am

Re: HTML forms + PHP

Post by danturn »

hey dude,

thanks for that! it's still giving me issues though...

i now have:

Code: Select all

     
 <td><input type= 'image' name= 'keypad' value='1' SRC='images/1UP.png' BORDER=0></td>
      <td><input type= 'image' name= 'keypad' value='2' SRC='images/2UP.png' BORDER=0></td>
      <td><input type= 'image' name= 'keypad' value='3' SRC='images/3UP.png' BORDER=0></td>
    if (isset($_POST['keypad']))
    {
    
    $keypad=$_POST['keypad'];
    echo $keypad;
    $xml = "XML= <CiscoIPPhoneExecute><ExecuteItem Priority='0' URL='Key:KeyPad".$keypad."'/></CiscoIPPhoneExecute>";
    $posttxt = "/CGI/Execute";
    sendXML($xml,$posttxt);
    }
 
 
Still works fine in Chrome, not in IE>..

i added the echo $keypad to check if whether the button click is working and it aint :*(

the buttons i have that are currently without images work fine though...

Code: Select all

<td><input type= 'submit' name= 'dialclick' value='Dial'></td>
any ideas?
danturn
Forum Newbie
Posts: 17
Joined: Wed Sep 02, 2009 10:23 am

Re: HTML forms + PHP

Post by danturn »

I dont suppose anyone has any further suggestions for this do they?

I still cant get my image buttons to work in IE :*(
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Re: HTML forms + PHP

Post by dude81 »

Can you paste your code completely. Also let me know what is the IE version you are using?
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Re: HTML forms + PHP

Post by Sindarin »

I'd use input type='button' by the way. Then you can easily style the button using CSS and background/width/height properties. I generally avoid use of input type='image'
danturn
Forum Newbie
Posts: 17
Joined: Wed Sep 02, 2009 10:23 am

Re: HTML forms + PHP

Post by danturn »

Hey dude,

Here's the code.. Just as a proviso - i'm sure i'm doing some very obvious basic things wrong. im new to php and have struggled with it.. as someone who has written in other programming languages I'm not very happy with my structure!!!!

I.E version is 7.0.5730.13

Sindarin... can i use an image if i have the type as button rather than submit? i know i can change size etc. but i didnt think i could use an image?

code is as follows:

Code: Select all

<html><head><title>PhoneRemote</title>
<style type='text/css'>
div#Loginfields {position: absolute; left: 0px; top: 0px; width: 100%; height: 450; background: gray;  padding: 5px;}
div#Info {position: absolute; left: 0px; top: 100px; padding: 5px}
div#LineKeys {position: absolute; left: 477px; top: 27px; height 234px; width: 19px; z-index:1; padding: 0px;}
div#Softkeys {position: absolute; left: 175px; top: 218px; height: 20px; width: 320px; z-index:1; padding: 0px;}
div#Refresh {position: absolute; left: 505px; top: 225px; height: 234px; width: 320px;}
div#Keypad {position: absolute; left: 170px; top: 250px; background: gray; height:150; width:145; padding: 5px;}
div#FunctionkeysL {position: absolute; left: 330px; top: 250px; background: gray; height:50; width:145; padding: 5px;}
div#FunctionkeysR {position: absolute; left: 410px; top: 250px; background: gray; height:50; width:145; padding: 5px;}
div#Volume {position: absolute; left: 350px; top: 328px; background: gray; height:50; width:145;}
div#Soundkeys {position: absolute; left: 359px; top: 355px; background: gray; height:50; width:200; padding: 5px;}
div#Dialkey {position: absolute; left: 330px; top: 395px; background: gray; height:50; width:200; padding: 5px;}
</style>
</head>
 
<?php
$publisher="10.0.200.10";
$username="root";
$password="xerxes22";
$database="phonedb";
            
 
mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
 
// if text boxes are blank display instructions
if (!isset($ip))
    {
    $ip="Enter IP";
    }
if (!isset($userid))
    {
    $userid="Enter User ID";
    }
if (!isset($pin))
    {
    $pin="Enter PIN";
    }
if (!isset($dial))
    {
    $dial="Enter number to dial";
    }
 
    // keeps values in the text boxes on submit click
if (isset($_POST['IP']) && isset($_POST['USERID']) && isset($_POST['PIN'])&& isset($_POST['DIAL']) && isset($_POST['MAC']) && isset($_POST['SWITCH']) && isset($_POST['PORT'])) 
    {
    $ip = $_POST['IP'];
    $userid = $_POST['USERID'];
    $pin = $_POST['PIN'];   
    $dial = $_POST['DIAL'];
    $macadd = $_POST['MAC'];
    $switchip = $_POST['SWITCH'];
    $portno = $_POST['PORT'];
    $status = $_POST['STATUS'];
    }   
 
    //if dblookup is clicked
    if (isset($_POST['dblookup']))
    {   
        $query = "SELECT * FROM phones WHERE USERID = '$userid'";
        $result = mysql_query($query);
        $thisrow=mysql_fetch_row($result);
        
        if ($thisrow)  //if the results of the query are not null
        {
            $ip=$thisrow[1];
            $userid=$thisrow[2];
            $pin=$thisrow[3];
                    $xml="";
        }
        
        else
        {
            $pin="USER NOT FOUND";
            $ip="IN DB";
        }
    }
 
    //if any keypad buttons are clicked
    if (isset($_POST['keypad']))
    //if (isset($_POST['keypad_x']))
    {
        echo "<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>";
        echo "hit it";
        $keypad=$_POST['keypad'];
        echo $keypad;
    
            // if ($keypad=="*")
            // {
                // $keypad = "Star";
            // }
            // if ($keypad=="#")
            // {
                // $keypad = "Pound";
            // }
    
        $xml = "XML= <CiscoIPPhoneExecute><ExecuteItem Priority='0' URL='Key:KeyPad".$keypad."'/></CiscoIPPhoneExecute>";
        EXECUTE($xml);
            DEVICEINFO($xml);
    }
    
    // if any other key buttons are clicked
    if (isset($_POST['key']))
    {
        $key=$_POST['key'];
        $xml = "XML= <CiscoIPPhoneExecute><ExecuteItem Priority='0' URL='Key:".$key."'/></CiscoIPPhoneExecute>";
        EXECUTE($xml);
            DEVICEINFO($xml);
    }
    
    // if dial button is clicked
    if (isset($_POST['dialclick']))
    {
        $xml = "XML= <CiscoIPPhoneExecute><ExecuteItem Priority='0' URL='Dial:".$dial."'/></CiscoIPPhoneExecute>";
        EXECUTE($xml);
            DEVICEINFO($xml);
    }
    
    // if form is submitted by Connect
    if (isset($_POST['auth']))
    {
        $xml = "";
        EXECUTE($xml);
        PORT($xml);
        DEVICEINFO($xml);
    }
    
        if (isset($_POST['refresh']))
    {
        $xml = "";
        EXECUTE($xml);
        PORT($xml);
        DEVICEINFO($xml);
    }
    
    
    if (isset($_POST['login']))
    {
        $xml = "";
        LOGIN($xml);
        //DEVICEINFO($xml);
    }
        
        if (isset($_POST['logout']))
    {
        $xml = "";
        LOGOUT($xml);
        //DEVICEINFO($xml);
    }   
    // function to send XML to phone
    function EXECUTE($xml)
    {
        $ip = $_POST['IP'];
        $userid = $_POST['USERID'];
        $pin = $_POST['PIN'];
        $curl = curl_init("http://".$ip."/CGI/Execute");
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_POSTFIELDS, "XML=".urlencode($xml));
        curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($curl, CURLOPT_USERPWD, $userid.":".$pin);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($curl, CURLOPT_HEADER,1);
        $response = curl_exec($curl);
 
        global $status;
                if (strpos($response, '<CiscoIPPhoneError Number="1">') !== false || strpos($response, 'Success') !== false)
                {   
                    $status="Connected";
                    $query = "SELECT * FROM phones WHERE USERID = '$userid'";
                    $result = mysql_query($query);
                    $thisrow=mysql_fetch_row($result);
                    
                    if (!$thisrow) 
                    {
                        $query = "INSERT INTO phones VALUES ('','$ip','$userid','$pin')";
                        mysql_query($query);
                    }
                }
                else 
                {           
                    $status="Authentication error";
                }
            
        
        return $response;
    }
    function PORT($xml)
    {
        $ip = $_POST['IP'];
        $userid = $_POST['USERID'];
        $pin = $_POST['PIN'];
        $curl = curl_init("http://".$ip."/CGI/Java/Serviceability?adapter=device.statistics.port.network");
        curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($curl, CURLOPT_HEADER,1);
        $response = curl_exec($curl);
        global $macadd;
        $macpos=strrpos($response,"SEP");
        
        if ($macpos>0)
        {
            $macadd=substr($response,$macpos,15);
        }
    
        
        if(preg_match('@CDP Neighbor IP Address</B></TD><td width=20></TD><TD><B>(.*?)</B>@',$response,$switch)) 
        {
                global $switchip;
                $switchip=$switch[1];
        }
                
        if(preg_match('@CDP Neighbor Port</B></TD><td width=20></TD><TD><B>(.*?)</B>@',$response,$port)) 
        {
                global $portno;
                $portno=$port[1];
        }
 
        return $response;
    }
    
    function DEVICEINFO($xml)
    {
    
        $ip = $_POST['IP'];
        $userid = $_POST['USERID'];
        $pin = $_POST['PIN'];
        $curl = curl_init("http://".$ip."/DeviceInformation");
        curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($curl, CURLOPT_HEADER,1);
        $response = curl_exec($curl);
        if(preg_match('@Message Waiting</B></TD><td width=20></TD><TD><B>(.*?)</B>@',$response,$message)) 
        {
            global $messageon;
            global $colour;
            $messageon=$message[1]; 
            if ($messageon=="Yes")
            {
                $colour="crimson";
            }
            else
            {
                $colour="black";
            }
        }
            return $response;
    }
 
    function LOGIN($xml)
    {
 
        $ip = $_POST['IP'];
        $userid = $_POST['USERID'];
        $pin = $_POST['PIN'];
        $macadd = $_POST['MAC'];
        $curl = curl_init("http://10.0.200.10/emapp/EMAppServlet?device=".$macadd."&userid=".$userid."&seq=".$pin."");
        curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($curl, CURLOPT_HEADER,1);
        $response = curl_exec($curl);
        
        if (strpos($response, 'Login Successful') !== false)
            {
             usleep(5500000);
                global $status;
                $status="Login Successful";
                $xml = "";
                EXECUTE($xml);
                PORT($xml);
                DEVICEINFO($xml);
            }
        return $response;
    }
    function LOGOUT($xml)
    {
    
        $ip = $_POST['IP'];
        $userid = $_POST['USERID'];
        $pin = $_POST['PIN'];
        $macadd = $_POST['MAC'];
        $curl = curl_init("http://10.0.200.10/emapp/EMAppServlet?device=".$macadd."&doLogout=true");
        curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($curl, CURLOPT_HEADER,1);
        $response = curl_exec($curl);
            if (strpos($response, 'Logout Successful') !== false)
            {
                global $status;
                $status="Logged Out";
            }
            return $response;
    }
// HTML Form stored in php variable
$form =
"
<body>
<form method='post' action='curl.php'> 
<div id='Loginfields'>
<input name= 'USERID' type= 'text' value= '$userid' onFocus='clearMe(this)'/><BR>
<input name= 'PIN' width='15' type= 'text' value= '$pin' onFocus='clearMe(this)'/><BR>
<input name= 'IP' type= 'text' value= '$ip' onFocus='clearMe(this)'/><BR>
<input type= 'submit' name= 'auth' value='Connect'/>
<input type= 'submit' name= 'dblookup' value='Lookup'/>
</div>
 
<div id='Info'>
<input name= 'MAC' type= 'text' value= '$macadd'/><BR>
<input name= 'SWITCH' type= 'text' value= '$switchip'/><BR>
<input name= 'PORT' type= 'text' value= '$portno'/><BR>
<input name= 'STATUS' type= 'text' value= '$status'/><BR>
<input name= 'PUBLISHER' type= 'text' value= '$publisher'/><BR>
<input type= 'submit' name= 'login' value='Login'/>
<input type= 'submit' name= 'logout' value='Logout'/>
</div>
 
<div id='LineKeys'>
<input type= 'image' name= 'key' value='Line1' SRC='images/linebutton.png'/><input type= 'image' name= 'key' value='Line2' SRC='images/linebutton.png'/><input type= 'image' name= 'key' value='Line3' SRC='images/linebutton.png'/><input type= 'image' name= 'key' value='Line4' SRC='images/linebutton.png'/><input type= 'image' name= 'key' value='Line5' SRC='images/linebutton.png'/><input type= 'image' name= 'key' value='Line6' SRC='images/linebutton.png'/><input type= 'image' name= 'key' value='Line7' SRC='images/linebutton.png'/><input type= 'image' name= 'key' value='Line8' SRC='images/linebutton.png'/>
</div>
 
<div style='position: absolute; left: 170px; top: 0px; height: 234px; width: 320px; background: black; border-color: $colour; border-style:solid; border-width:5px;'>
<img src='screenshot.php?userid=$userid&pin=$pin&ip=$ip' width='320' height='234'/>
</div>
 
<div id='Refresh'>
<input type= 'image' name= 'refresh' value='refresh' SRC='images/RefreshUP.png'/>
</div>
 
<div id='Softkeys'>
<input type= 'image' name= 'key' value='Soft1' SRC='images/70Softkey.png'/><input type= 'image' name= 'key' value='Soft2' SRC='images/70Softkey.png'/><input type= 'image' name= 'key' value='Soft3' SRC='images/70Softkey.png'/><input type= 'image' name= 'key' value='Soft4' SRC='images/70Softkey.png'/><input type= 'image' name= 'key' value='Soft5' SRC='images/70Softkey.png'/>
</div>
 
<div id='Keypad'>
 
    <input type= 'image' name= 'keypad' value='1' SRC='images/1UP.png'/>
    <input type= 'image' name= 'keypad' value='2' SRC='images/2UP.png'/>
    <input type= 'image' name= 'keypad' value='3' SRC='images/3UP.png'/>
    <input type= 'image' name= 'keypad' value='4' SRC='images/4UP.png'/>
    <input type= 'image' name= 'keypad' value='5' SRC='images/5UP.png'/>
    <input type= 'image' name= 'keypad' value='6' SRC='images/6UP.png'/>
    <input type= 'image' name= 'keypad' value='7' SRC='images/7UP.png'/>
    <input type= 'image' name= 'keypad' value='8' SRC='images/8UP.png'/>      
    <input type= 'image' name= 'keypad' value='9' SRC='images/9UP.png'/>
    <input type= 'image' name= 'keypad' value='Star' SRC='images/STARUP.png'/>
    <input type= 'image' name= 'keypad' value='0' SRC='images/0UP.png'/>
    <input type= 'image' name= 'keypad' value='Pound' SRC='images/HASHUP.png'/>
</div>
 
<div id='FunctionkeysL'>
        <input type= 'image' name= 'key' value='Messages' SRC='images/MessagesUP.png'/>
        <input type= 'image' name= 'key' value='Services' SRC='images/ServicesUP.png'/>
</div>
 
<div id='FunctionkeysR'>
        <input type= 'image' name= 'key' value='Directories' SRC='images/DirectoriesUP.png'/>
        <input type= 'image' name= 'key' value='Settings' SRC='images/SettingsUP.png'/>
</div>
 
<div id='Volume'>
        <input type= 'image' name= 'key' value='VolDwn' SRC='images/volumerampUPLEFT.png'/><input type= 'image' name= 'key' value='VolUp' SRC='images/volumerampUPRIGHT.png'/>
</div>
                
<div id='Soundkeys'>
    <input type= 'image' name= 'key' value='Headset' SRC='images/HeadsetUP.png'/>
    <input type= 'image' name= 'key' value='Mute' SRC='images/MICUP.png'/>
    <input type= 'image' name= 'key' value='Speaker' SRC='images/SpeakerUP.png'/>
</div>      
 
<div id='Dialkey'>
<input name= 'DIAL' type= 'text' value= '$dial' onfocus='clearMe(this)'/><input type= 'submit' name= 'dialclick' value='Dial'/>
</div>
</form>
 
</body>
";
 
echo $form;
 
 ?>
 
 <script type="text/javascript">
 function clearMe(formfield){
  if (formfield.defaultValue==formfield.value)
   formfield.value = ""
 }
</script>
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Re: HTML forms + PHP

Post by dude81 »

try using heredoc string declaration for form. Definitely there must be quotes problem with the form
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Re: HTML forms + PHP

Post by Sindarin »

Yes, the button element needs javascript to work, the submit element submits the form without javascript. Both of them can be fully styled including image, color, size etc.

button element syntax:

Code: Select all

<input name="mybutton" style="mybuttonstyle" id="mybutton" type="button" value="My Button" onclick="javascript&#058;document.myform.submit();" />
submit element syntax:

Code: Select all

<input name="mysubmit" style="mybuttonstyle" id="mysubmit" type="submit" value="My Submit" onclick="javascript&#058;document.myform.submit();" />
where "myform" is the name of your form, and replace &#058; with :

and try the above buttons with this css:

Code: Select all

 
z-index:1;
 
width:100px;
min-width:100px;
height:26px;
min-height:26px;
 
font-family: Georgia, Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
font-weight: bold;
color:#888CCC;
text-transform: none; /*could be capitalize, lowercase, uppercase or none */
 
letter-spacing:0px;
word-spacing:2px;
 
border-color:#0066FF;
border-style:solid;
border-width:1px;
 
margin-left:2px;
margin-right:2px;
margin-top:6px;
margin-bottom:0px;
 
padding-left:0px;
padding-right:0px;
padding-top:0px;
padding-bottom:0px;
 
background-color:#FFFFFF;
cursor:pointer;
 
of course you can also put a javascript client-side verification before sending the form instead of document.myform.submit();
Post Reply