user860511
user860511

Reputation:

Form isn't picking up the variables to post

My test PHP submission code:

<?php 
if($_POST['create']) { echo $_POST['name']; }
?> 

My HTML form code:

<form class="form-horizontal" id="ConsultantSignUp" method="post" action="#">

<div class="control-group">
    <label class="control-label" for="inputForename">Name</label>
    <div class="controls">
        <input type="text" class="input-xlarge" id="name" name="name" rel="popover" data-content="Enter your first and last name." data-original-title="Full Name">
    </div>
</div>

<div class="control-group">
        <label class="control-label" for="input01"></label>
        <div class="controls">
            <button type="submit" class="btn btn-success" rel="create" title="create" id="create" name="create">Create My Account</button>
        </div>

    </div>

</form>

My error is that it doesn't even print out the name after submission. I've checked the PHP Error log and it says:

PHP Notice: Undefined index: create in /Users/**/sites/signup.php on line 2

Line 2 being 'if($_POST['create']) { echo $_POST['name']; }'.

I'm aware of the isset() method to remove the Undefined Index notice, how ever, I just want to test my form!

Upvotes: 1

Views: 1597

Answers (3)

Php Geek
Php Geek

Reputation: 1107

This is my total code...This working perfectly for me in Chrome, Explorer and Firefox. Just check it

<?php
    if(isset($_POST['create'])) 
    { 
        echo $_POST['name']; 
    }
    else
    {
?>
<form class="form-horizontal" id="ConsultantSignUp" method="post" action="#">

<div class="control-group">
<label class="control-label" for="inputForename">Name</label>
<div class="controls">
    <input type="text" class="input-xlarge" id="name" name="name" rel="popover" data-content="Enter your first and last name." data-original-title="Full Name">
</div>
</div>
<div class="control-group">
    <label class="control-label" for="input01"></label>
    <div class="controls">
        <button type="submit" class="btn btn-success" rel="create" title="create" id="create" name="create">Create My Account</button>
    </div>
</div>

<?php
}
?>

Upvotes: 0

saad arshad
saad arshad

Reputation: 259

the 'undefined index' NOTICE will go away when you use isset() function. this often occurs when an unchecked checkbox is also posted.

the error is only there because no 'value' is passed on the submit button and the the submit button is POSTED empty.

replace submit button with,

<button value='submitbtn' type="submit" class="btn btn-success" rel="create" title="create" id="create" name="create">Create My Account</button>

PS ONLY (value='submitbtn') is added to your original button

Upvotes: 0

Quentin
Quentin

Reputation: 944076

Your <button ... name="create"> doesn't have a value so it will submit an empty string and $_POST['create'] will evaluate as false.

Give it a value.

Upvotes: 0

Related Questions