Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-25-2013, 10:37 PM   PM User | #1
gkjr1
New Coder

 
Join Date: Jan 2013
Location: Texas, USA
Posts: 35
Thanks: 5
Thanked 0 Times in 0 Posts
gkjr1 is an unknown quantity at this point
form not sending

I have a form in html that is sending to my php to login. The form, when hitting submit, does nothing. If you hover over the button it shows the correct path that it should be posting to. It asks to save the password just like any other typical form as well, so I'm not sure why it's not going through. I do have a html5 form shim on, but it doesn't submit in FF/Chrome either (https://github.com/dsheiko/HTML5-Form-Shim). This is the HTML for the form (sorry if should have posted in html instead):

PHP Code:
<form method="post"  action="classes/class.registration.php" id="register_form" class="register_form" data-custom-validation="true">
                <
fieldset id="logininfo">
                    <
label for="email">Email: </label>
                    <
input name="email" id="email" type="email" placeholder="enter email" required="required" />
....
</
form
and this is what its sending to (yes its not a real class)
PHP Code:
<?php
//require necessary files
require('../config/dbconfig.php');
include(
'class.mysqli.php');
$checkValid false;

if (isset(
$_POST['submit']))
{
    
//check for blank fields
    
if ($_POST['email'] == '' || $_POST['email'] == null ||
        
$_POST['pass2'] == '' || $_POST['pass2'] == null ||
        
$_POST['regcode'] == '' || $_POST['regcode'] == null ||
        
$_POST['firstname'] == '' || $_POST['firstname'] == null ||
        
$_POST['lastname'] == '' || $_POST['lastname'] == null ||
        
$_POST['country'] == '' || $_POST['country'] == null ||
        
$_POST['street'] == '' || $_POST['street'] == null ||
        
$_POST['city'] == '' || $_POST['city'] == null ||
        
$_POST['state'] == '' || $_POST['state'] == null ||
        
$_POST['zip'] == '' || $_POST['zip'] == null ||
        
$_POST['lang'] == '' || $_POST['lang'] == null ||
        
$_POST['tzone'] == '' || $_POST['tzone'] == null ||
        
$_POST['bday'] == '' || $_POST['bday'] == null)
    {
        
header('location:register.php?error=blank');
        exit;
    }

    
//hash the password
    
$hash hash('sha256'$_POST['pass1']);

    
//create salt for password
    
$salt createSalt();

    
//add salt to pass
    
$hash hash('sha256'$salt $hash);

    
//connect to the database
    
$db = new db("mysql:host=$db_host;dbname=$db_name"$db_user$db_pass);

    
//double check username availability before entering in db//if disabled javascript or error
    //set up bind variables
    
$bind = array(
        
":uemail" => "$_POST['email']"
    
);

    
//query database
    
$results $db->select('users','email=:uemail',$bind,'email','','');

    
//check results for email
    
if (count($results) > 0) {
        foreach(
$results as $row)
        {
            if (
$row['regcode'] == null)
            {
                
header('location:register.php?error=email');
                exit;
            }
            if (
$row['regcode'] == $_POST['regcode'])
            {
                
$checkValid true;
            }
        }
    }

    
//set up array to insert
    
$insVal = array(
        
"email" => $_POST['email'],
        
"password" => $hash,
        
"salt" => $salt,
        
"firstname" => $_POST['firstname'],
        
"lastname" => $_POST['lastname'],
        
"country" => $_POST['country'],
        
"street" => $_POST['street'],
        
"city" => $_POST['city'],
        
"state" => $_POST['state'],
        
"zip" => $_POST['zip'],
        
"joined" => date("Y-m-d H:i:s"),
        
"lastlogin" => date("Y-m-d H:i:s"),
        
"active" => 1,
        
"staff" => 0,
        
"department" => null,
        
"position" => "user",
        
"language" => $_POST['lang'],
        
"timezone" => $_POST['tzone'],
        
"birthday" => $_POST['bday'],
        
"regcode" => null
    
);
    
//var_dump($insVal);

    //insert into database
    
if ($checkValid == true)
    {
        
$putIn $db->insert("users"$insVal);
    }else
    {
        
header('location:register.php?error=regcode');
    }

    
//var_dump($insert);
    //check results and return    
    
if ($putIn == 1)
    {
        
header('location:success_register.php');
    } else
    {
        
header('location:register.php?error=dberror');
        exit;
    }
}else
{
    
header('location:register.php?error=blank');
}

//creates a 3 character sequence, hash pass again
function createSalt()
{    
    
$string md5(uniqid(rand(), true));    
    return 
substr($string03);
}
?>
Also going to the php file itself throws a 500 server error. I took out the includes/requires at the top and tried again, and it still does the error, which I dont see why as it should just call the header back since the post is blank.
I also didn't notice it sending anything at all in firefox. If you want you can see at:
http://imengine.gofreeserve.com/fileshare/register.php

Last edited by gkjr1; 01-25-2013 at 10:47 PM..
gkjr1 is offline   Reply With Quote
Old 01-26-2013, 02:05 AM   PM User | #2
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,667
Thanks: 46
Thanked 456 Times in 444 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by gkjr1 View Post
The form, when hitting submit, does nothing.
Where do I start?

First of all, stop checking for the submit button

Quote:
Originally Posted by gkjr1 View Post
I do have a html5 form shim on, but it doesn't submit in FF/Chrome either (https://github.com/dsheiko/HTML5-Form-Shim).
From what I could make out thats a jquery plugin right? Sounds like it could be interfering with the browser but I'm no JS / JQuery expert.

Quote:
Originally Posted by gkjr1 View Post
PHP Code:
if (isset($_POST['submit']))

GET RID OF THAT!!!

Seriously, it's awful and will annoy and frustrate your IE users.

Quote:
Originally Posted by gkjr1 View Post
Also going to the php file itself throws a 500 server error.
So you need to look at your webserver / php error logs.

Quote:
Originally Posted by gkjr1 View Post
I also didn't notice it sending anything at all in firefox. If you want you can see at:
http://imengine.gofreeserve.com/fileshare/register.php
If you're going to ask people to look at it and test it you at least need to give them things like the registration code otherwise you're not going to get a lot of help if we can't test it
__________________
Please don't be rude: Put your php code in [php][/php] tags. It is a sticky topic at the top of the forum and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Users who have thanked tangoforce for this post:
gkjr1 (01-26-2013)
Old 01-26-2013, 04:04 AM   PM User | #3
gkjr1
New Coder

 
Join Date: Jan 2013
Location: Texas, USA
Posts: 35
Thanks: 5
Thanked 0 Times in 0 Posts
gkjr1 is an unknown quantity at this point
Quote:
Originally Posted by tangoforce View Post

If you're going to ask people to look at it and test it you at least need to give them things like the registration code otherwise you're not going to get a lot of help if we can't test it
Sorry about that. Been sick. it doesnt matter what you put in the form. Just keep going with characters until a green arrow shows up, but to be exact one some things:

email needs an email type, password is 6 characters and both have to match, reg code is 16 characters, zip code is 5 numbers, and the rest shouldn't need more than 2 characters.

I took out the submit and yes it is a jquery plugin. There isn't another way I know of to use validation like the rest of the good browsers. The checks still work per browser, at least visually, with those that support html5 form validation. I've looked through the plugin and don't see anything, but I could very possibly be missing something.

Still in the same boat though, no go.

Last edited by gkjr1; 01-26-2013 at 04:09 AM..
gkjr1 is offline   Reply With Quote
Old 01-26-2013, 04:13 AM   PM User | #4
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,532
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
With JavaScript enabled the form will not submit - it also insists on rejecting valid values entered into several of the fields - such as not allowing one character surnames (I know of people with surnames like that), three character state codes and no state code at all are valid depending on which country you are in etc.

With JavaScript disabled it submits and presents http://imengine.gofreeserve.com/fileshare/classes/class.registration.php as a blank page with no code in it whatsoever.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
gkjr1 (01-26-2013)
Old 01-26-2013, 04:53 AM   PM User | #5
gkjr1
New Coder

 
Join Date: Jan 2013
Location: Texas, USA
Posts: 35
Thanks: 5
Thanked 0 Times in 0 Posts
gkjr1 is an unknown quantity at this point
Quote:
Originally Posted by felgall View Post
With JavaScript enabled the form will not submit - it also insists on rejecting valid values entered into several of the fields - such as not allowing one character surnames (I know of people with surnames like that), three character state codes and no state code at all are valid depending on which country you are in etc.

With JavaScript disabled it submits and presents http://imengine.gofreeserve.com/fileshare/classes/class.registration.php as a blank page with no code in it whatsoever.
The validation isn't completely done as I'm still going to add in the dynamic provinces/states/postal codes, but I do appreciate you pointing that out for me to keep in mind.

Weird that it will submit w/o javascript on. Is that typical of all forms, or most likely the validation code I'm using is stopping it? Also which browser? The other page is blank because it wasn't done, and disabling javascript (it's required on the site, eventually when complete) kills some checks clientside, and I haven't returned the errors in the php check yet because I couldn't get there. xD
gkjr1 is offline   Reply With Quote
Old 01-26-2013, 05:35 AM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,752
Thanks: 4
Thanked 2,468 Times in 2,437 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Its typical of all forms that the javascript is interfering with. JS should be the very last thing added. Make sure it works and is validated properly server side, then add the splash of JS for the fancy.

This has syntactical errors within it:
PHP Code:
    $bind = array(
        
":uemail" => "$_POST['email']"
    
); 
That is invalid. That should be:
PHP Code:
    $bind = array(
        
":uemail" => $_POST['email']
    ); 
There is never a reason to require JS.
You shouldn't be developing code on a live server. Download an apache, php and mysql environment and install it (or a package like the wamp or many other flavours), and test there. At the minimum get ahold of the php.exe which can execute a lint check against the code, which is what I did to see the T_ENCAPSED_AND_WHITESPACE error on that line above.
__________________
PHP Code:
header('HTTP/1.1 420 Enhance Your Calm'); 
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
gkjr1 (01-26-2013)
Old 01-26-2013, 07:00 PM   PM User | #7
gkjr1
New Coder

 
Join Date: Jan 2013
Location: Texas, USA
Posts: 35
Thanks: 5
Thanked 0 Times in 0 Posts
gkjr1 is an unknown quantity at this point
Quote:
Originally Posted by Fou-Lu View Post
Its typical of all forms that the javascript is interfering with. JS should be the very last thing added. Make sure it works and is validated properly server side, then add the splash of JS for the fancy.

This has syntactical errors within it:
PHP Code:
    $bind = array(
        
":uemail" => "$_POST['email']"
    
); 
That is invalid. That should be:
PHP Code:
    $bind = array(
        
":uemail" => $_POST['email']
    ); 
There is never a reason to require JS.
You shouldn't be developing code on a live server. Download an apache, php and mysql environment and install it (or a package like the wamp or many other flavours), and test there. At the minimum get ahold of the php.exe which can execute a lint check against the code, which is what I did to see the T_ENCAPSED_AND_WHITESPACE error on that line above.
I got it working. It was hung up on the way I was updating the db. I understand you NEVER have to have js, but I was using it no matter what for other things like folder tree stuctures, ect.

All I was trying to do was let html5 do it's pretty validation on IE as well as older browser versions that don't support it, so the majority of regular users on IE 9 could enjoy it, and save me some time. It isn't a requirement I know, just never ran into a js for input fields interrupt a submit button action on a form.
gkjr1 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:24 AM.


Advertisement
Log in to turn off these ads.