Jump to content

Archived

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

wolfas

form that doesn't work in some ways...

Recommended Posts

Hello, i have a problem in this script.
the problem is that this form works then i use submit instead of image and with image this form doesn't work  :-[
<?php
echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\">";
if ($_POST['submit'])
{
  echo $user.' '.$pass;
}
else
{
echo "<p><input type=\"text\" name=\"user\" size=5 maxlength=12 value=\"name\"></p>";
echo "<p><input type=\"password\" name=\"pass\" size=7 maxlength=12 value=\"password\"></p>";
echo "<p><input type=\"image\" src=\"image.jpg\" height=\"16\" width=\"24\" border=\"0\" ALT=\"hello\" name=\"submit\"></p>";
echo "</form>";}
?>

Share this post


Link to post
Share on other sites
[code]
<?php
if($_POST['_submit_check']){
  echo $_POST['user'].' '.$_POST['pass'];
}else{
echo "<form action='". $_SERVER['PHP_SELF'] ."' method='POST'>
  <p><input type='text' name='user' size='5' maxlength='12' value='name'></p>
  <p><input type='password' name='pass' size='7' maxlength='12' value='password'></p>
  <p><input type='image' src='image.jpg' height='16' width='24' border='0' ALT='hello' name='submit'></p>
  <input type='hidden' name='_submit_check' value='1'/>
  </form>";
}
?>
[/code]

Share this post


Link to post
Share on other sites
The problem occurs because when an image is used for a submit button, the x & y positions in that image are returned to your script. To see what is being returned, put this statement at the start of your script:
[code]<?php
if (isset($_POST))
  echo '<pre>' . print_r($_POST,true) . '</pre>';
?>[/code]

Ken

Share this post


Link to post
Share on other sites
If you still wan't to use an image as a button then change this line:[code]echo "<p><input type=\"image\" src=\"image.jpg\" height=\"16\" width=\"24\" border=\"0\" ALT=\"hello\" name=\"submit\"></p>";[/code] to this line:[code]echo "<p><button type='submit' style='border: 0px; padding: 0px;' name='submit' alt='hello'><img src='image.jpg' height='16' width='24' border='0'></button></p>";[/code]

Share this post


Link to post
Share on other sites

×

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.