By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,646 Members | 1,175 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,646 IT Pros & Developers. It's quick & easy.

submit form without a "submit" button

P: n/a
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.php'); // 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($_POST['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($_POST['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=PASSWORD('$p')";
$result = @mysql_query ($query);
$row = mysql_fetch_array ($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($_SERVER['PHP_SELF']) . "/view_profile.php");
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">Please 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"><input type="submit" name="submit" value="Login"
/></div>

</div>
</form><!-- End of Form -->
<?php // Include the HTML footer.
include ('includes/footer.html');
?>
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
lsarg wrote:
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.


It's Javascript you're wanting not PHP.

<a href="javascript:document.formname.submit()">Link</a>

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

Chris

--
Chris Hope
The Electric Toolbox Ltd
http://www.electrictoolbox.com/
Jul 17 '05 #2

P: n/a
"Chris Hope" <bl*******@electrictoolbox.com> schrieb im Newsbeitrag
news:40********@news.athenanews.com...
lsarg wrote:
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.


It's Javascript you're wanting not PHP.

<a href="javascript:document.formname.submit()">Link</a>

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


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
Jul 17 '05 #3

P: n/a
I noticed that Message-ID: <40***********************@news.easynet.ch>
from Markus Ernst contained the following:
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.


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/
Jul 17 '05 #4

P: n/a
Markus Ernst wrote:
"Chris Hope" <bl*******@electrictoolbox.com> schrieb im Newsbeitrag
news:40********@news.athenanews.com...
lsarg wrote:
> 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.


It's Javascript you're wanting not PHP.

<a href="javascript:document.formname.submit()">Link</a>

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


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.


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
http://www.electrictoolbox.com/
Jul 17 '05 #5

P: n/a
> 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.


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.
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.