Jump to content

Beginner ?: Why won't the submit button work?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
jackolantern

jackolantern

    Learning Programmer

  • Members
  • PipPipPip
  • 47 posts
Hello! I have been working on PHP for a very short time, and I have come to a roadblock. I am not sure why this page is not working. I am working on a simple example script from a book that I am reading. It is a very simple HTML form to fill out feedback, you press the submit button, and then it calls a PHP script to send an email. I have XAMPP webserver installed on my PC, and I have had other somewhat similar pages work correctly (no mail() function, but other submit buttons have worked fine). I have both the pages in the same htdocs folder that XAMPP has established as the folder to place them in.

I am not sure if this is a problem in the HTML, or in the PHP. Thank you for taking a look, and I appreciate any pointers anyone has as to why this is not working:

HTML page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<h1>Customer Feedback</h1>
<p>Please tell us what you think.</p>
<form action="processfeedback.php" method="post" name="feedback">
  <p>Your name:<br /><input name="name" type="text" size="45" maxlength="45" />
  </p>
  <p>Your email address:<br /><input name="email" type="text" size="45" maxlength="45" />
  </p>
  <p>Your feedback:<br /><textarea name="feedbacktext" cols="45" rows="8"></textarea>
  </p>
  <p><input name="submit" type="button" value="Submit Feedback" />
  </p>
</form>
</body>
</html>

PHP page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
//create short variable names
$name = $_POST['name'];
$email = $_POST['email'];
$feedback = $_POST['feedbacktext'];

//set up some static info
$toaddess = "feedback@example.com";

$subject = "Feedback from website";
$mailcontents = "Customer name: ".$name."\n"."Customer email: ".$email."\n"."Customer comments: \"".$feedback."\"\n";

$fromaddress = "webserver@feedback.com";

//invoke mail() function to send mail
mail($toaddress, $subject, $mailcontents, $fromaddress);


?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bob's Auto Parts - Feedback submitted</title>
</head>

<body>
<h1>Feedback Submitted</h1>
<p>Your feedback has been sent</p>
</body>
</html>

EDIT: I forgot the code would not show it, but the script is named "processfeedback.php", as the HTML page requires.

#2
mikelbring

mikelbring

    Programmer

  • Members
  • PipPipPipPip
  • 118 posts
Make the type on the submit button submit, not button

type="submit"

Realize the Web Web services and design.


#3
Guest_Jordan_*

Guest_Jordan_*
  • Guests
You can use type="button" but you must use JavaScript to make it submit the form. I'd go with mikelbring's suggestion.

#4
jackolantern

jackolantern

    Learning Programmer

  • Members
  • PipPipPip
  • 47 posts
Thanks! That was it. If I am remembering correctly, I think Dreamweaver wrote that part (I have only recently started paying attention to the code DW creates, instead of just going to down in design), so I probably left out some javascript files it needed when I moved it to the XAMPP folder.

Thanks again!