submit form without a "submit" button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lsarg

    submit form without a "submit" button

    i've been trying forever to figure out a way to use a regular text
    link in place of a submit button at the bottom of this. can't get it.
    i'm just starting to learn php, so i'm stuck. any help at all would be
    amazing.


    <?php # Script 12.7 - login.php
    // This is the login page for the site.

    // Include the configuration file for error management and such.
    require_once ('includes/config.inc');

    // Set the page title and include the HTML header.
    $page_title = 'Login';
    include ('includes/header.html');

    if (isset($_POST['submit'])) { // Check if the form has been
    submitted.

    require_once ('../../mysql_connect.p hp'); // Connect to the database.

    if (empty($_POST['username'])) { // Validate the username.
    $u = FALSE;
    echo '<p><font color="red" size="+1">You forgot to enter your
    username!</font></p>';
    } else {
    $u = escape_data($_P OST['username']);
    }

    if (empty($_POST['password'])) { // Validate the password.
    $p = FALSE;
    echo '<p><font color="red" size="+1">You forgot to enter your
    password!</font></p>';
    } else {
    $p = escape_data($_P OST['password']);
    }

    if ($u && $p) { // If everything's OK.

    // Query the database.
    $query = "SELECT user_id, first_name, last_name, username FROM users
    WHERE username='$u' AND password=PASSWO RD('$p')";
    $result = @mysql_query ($query);
    $row = mysql_fetch_arr ay ($result, MYSQL_NUM);

    if ($row) { // A match was made.

    // Start the session, register the values & redirect.

    $_SESSION['username'] = $row[3];
    $_SESSION['first_name'] = $row[1];

    $_SESSION['user_id'] = $row[0];



    ob_end_clean(); // Delete the buffer.

    header ("Location: http://" . $_SERVER['HTTP_HOST'] .
    dirname($_SERVE R['PHP_SELF']) . "/view_profile.ph p");
    exit();

    } else { // No match was made.
    echo '<p><font color="red" size="+1">The username and password
    entered do not match those on file.</font></p>';
    }

    mysql_close(); // Close the database connection.

    } else { // If everything wasn't OK.
    echo '<p><font color="red" size="+1">Pleas e try again.</font></p>';
    }

    } // End of SUBMIT conditional.
    ?>
    <div id="Content">
    <h1>Login</h1>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" name="myForm"
    method="post">

    <p><b>User Name:</b><br> <input type="text" name="username" size="10"
    maxlength="20" value="<?php if (isset($_POST['username'])) echo
    $_POST['username']; ?>" /></p>
    <p><b>Password: </b><br> <input type="password" name="password"
    size="20" maxlength="20" /></p>
    <div align="left"><i nput type="submit" name="submit" value="Login"
    /></div>



    </div>
    </form><!-- End of Form -->


    <?php // Include the HTML footer.
    include ('includes/footer.html');
    ?>
  • Chris Hope

    #2
    Re: submit form without a &quot;submit&qu ot; button

    lsarg wrote:
    [color=blue]
    > i've been trying forever to figure out a way to use a regular text
    > link in place of a submit button at the bottom of this. can't get it.
    > i'm just starting to learn php, so i'm stuck. any help at all would be
    > amazing.[/color]

    It's Javascript you're wanting not PHP.

    <a href="javascrip t:document.form name.submit()"> Link</a>

    where "formname" is the name of your form eg <form name="formname" >

    Chris

    --
    Chris Hope
    The Electric Toolbox Ltd

    Comment

    • Markus Ernst

      #3
      Re: submit form without a &quot;submit&qu ot; button

      "Chris Hope" <blackhole@elec trictoolbox.com > schrieb im Newsbeitrag
      news:40860961_2 @news.athenanew s.com...[color=blue]
      > lsarg wrote:
      >[color=green]
      > > i've been trying forever to figure out a way to use a regular text
      > > link in place of a submit button at the bottom of this. can't get it.
      > > i'm just starting to learn php, so i'm stuck. any help at all would be
      > > amazing.[/color]
      >
      > It's Javascript you're wanting not PHP.
      >
      > <a href="javascrip t:document.form name.submit()"> Link</a>
      >
      > where "formname" is the name of your form eg <form name="formname" >
      >[/color]

      But as Javascript might be turned off it is in most cases a good idea to
      leave the submit button there though it does not look nice.

      --
      Markus


      Comment

      • Geoff Berrow

        #4
        Re: submit form without a &quot;submit&qu ot; button

        I noticed that Message-ID: <40863b4f$0$247 03$afc38c87@new s.easynet.ch>
        from Markus Ernst contained the following:
        [color=blue]
        >But as Javascript might be turned off it is in most cases a good idea to
        >leave the submit button there though it does not look nice.[/color]

        You can use an image. Even an image of some text.

        --
        Geoff Berrow (put thecat out to email)
        It's only Usenet, no one dies.
        My opinions, not the committee's, mine.
        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

        Comment

        • Chris Hope

          #5
          Re: submit form without a &quot;submit&qu ot; button

          Markus Ernst wrote:
          [color=blue]
          > "Chris Hope" <blackhole@elec trictoolbox.com > schrieb im Newsbeitrag
          > news:40860961_2 @news.athenanew s.com...[color=green]
          >> lsarg wrote:
          >>[color=darkred]
          >> > i've been trying forever to figure out a way to use a regular text
          >> > link in place of a submit button at the bottom of this. can't get it.
          >> > i'm just starting to learn php, so i'm stuck. any help at all would be
          >> > amazing.[/color]
          >>
          >> It's Javascript you're wanting not PHP.
          >>
          >> <a href="javascrip t:document.form name.submit()"> Link</a>
          >>
          >> where "formname" is the name of your form eg <form name="formname" >
          >>[/color]
          >
          > But as Javascript might be turned off it is in most cases a good idea to
          > leave the submit button there though it does not look nice.[/color]

          I completely agree with that and should have mentioned it. You can also use
          images as the submit or use styles to change the appearance.

          Chris

          --
          Chris Hope
          The Electric Toolbox Ltd

          Comment

          • Kevin Thorpe

            #6
            Re: submit form without a &quot;submit&qu ot; button

            > But as Javascript might be turned off it is in most cases a good idea to[color=blue]
            > leave the submit button there though it does not look nice.[/color]

            Idea: leave the submit button and use javascript in the body onload
            event to set style display to none. That way the button is only visible
            if javascript is off.

            Comment

            Working...