John O'Grady
John O'Grady

Reputation: 245

HTML label control doesn't pass form data to controller

This format of html form control doesn't pass form data

<form action="index.php?action=createNewCustomer"
      method="POST">
 <fieldset>
<label class="field" for="firstName">First Name:</label>
<input type="text">
</fieldset>
<input type="submit">
</form>

but this one does

    <form action="index.php?action=createNewCustomer"
          method="POST">
        <fieldset>

                <label>First Name:</label>
                <input type="text" name="firstName">
</fieldset>
            <input type="submit">
    </form>

Unless I'm missing something obvious, the difference is in the label control..Are both valid and if so, can anyone explain to me why only the second one passes form data to my PHP controller method.

Upvotes: 1

Views: 306

Answers (1)

Propagating
Propagating

Reputation: 130

<input type ="submit"> is not part of the fieldset in the first bit of code, but I don't think that's really the issue.

I believe changing the code on the first bit to:

<form action="index.php?action=createNewCustomer"
      method="POST">
    <fieldset>
        <label for = "firstName">First Name: </label>
         <input type="text" name = "firstName">
        <input type="submit">
    </fieldset>
</form>

will work. You need to make sure the name of the input is the same as the property you are trying to set.

Upvotes: 1

Related Questions