简体   繁体   中英

HTML PHP Contact Form - Submit Button Not Working? Or PHP Issue?

Hope you can help, I am trying to knock up a contact form for my website which is HTML, styled with CSS and the email sent with PHP.

<form class="form" action="webform.php" method="post">
    <h1>Contact Form:</h1>
    <label>
    <span>Your Name:</span><input id="name" type="text" name="name" />
    </label>

    <label>
    <span>Email Address:</span><input id="email" type="text" name="email" />
    </label>

    <label>
    <span>Subject:</span><input id="subject" type="text" name="subject" />
    </label>

    <label>
    <span>Message</span><textarea id="feedback" name="feedback"></textarea>
    <input id="button" type="button" value="Submit Form" />
    </label>
</form>

Anyone help me out, can provide the link to my site if necessary.

Appreciate any help :)

You should use submit as the button type

<input id="button" type="submit" value="Submit Form" />

Fiddle DEMO

See updated FIDDLE

Have you tried changing:

<input id="button" type="button" value="Submit Form" />

to:

<input id="button" type="submit" value="Submit Form" />

Alternatively, you can use:

<button id="button" >Submit Form</button>

As you have it now, input type='button' is not a valid element for form submission. For valid form elements, MDN have a great article - see the sections input and buttons

Change type="button" to type="submit"

<form class="form" action="webform.php" method="post">
    <h1>Contact Form:</h1>
    <label>
    <span>Your Name:</span><input id="name" type="text" name="name" />
    </label>

    <label>
    <span>Email Address:</span><input id="email" type="text" name="email" />
    </label>

    <label>
    <span>Subject:</span><input id="subject" type="text" name="subject" />
    </label>

    <label>
    <span>Message</span><textarea id="feedback" name="feedback"></textarea>
    <input id="button" type="submit" value="Submit Form" />
    </label>
</form>

In this particular case, I agree with the suggested solutions re: type="submit .

But I arrived here due to having my buttons stop working all of a sudden, though a Select submit was still working. And it was due to a tiny bug in some Javascript that was killing the submission.

Just something else to check.

try this html form

<form class="form" action="webform.php" method="post">
    <h1>Contact Form:</h1>
    <label>
    <span>Your Name:</span><input id="name" type="text" name="name" />
    </label>

    <label>
    <span>Email Address:</span><input id="email" type="text" name="email" />
    </label>

    <label>
    <span>Subject:</span><input id="subject" type="text" name="subject" />
    </label>

    <label>
    <span>Message</span><textarea id="feedback" name="feedback"></textarea>
    <input id="button" type="submit" value="Submit Form" />
    </label> </form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM