Form Problems 1

Hello.

I’m having problems with my form. I’ve never built one before, and know absolutely nothing about server-side stuff like php so the only way I have found to make a form is to use a service like Formspree.

When testing it, I keep getting an error message saying:

Can’t send an empty form

Make sure you have placed the “name” attribute in all your form elements.

I have put name attributes in there - lots of them! My code is:

<form action="http://formspree.io/example@hotmail.com" method="post" enctype="text/plain">
           <div>
        <label name="message" for="name">Name:</label>
        <input type="text" name="name" id="name" required>
    </div>
    <div>
        <label name="message" for="mail">E-mail:</label>
        <input type="email" name="email" id="mail" required>
    </div>
    <div>
        <label name="message" for="msg">Message:</label>
        <textarea id="msg" name="message" required></textarea>
    </div>
       <div class="button">
        <button type="submit" name="message" class="contactbutton">Send your message</button>
    </div>
        </form>

Website is http://ineedaweatherforecast.co.uk/# - on the contact us page.

Can anyone please point me in the right direction?

Thanks
James

1 Like

The example at Formspree uses

<input type="submit" value="Send">

rather than a button for submit. I don’t know if it makes a difference but have you tried that?

Both your message textarea and your submit button share the same name: “message”.
Field names should be unique.

1 Like

Your labels don’t need a name attribute - just the elements such as input and textarea. The name attribute helps the code identify what the user is putting in each of the form fields.

1 Like

Just tried that but it didn’t help.

Did you remove all the duplicate name="message" attributes from the labels and the button?

Yes I think so. I now have:

<form action="http://formspree.io/example@hotmail.com" method="post" enctype="text/plain">
           <div>
        <label for="name">Name:</label>
        <input type="text" name="name" id="name" required>
    </div>
    <div>
        <label for="mail">E-mail:</label>
        <input type="email" name="email" id="mail" required>
    </div>
    <div>
        <label for="msg">Message:</label>
        <textarea id="msg" name="message" required></textarea>
    </div>
       <div class="button">
        <button type="submit" name="submit" class="contactbutton">Send your message</button>
    </div>
        </form>

Try giving the form element a name too.

Finally worked it out - I removed enctype=“text/plain” - no idea why I had that in there?

Thanks for your help.

3 Likes

Hi there jamesthemonkeh,

I would just like to point out that the code that you
posted in your original post, did work in spite of the
errors that have already been mentioned, or the
removal of the enctype=“text/plain” attribute. :ok:

I tested the code with my installed server “XAMPP”
and also at my http://www.coothead.co.uk/ server. :sunglasses:

coothead

1 Like

The form element is not supposed to have a name - only the fields you expect to be passed to the server should have a name and the form itself doesn’t have a value to be passed. That would be just as incorrect as naming the labels (that is it would work because browsers ignore the names on everything except form fields that can be passed to the server).

enctype=“text/plain” is the default for that particular form attribute which is why the form still works without it.

2 posts were split to a new topic: Redirect all pages to one

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.