Hi all,
I want to alter my php file so when the user clicks the button, it calls my php function. Here is the code.
<?
echo 'Username <input type="text" name="username" size="14" maxlength="14"><BR>';
echo 'Password <input type="password" name="password" size="14" maxlength="14">';
echo '<input type="submit" value="Submit">'; <--Here is the button
function checkPass(){ <--How do I call this function?
if($username=="forge" && $password=="order2002") {
include ("selectDocket.php");
}
else {
echo "You have not entered a valid username/password. Remember, they are case sensitive.";
}
}
?> [b][/b]
Call PHP function on click of HTML button?
Moderator: General Moderators
-
slipstream
- Forum Commoner
- Posts: 86
- Joined: Fri Apr 19, 2002 8:53 am
- Location: Canada
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You have to do a check to see if the form has been submitted. If you added a hidden field to your form:
Then you can test for that variable when the page is submitted and run your function:
you'll need to amend the function to something like that below in order to be able to test those posted variables:
Mac
P.S. Please remember to put your PHP code into tags.
Code: Select all
<input type="hidden" name="action" value="post" />Code: Select all
if (isset($_POSTї'action'] && $_POSTї'action'] == 'post') {
checkPass();
} else {
// show login form
}Code: Select all
function checkPass() {
$username = (!empty($_POST['username'])) ? $_POST['username'] : '';
$password = (!empty($_POST['password'])) ? $_POST['password'] : '';
if ($username == 'forge' && $password == 'order2002') {
include 'selectDocket.php';
} else {
echo '<p>You have not entered a valid username/password Remember, they are case sensitive.</p>';
}
}P.S. Please remember to put your PHP code into
Code: Select all
PHP is all server side. As a result, it is not possible to have a button on the clients machine call a function on the server without generating a new page. Perhaps if you had a page "authenticate.php" that you send your form data to. It can just does what checkPass() does, but redirect either back to the login if it fails, or onto another page which is basically selectDocket.php.