FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Code Stops Working
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Code Stops Working [message #172397 is a reply to message #172395] Wed, 16 February 2011 14:01 Go to previous messageGo to previous message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma:
Senior Member
On 2/16/2011 8:27 AM, Denis McMahon wrote:
> On 16/02/11 00:36, Mike Copeland wrote:
>
>> My apologies to all: I didn't realize that the PHP source isn't
>> accessible. Here it is (but it's messy due to the tabs, etc.). Hope
>> this helps...
>
> Hi Mike
>
> I reduced your php code to a minimal example, and then made it work:
>
> ----8<----8<----8<-- cut here --8<----8<----8<----
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
> "http://www.w3.org/TR/html4/strict.dtd">
>
> <html>
> <head>
> <meta http-equiv="Content-Type"
> content="text/html; charset=utf-8">
> <meta name="MSSmartTagsPreventParsing" content="TRUE">
> <title>Form Test</title>
> <!-- provide trim() and
> notifyInvalidInput() functions -->
> <script type="text/javascript">
> function notifyInvalidInput(msg,field) {
> alert(msg);
> field.focus();
> }
> function trim(str) {
> var len = str.length;
> var result = "";
> if (len == 0) return "";
> var first = 0;
> while (str.charAt(first).match(/\s/) != null&&
> first< len) first++;
> var last = len - 1;
> while (str.charAt(last).match(/\s/) != null&&
> last> 0) last--;
> last ++;
> if (last>= first) return str.slice(first,last);
> return "";
> }
> </script>
> <!-- re-written checkInput() function -->
> <script type="text/javascript">
> function checkInput() {
> var runner = document.getElementById("runner");
> if (trim(runner.value) == "") {
> notifyInvalidInput("Name is a required field. "+
> "Please enter your name.", runner);
> return false;
> }
> return true;
> }
> </script>
> </head>
> <body>
>
> <?php
> if(isset($_POST['submit'])) {
> $to = "invalid1(at)example(dot)com,invalid2(at)example(dot)com";
> $from = "From: invalid3(at)example(dot)com";
> $subject = "Website Results Query Submitted";
> $body1 = "Below is the info submitted on the website:
> Name: {$_POST['runner']}";
> $body2 = wordwrap($body1,70);
> $eml_result = mail($to, $subject, $body2, $from);
> if($eml_result) {
> echo "<p>Your info has been submitted. You will be
> contacted in the next couple of days.</p>";
> }
> else {
> $subject = rawurlencode($subject);
> $body2 = rawurlencode($body2);
> $dest = "invalid4(at)example(dot)com";
> $url = "mailto:$dest?subject={$subject}&body={$body2}";
> echo "<p>There was a problem sending your info. Please
> email<a href='{$url}'>{$dest}</a> about your results
> problem.</p>";
> }
> }
> else {
> ?>
>
> <p>Basic Form:</p>
> <form name="ques_form" id="ques_form"
> action="<?php echo $_SERVER['PHP_SELF'] ?>"
> method="post" onsubmit="return checkInput();">
> <table>
> <tr><td>Name:</td><td><input type="text"
> name="runner" id="runner" size="30"></td></tr>
> <tr><td colspan="2" align="center">
> <input type="submit" name="submit" id="submit">
> </td></tr>
> </table>
> </form>
>
> <?php
> }
> ?>
>
> </body>
> </html>
> ----8<----8<----8<-- cut here --8<----8<----8<----
>
> I have made changes to the php, html and javascript.
>
> Note the following points:
>
> 1) In the above, I have used invalidX(at)example(dot)com email addresses, as
> obviously I don't want to publish the email addresses I used for
> testing. You will need to change these.
>
> 2) I had to write my own trim() and notifyInvalidInput() functions as
> these are not art of standard javascript. I have included the ones I
> used here. I presume the ones you referenced were included in the
> document header php file you were including, but I didn't have a copy of
> that.
>
> 3) Your javascript elements used the deprecated "language" attribute and
> were missing the required "type" attribute.
>
> 4) I removed all the css from the example, it just takes up space.
>
> 5) As previously mentioned, form elements called "name" can cause a
> naming conflict with the form attribute "name" - I reassigned the "Name"
> field as "runner". "contestant" might be another good alternative.
>
> 6) I assigned an "id" attribute to the form and input elements, and I
> use the element id and the document.getElementById() method in
> javascript to identify the form field for both testing content and
> setting focus when the field is empty. Note that any specific id may
> only be applied to a single element in an html document.
>
> 7) I use the standard php "mail()" function and not the "email()"
> function that you were using. I assume your "email()" function is
> defined somewhere in the document header php file you were including,
> but I didn't have a copy of that.
>
> 8) I changed the form to use the post method instead of the get method,
> and additionally, to refer to form elements using the $_POST['']
> predefined variable array.
>
> 9) In the fallback message for email failure, I encode the subject and
> body in the url, so that a suitably configured client-side email client
> will, when clicking on the link, automatically fill in the message
> subject and body text as well as the recipient.
>
> 10) I formatted the source to remain reasonably readable even when in
> the restricted width of a news post.
>
> 11) I've put the form validation javascript in the document head. This
> is cosmetic, but it helps make things more readable too.
>
> I suggest that you save the file as something like "form_test.php", edit
> the email addresses, upload to your server, and see if it works. If it
> does, you may need to investigate and understand some of the points I
> mentioned above.
>
> Rgds
>
> Denis McMahon

Wow! It seems you have essentially done 90% of his work for him. When
I have a problem, I hope you are still around :-) .


--
Shelly
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: about memory usage with php application
Next Topic: PHP currency converter with XML feed
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Nov 25 23:50:38 GMT 2024

Total time taken to generate the page: 0.04811 seconds