Jump to content

Basic Form Question. <button> vs. <input>


bpburrow

Recommended Posts

Need help figuring out why my button tag isn't working.  If I use the standard input tag, <input type="submit" name="submit" value="Sign in" />, I have no issues.  However, I want to use  <button type="submit" name="submit" class="primary_lg right">Sign in</button> to dress it up a bit.  Problem is, even though variables are being passed, it doesn't pull up my main admin page.

 

In short, I want this which doesn't work:

<button type="submit" name="submit" class="primary_lg right">Sign in</button>

instead of this which does work:

<input type="submit" name="submit" value="Sign in" />

 

Both pass variables, however the <button> doesn't load the follow-on page (mainadmin.php).

 

Here's my script:

<?php if(!$_POST['submit']){ // 'submit' hasn't been clicked so output html.?>
          <form action="admin_login2.php" method="post">
            <fieldset>
		  <div style="float:right;"><a href="/SSP/ssp_director/index.php?/users/password" title="Click here to retrieve login" class="mute">Lost username?</a></div>
              <label for="username">Username:</label>
                    <input id="username" type="text" name="username" class="wide" value="" />
            </fieldset>
		<fieldset>
              <label for="password">Password:</label>
              <input type="password" name="password" class="wide" value="" />
            </fieldset>
		<fieldset>
		  <button type="submit" name="submit" class="primary_lg right">Sign in</button>
              <input type="submit" name="submit" value="Sign in" />
            </fieldset>
          </form>
          <?php
          }else{
            $user= protect($_POST['username']);
            $pass= protect($_POST['password']);

            if($user && $pass){
              $pass = md5($pass); //compare the encrypted password
              $sql="SELECT id,username FROM Admin WHERE username='$user' AND password='$pass'";
              $query=mysql_query($sql) or die(mysql_error());

            if(mysql_num_rows($query) > 0){
              $row = mysql_fetch_assoc($query); // mysql_fetch_assoc gets the value for each field in the row
              $_SESSION['id'] = $row['id']; //creates the first session var
              $_SESSION['username'] = $row['username']; // second session var
              echo "<script type=\"text/javascript\">window.location=\"mainadmin.php\"</script>";	
            }else{
              //I added $user, $pass to see the forms output.  Output was same as db.
              echo "<script type=\"text/javascript\">
                alert(\"Username and password combination is incorrect!\");
                window.location=\"admin_login2.php\"</script>";   
            }	
            }else{			
               //this script works fine when I leave a field empty
               echo "<script type=\"text/javascript\">
               alert(\"You need to gimme a username AND password!\");
               window.location=\"admin_login2.php\"</script>";
            }
          }
          ?>

Link to comment
https://forums.phpfreaks.com/topic/188968-basic-form-question-vs/
Share on other sites

If anyone's interested I had to add a value to the button tag.  Don't know why, didn't think it was necessary considering the format I was using.

 

Here's my new button:

<button class="primary_lg right" title="Sign in" type="submit" name="submit" value="Sign in">Sign in</button>

 

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.