Can't Get Submit Button To Work On PHP Contact Form

Discussion in 'PHP' started by bad_bob00, Dec 11, 2009.

  1. #1
    Hi,

    The form appears fine on my site but when I click submit it doesn't actually submit any info, doesn't seem to do anything. This is the code on my HTML page of the site:

    I have a PHP file (contact.php) which contains this code:



    Any idea why the button isn't working?

    Thanks for any help
     
    bad_bob00, Dec 11, 2009 IP
  2. n3r0x

    n3r0x Well-Known Member

    Messages:
    257
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    120
    #2
    First of all you don't have <Form method="" action=""> in the code you posted...
     
    n3r0x, Dec 11, 2009 IP
  3. bad_bob00

    bad_bob00 Active Member

    Messages:
    3,472
    Likes Received:
    56
    Best Answers:
    0
    Trophy Points:
    90
    #3
    Sorry n3r0x, where do I need to put this in my code? :eek:
     
    bad_bob00, Dec 11, 2009 IP
  4. einsteinsboi

    einsteinsboi Well-Known Member

    Messages:
    1,122
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    140
    #4
    Technically, you don't really have a form to work with here. What you have is a table with the fields you want but not a form with a method. Look at this tutorial, it will walk you through how to create a simple contact form:

    http://www.kirupa.com/web/php_contact_form.htm
     
    einsteinsboi, Dec 11, 2009 IP
  5. bad_bob00

    bad_bob00 Active Member

    Messages:
    3,472
    Likes Received:
    56
    Best Answers:
    0
    Trophy Points:
    90
    #5
    Thanks einsteinsboi, got that working but just wondered, instead of it showing "Data has been submitted to !" is it possible to just redirect to a different page? Just don't really want to display that page if possible, seems a bit pointless.

    This is the code:

    Thanks for any more help
     
    bad_bob00, Dec 11, 2009 IP
  6. einsteinsboi

    einsteinsboi Well-Known Member

    Messages:
    1,122
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    140
    #6
    Not sure about this, but I think you can redirect it back to another page by using the header() function. Try adding this line at the end of your form submission in place of your echo statement:

    header("location:thepageyouwant.php");
    PHP:
    thepageyouwant.php is the filename of the page you want to redirect the user to after they submit the form. Hope that helps.
     
    einsteinsboi, Dec 11, 2009 IP
  7. bad_bob00

    bad_bob00 Active Member

    Messages:
    3,472
    Likes Received:
    56
    Best Answers:
    0
    Trophy Points:
    90
    #7
    Thanks once again einsteinsboi, thats sorted it out now :)

    Thanks again everyone!
     
    bad_bob00, Dec 11, 2009 IP
  8. einsteinsboi

    einsteinsboi Well-Known Member

    Messages:
    1,122
    Likes Received:
    76
    Best Answers:
    0
    Trophy Points:
    140
    #8
    Glad to help. Make sure to do some reading on validation because you want to sanitize the information entered into your form inputs to prevent attacks. You can just Google it and you'll get lots of information.

    Good luck!
     
    einsteinsboi, Dec 11, 2009 IP