TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,973
  • Latest: NonStop
Stats
  • Total Posts: 196,250
  • Total Topics: 21,354
  • Online today: 626
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online

php article - an email form using "textarea" and PHP_SELF

Started by iowamf, November 15, 2005, 06:59:49 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

iowamf

I'm trying to do a basic email form in a PHP article ... the following code below works.

When I try to change the comments in the form to "textarea" and save it ... it works (the form is saved in the MySQL)
However, the next time I go to edit it (no WYSIWG) it looks like the editor is trying to execute the PHP and everything after the "textarea" form is truncated - if somebody has been able to get a PHP form using a textarea I'd like to see the code.

Also, I get this in the error log

  8: Undefined variable: PHP_SELF

but then when I try to define it .. global $PHP_SELF; ... the script stops working ... I think I'll live with the entry in the error_log.

Note,  yes I'm struggling with PHP ... I'm sure there are better ways to do this ... this was mostly taken from a book and adapted to TinyPortal.

?>
<html><head><title>Feedback</title></head><body>
<?php
if ($_POST)
       {
           
$name = $_POST['name'];
           
$email = $_POST['email'];
           
$comments = $_POST['comments'];
           
// Compose simple text message:
           
$message = "Message from $name ($email)\n\nComments:\n\n$comments";
           
mail("someuser@gbmail.com", "Feedback", $message);
           
//
           
echo "msg sent\n";
       }
       else
       {
?>
        <h1>Feedback</h1>
        <form action="<?= $PHP_SELF ?>" method="post">
            <p>Name: <input type="text" name="name" /></p>
            <p>Email: <input type="text" name="email" /></p>
            <p>Comments: <input type="text" name="email" /></p>
            <p><input type="submit" value="Send!" /></p>
        </form>
<?php
       
}
?>
</body>
</html>

bloc

This is all you need in a php-article, its like writing just pure php:

if ($_POST)
        {
            $name = $_POST['name'];
            $email = $_POST['email'];
            $comments = $_POST['comments'];
            // Compose simple text message:
            $message = "Message from $name ($email)\n\nComments:\n\n$comments";
            mail("someuser@gbmail.com", "Feedback", $message);
            //
            echo "msg sent\n";
        }
        else
        {
        echo '
        <h1>Feedback</h1>
        <form action="'.$_SERVER['PHP_SELF'].'" method="post">
            <p>Name: <input type="text" name="name" /></p>
            <p>Email: <input type="text" name="email" /></p>
            <p>Comments: <input type="text" name="email" /></p>
            <p><input type="submit" value="Send!" /></p>
        </form>';
        }


The PHP_SELF variable is part of $_SERVER value btw.

iowamf

Thanks for the PHP in Articles tip ... I gave it a try and the $PHP_SELF error went away.
However, the email function stopped working.

I tried lots of different things, but after changing the PHP_SELF line to:
<form action="'.$_SERVER['$PHP_SELF'].'" method="post">
note the dollar PHP_SELF ... that's the only change
and got it to work again. However, I do get the "error 8: Undefined index: $PHP_SELF" in the logs again. I have no idea why it only seems to work with the error?

With respect to the textarea issue, I can duplicate it with the php code below in an article. Perhaps my code is so bad it is making the editor go crazy  :-\

echo "PHP_SELF with dollar sign and text area<br>";
if ($_POST)
  {
  $name = $_POST['name'];
  $email = $_POST['email'];
  $comments = $_POST['comments'];
  // Compose simple text message:
  $message = "Message from $name ($email)\n\nComments:\n\n$comments";
  mail("xxxxxxx@gmail.com", "Feedback", $message);
  echo "msg sent\n";
  }
else
  {
  echo '
  <h1>Feedback</h1>
  <form action="'.$_SERVER['$PHP_SELF'].'" method="post">
  <p>Name: <input type="text" name="name" /></p>
  <p>Email: <input type="text" name="email" /></p>
  <p>Enter Your Comments: </p>
  <textarea name= "comments" cols="30" rows="5" /></textarea></p>
  <p><input type="submit" value="Send!" /></p>
  </form>';
  }


After the above code is saved,  the user is presented the form and the email works.

If I go back to edit the code (using the built-in editor) -  the editor drops everything after the textarea command and a "send!" button shows up below the editor.

The article cannot be edited (but it's not corrupted either - the email function still works).

Here is a screenshot of what I see in the editor trying to edit the above code a 2nd time:

IchBin

You are finding out what a piece of sh!t that editor is. There are known problems with the editor. I would suggest you go into TPAdmin and disable it. Then edit your code in the regular boxes. You find you won't have these problems. Bloc is looking into using a different editor in the next release I believe.

Leviathan

I don't think iowamf is using the WYSIWYG editor at all. Tried it myself as well, since I like the idea of a feedback form, and I get the same thing as iowamf.

IchBin

hmm.... it happened with and without the editor to me.

bloc

Its the form of the code that clash with the form of TP. it shouldn't do that..I will investigate.

bloc

Found the error, php articles are not specialchars escaped..i will need to add that to TPortalAdmin file.

IchBin


iowamf

Excellent job on figuring out the "editor gone wild" - the work around is to just not edit it twice.  I'm keeping that script in a separate file and will edit the script and paste it into a new a php article each time for changes.

Actually, I'm more interested in why;

* the mail script works with the $PHP_SELF which causes an error in the logs and
* the mail script doesn't work when PHP_SELF Is defined correctly per Bloc's example.

I ditched that editor early when I was trying to do raw HTML only in articles - damn thing would "help me out" and put some random text at the start of the file for me ... glad Bloc is doing a 4th and long on that editor.

This website is proudly hosted on Crocweb Cloud Website Hosting.