Jump to content

Recommended Posts

Hello, I have a problem with my login form, when i press the submit button, it returns a valitation error that I made.

 

The error message is triggered when the submit button isn't pressed, but the form still tries to submit.

 

session_start();

include "sources/php/class.php";

$e = $_POST['loginname'];
$p = $_POST['loginpass'];
$s = $_POST['submit'];

if(!isset($s)) {
    header('location: '.$_SESSION['psite'].'.php?p=error&ploca=login&pid=0');
    exit();
}

 

Heres a piece of my code, first i define the variables, then check if the button was pressed, but something is wrong there? - But what?

 

Hope you can help me.

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/253322-problems-with-submitting-a-form/
Share on other sites

Try

 

if(isset($_POST['submit']))
{
   echo 'here';
}

 

if you see "here" on your page, you know you are inside the condition and you can then continue to code inside.  You should then set your vars and anything else you need.  Always make sure the condition works before you start anything else.

I do not see the 'here' anywhere, thats the weird thing?

 

My form

<form action="login_attempt.php" id="login-form">
                        <fieldset>
                            <div class="field">
                                <label>Email-addresse<br /></label>
                                <input type="text" class="text" value="" name="loginname"/><br />
                                <label>Adgangskode</label>
                                <input type="password" class="text" value="" name="loginpass"/><br />
                                <input type='hidden' name='submit2' />
                                <input type="submit" value="" class="submit" name="submit"/>
                            </div>
                        </fieldset>
                    </form>

OR you could dumb it down still further just to test it and do

 


if(empty($_POST['loginname']) && empty($_POST['loginpass'])) {

echo "Display form";
}


else{

echo "process form data";
}

 

I suggest this because sometimes white space can mean a var isset even when it's not

I made some changes to the code snippet, and debugged it.

This is the code.

include "sources/php/class.php";

$e  = $_POST['loginname'];
$p  = $_POST['loginpass'];
$s  = $_POST['submit'];

if(empty($e) && empty($p)) {

echo "Display form";
exit();
}


else{

echo "process form data";
exit();
}

if(!$s) {
    header('location: '.$_SESSION['psite'].'.php?p=error&ploca=login&pid=0');
    $_SESSION['debug'] = 1;
    exit();
}

 

And this is the result

Undefined loginname
undefined loginpass
undefined submit

Even if I add

method="POST"

in the form, it doesn't work.

 

This is my form

<form action="login_attempt.php" id="login-form" method="POST">
                        <fieldset>
                            <div class="field">
                                <label>Email-addresse<br /></label>
                                <input type="text" class="text" value="" name="loginname"/><br />
                                <label>Adgangskode</label>
                                <input type="password" class="text" value="" name="loginpass"/><br />
                                <input type="submit" value="" class="submit" name="loginsubmit"/><a href="register.php"><img style="margin-top:5px;margin-left:5px;" src="images/opret-bruger.gif" width="70" height="16" alt="opret-bruger"/></a>
                            </div>
                        </fieldset>
                    </form>

 

And heres all my login_attempt.php

session_start();

$e = $_POST['loginname'];
$p = $_POST['loginpass'];
$s = $_POST['submit'];

if(!$s) {
    header('location: login.php?p=error&ploca=login&pid=0'); // This is what it returns all the time.
    exit();
}
if(empty($e) || empty($p)) {
    header('location: login.php?p=error&ploca=login&pid=1');
    exit();
}
if(!validate::email($e)) {
    header('location: login.php?p=error&ploca=login&pid=2');
    exit();
}
if(mysql::is_registered($e)) {
    mysql::login($e, $p);
}

 

I can't see whats wrong?

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.