kinda noobie question on form processing...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
loinsees
Forum Newbie
Posts: 1
Joined: Wed Mar 21, 2007 7:18 pm

kinda noobie question on form processing...

Post by loinsees »

Hello, can someone please help me out with form processing?

The form is located at http://www.loinsees.info/loin/feedback/feedback.php. What I am trying to do is to get the error messages to show up on the same page as the form. Right now it shows up in a different page and you have to click back to get back to the form. To see the error messages, submit a blank form. The form and the form processor php is in the same document. Here is the source:

Code: Select all

<html>
<head>
</head>
<body>

<?php if (!isset($_POST['submit'])) { ?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  Send email from: <input name="from_email" type="text" /><br />
  Send email to: <input name="to_email" type="text" /><br />
  Subject: <input name="subject_email" type="text" /><br />
  Message:<br />
  <textarea name="message_email" rows="15" cols="40" default="">
  </textarea><br />

  <br />
  <input type="submit" name="submit"/>
</form>

<?php
    }
else {

$from_email = $_REQUEST['from_email'] ;
$to_email = $_REQUEST['to_email'] ;
$subject_email = $_REQUEST['subject_email'] ;
$message_email = $_REQUEST['message_email'] ;

echo '<strong>Messages:</strong>';
echo '<ul>';
if (!$_POST['from_email'])
echo '<li> "Send email from" section cannot be empty </li>';
if (!$_POST['to_email'])
echo '<li> "Send email to" section cannot be empty </li>';
if (!$_POST['subject_email'])
echo '<li> "Subject" section cannot be empty </li>';
if (!$_POST['message_email'])
echo '<li> "Message" section cannot be empty </li>';
if (mail ( $to_email, $subject_email, $message_email, "From:$from_email" ))
echo '<li> Message sent succesfully </li>';
else 
echo '<li> Failed to send </li>';

echo '</ul>';

}
?>

</body>
</html>
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

put your form in a function. e.g.

Code: Select all

function show_form() {
    print('form html');
}
then call it when you need.

Code: Select all

if (!isset($_POST['submit'])) {
    show_form();
}
else {
    if (!validate) {
        print("uhoh!");
        show_form();
    }
}
Post Reply