Jump to content

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


wolfas

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>";}
?>
Link to comment
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]
Link to comment
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
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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