0

I know I must be doing some small mistake somewhere but its been last 4 hours and I'm still scratching my head as to where is the mistake hence help would be greatly appreciated.

So I've a form in php and I try submitting it to itself. Basically my form is in register.php and it includes register.inc.php file through

include_once 'register.inc.php';

There is another page namely home.php which also includes register.inc.php and does its form processing from there. Though I've different criteria to differentiate from which page is the page register.inc.php called but for clarifications, I'll add codes from both.

Here is my home.php.

<form action = "<?php echo esc_url($_SERVER['PHP_SELF']); ?>" method = "post" name = "key">
     Enter the Unique (10 letter) you received to proceed : <input type = "text" name = "key" id = "key"></br>
<input type="submit" value="Submit"  /> <?php echo $err; ?>

esc_url() is custom built function and works fine.

Here is my register.php file.

<form action="<?php echo esc_url($_SERVER['PHP_SELF']); ?>" 
            method="post" 
            name="registration_form">
        Full Name: <input type='text' 
            name='fullname' 
            id='fullname' value = "<?php echo $fullname; ?>" disabled/><br>
        Email: <input type="text" name="email" id="email" value = "<?php echo $email; ?>" disabled/><br>
        Username: <input type='text' 
            name='username' 
            id='username' /><br>
        Password: <input type="password"
                         name="password" 
                         id="password"/><br>
        Confirm password: <input type="password" 
                                 name="confirmpwd" 
                                 id="confirmpwd" /><br>
        Project Name: <input type="text"
                         name="project" 
                         id="project" value = "<?php echo $project; ?>" disabled/><br>
        Phone Number: <input type="text" 
                                 name="phone" 
                                 id="phone" value = "<?php echo $phone; ?>" disabled/><br>
        <input type="button" 
               value="Register" 
               onclick="return regformhash(this.form,
                               this.form.fullname,
                               this.form.project,
                               this.form.phone,
                               this.form.username,
                               this.form.email,
                               this.form.password,
                               this.form.confirmpwd);" /> 
    </form>

I've a js file named forms.js which does encryption of password in client side before sending it to server. So here is my js file just in case required. (Though it works fine. There is no problem due to it. I've verified it.)

function regformhash(form, uid, , fullname, email, phone, project, password, conf) {
var p = document.createElement("input");

// Add the new element to our form. 
form.appendChild(p);
p.name = "p";
p.type = "hidden";
p.value = hex_sha512(password.value);

// Make sure the plaintext password doesn't get sent. 
password.value = "";
conf.value = "";

// Finally submit the form. 
form.submit();
return true;
}

And finally, here is the code snipet from my register.inc.php file. I think there is some error in this file. I'm posting it in two parts.

The following part is condition used to check if the register.inc.php is called from home.php

if(isset($_POST['key'])) {
  //Something....
}

And the following to check if its called from register.php

echo $_POST['username']. $_POST['project']. $_POST['p'];
if (isset($_POST['fullname'], $_POST['project'], $_POST['phone'],$_POST['username'],$_POST['email'], $_POST['p'])) {
// Sanitize and validate the data passed in
echo "12";
//something...
}

I start at home.php. Enter the key. Check weather it exists in database or not. If true, I redirect my user to register.php. There he gets to fill out the form. Some of details like full name, phone, email etc are filled out earlier. Hence those text fields are locked. The user needs to fill out only username and password. After he presses submit, I verify all credentials and if everything checks out I save it in DB. DB work is done in register.inc.php.

But my error is that, though my key verifies out and I get redirected to register.php, but after that when I enter my username & password, is always says :

Undefined index: username

Undefined index: project

Undefined index: p

And the array $_POST[] in register.inc.php(before isset(......)) remains undefined. I also tried GET method but the same error.

I dont know what I am doing wrong hence help will be greatly appreciated.

Thanks in advance.

Community
  • 1
  • 1
Debasish Kanhar
  • 1,123
  • 2
  • 15
  • 27
  • Looks like your first input tag isn't self-closing. Make sure it ends with "/>" and try again. That might be it. –  Oct 17 '14 at 01:00
  • Yes disabled and /> were attached. I gave space between those. But still the problem is same. I hope you are talking about > close in register.php right? – Debasish Kanhar Oct 17 '14 at 01:16
  • Okay you meant /> in home.php. Tried that but the same problem. – Debasish Kanhar Oct 17 '14 at 01:19
  • `project` is not set as you have it `disabled`, and disabled elements are not sent, see http://stackoverflow.com/a/7730719/689579 – Sean Oct 17 '14 at 01:25
  • I tried using the same code without disabled. I instead used "readonly" and didnt use any even. But the same problem persists. – Debasish Kanhar Oct 17 '14 at 01:28
  • My guess is that you are getting `undefined index ` from `echo $_POST['username']. $_POST['project']. $_POST['p'];` when you redirect from `home.php` to `register.php`. Try putting them in an `isset()` – Sean Oct 17 '14 at 01:31
  • Even isset doesn't seem to work. I ve written a statement to print if isset is successful bit it never prints. ( I ve given the code – Debasish Kanhar Oct 17 '14 at 01:47
  • Okay I did some modification, but it doesnt work still. I added the register.inc.php code to register.php file and didnt include register.inc.php. I also changed submit button type from "button" to "submit" in register.php I also changed form submission as "document.registration_form.submit()" in my forms.js file where registration_form is id of my form but still error continuous. The data is not transmitted. The $_POST array is blank. Any help please? – Debasish Kanhar Oct 17 '14 at 13:43
  • It doesn't seem logical to use `name="key"` at home.php for the form and text input tags. I'd make them unique. – mickmackusa Nov 03 '17 at 21:13
  • Rather than writing `onclick` in the submit button, try writing `onsubmit` in the form tag and `return true` without `form.submit()`. – mickmackusa Nov 03 '17 at 21:22

0 Answers0