> -----Original Message----- > From: Tom [mailto:obelix16@xxxxxxxxxxx] > Sent: Tuesday, January 27, 2009 9:58 AM > To: php-general@xxxxxxxxxxxxx > Subject: Re: Coding for email response forms > > > "Edmund Hertle" <edmund.hertle@xxxxxxxxxxxxxxx> wrote in message > news:f7ed91b20901261644y125f71aer3e0b70735c949811@xxxxxxxxxxxxxxxxx > > 2009/1/26 Tom <obelix16@xxxxxxxxxxx> > > > >> > >> "Shawn McKenzie" <shawn@xxxxxxxxxxxxx> wrote in message > >> news:497E3AB9.2060008@xxxxxxxxxxxxxxxx > >> > > >> > > >> > Shawn McKenzie wrote: > >> >> > >> >> Tom Scott wrote: > >> >>> ----- Original Message ----- From: "Shawn McKenzie" > >> >>> <nospam@xxxxxxxxxxxxx> > >> >>> Newsgroups: php.general > >> >>> To: <php-general@xxxxxxxxxxxxx> > >> >>> Sent: Monday, January 26, 2009 3:52 PM > >> >>> Subject: Re: Coding for email response forms > >> >>> > >> >>> > >> >>>> Tom wrote: > >> >>>>> "Shawn McKenzie" <> wrote in message > >> >>>>> news:A0.87.62571.3D92E794@xxxxxxxxxxxxxxx > >> >>>>>> Tom wrote: > >> >>>>>>> My Hosting site said that I needed to include the PHP > otherwise > >> >>>>>>> the form > >> >>>>>>> won't work. I need to know where to include my email info to > get > >> >>>>>>> this set > >> >>>>>>> up > >> >>>>>>> don't I? What do you suggest? > >> >>>>>>> T > >> >>>>>>> "Daniel Brown" <danbrown@xxxxxxx> wrote in message > >> >>>>>>> > news:ab5568160901261259p6d6442a4ya5ea4134025e5f50@xxxxxxxxxxxxxxx > >> .. > >> >>>>>>>> On Mon, Jan 26, 2009 at 15:57, Tom <obelix16@xxxxxxxxxxx> > wrote: > >> >>>>>>>>> I am a new user of PHP, and am using Dreamweaver CS3 for > the > >> >>>>>>>>> webpages. > >> >>>>>>>>> The > >> >>>>>>>>> following page has my form but the submit button is not > working > >> >>>>>>>>> properly. > >> >>>>>>>>> http://www.richlandmtg.com/contacts.html > >> >>>>>>>>> What code is needed and where does it get placed in the > page.? > >> >>>>>>>>> I > >> >>>>>>>>> thought > >> >>>>>>>>> CS3 > >> >>>>>>>>> took care of this. > >> >>>>>>>> Tom, > >> >>>>>>>> > >> >>>>>>>> This issue has nothing at all to do with PHP. This is > all > >> >>>>>>>> client > >> >>>>>>>> side (JavaScript and HTML). > >> >>>>>> What you have now is a form that when submitted sends the > data to > >> >>>>>> itself. So you either need to include some php in this file > to > >> >>>>>> gather > >> >>>>>> up the data and email it when submitted, or submit to another > file > >> >>>>>> that > >> >>>>>> does that. > >> >>>>> Shawn, > >> >>>>> So would that look something like this: > >> >>>>> <? > >> >>>>> if ($_SERVER['REQUEST_METHOD'] == "POST") { > >> >>>>> > >> >>>>> // Just to be safe, I strip out HTML tags > >> >>>>> $realname = strip_tags($realname); > >> >>>>> $email = strip_tags($email); > >> >>>>> $feedback = strip_tags($feedback); > >> >>>>> > >> >>>>> // set the variables > >> >>>>> // replace $me@xxxxxxxxxx with your email > >> >>>>> $sendto = "$me@xxxxxxxxxx"; > >> >>>>> $subject = "Sending Email Feedback From My Website"; > >> >>>>> $message = "$realname, $email\n\n$feedback"; > >> >>>>> > >> >>>>> // send the email > >> >>>>> mail($sendto, $subject, $message); > >> >>>>> > >> >>>>> } > >> >>>>> ?> > >> >>>>> > >> >>>> Oh, you should also think about some other things, such as > >> >>>> validation. > >> >>>> Is realname only alpha characters? Is email in the form of a > real > >> >>>> email > >> >>>> address? At a bare minimum, are they not empty: > >> >>>> > >> >>>> if (empty($_POST['email']) || > >> >>>> empty($_POST['realname']) || > >> >>>> empty($_POST['feedback'])) > >> >>>> { > >> >>>> echo 'You must complete all required fields!'; > >> >>>> // show form again > >> >>>> } > >> >>>> > >> >>> Ok. I have the validation part. > >> >>> http://www.richlandmtg.com/index-5.html still working on the > Send > >> >>> button. > >> >>> > >> >> Please reply all so this stays on the list. > >> >> > >> >> 1. In the source for your link I see that the JS is doing some > >> >> validation. > >> >> 2. You have method="get" in your form. This will work, but > you'll > >> >> have > >> >> to change the PHP code to use $_GET instead of $_POST vars. Or > change > >> >> to method="post" in the form. > >> >> 3. If you want to keep the .html extension for the page, then > you'll > >> >> probably need to send the post to another script with a .php > >> >> extension. > >> >> Normally a file with a .html extension won't execute the PHP > code. > >> I was just looking at that. Someone told me to use GET instead of > POST. > >> Since JS is validating is it as easy replacing GET with POST ? > Nothing > >> else > >> needed? Is it better to remove the JS and just code using PHP as you > >> showed > >> before? > >> if (empty($_POST['email']) || > >> empty($_POST['realname']) || > >> empty($_POST['feedback'])) > >> > > Yes, I think it is better to just use PHP code and post is the better > > method > > (in this case) because with get all your fields and values will show > up in > > the url > > > I don't seem to be getting he hang of this. Sounds so simple but.... > Can > someone check this out and tell me where exactly I'm messing up? > http://www.richlandmtg.com/Contact_Us.html > I removed the JS validation. Is the following code ok? > > <a href="#" > onClick="document.getElementById('form').reset()">clear</a><img > alt="" src="images/ch_more_red.gif" style="margin:1px 0 0 3px; > vertical-align:text-bottom"></b><b style="margin-left:17px;"><a > href="#" > onClick="document.getElementById('form').submit()">send</a> > > I posted the PHP info at the top of the page before the <html> tag. > Should > it be after <html>? Tom, I don't think you're getting it... by the time the form is displayed on the user's browser, PHP has wiped its hands clean of the whole ordeal. PHP is used on the server ONLY. Javascript is used on the client ONLY. PHP can take an HTTP request (when the browser REQUESTs a URL) and then perform certain actions based on any number of conditions (variables in the URL or the user's request, the time of day, the color of your socks... whatever). If you want your form to be e-mailed, then it will need to submit itself TO something. Right now, it's not submitting anywhere but to itself. Since it is not a PHP script that e-mails forms, POSTing it to itself does absolutely nothing but refresh the page. It works kinda like this: 1.) Client requests the form 2.) Web server sends the form down (no PHP) 3.) User fills out the form and clicks SUBMIT 4.) Form POSTs to a PHP page 5.) PHP page grabs form data and e-mails it somewhere 6.) PHP page creates HTML that says "success/failure" 7.) User sees PHP-created success/failure page. The thing isn't going to e-mail itself, and Javascript certainly isn't enough to pull it off. I think you need to buff up a tad bit on the basic concepts of server-side languages before you try to tackle even the simplest task. People who don't fully understand PHP tend to further confuse themselves when they try to mix Javascript with it before knowing what they're dealing with. http://www.w3schools.com/php HTH, // Todd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php