www.webdeveloper.com
Results 1 to 13 of 13

Thread: php formhandler only works in Firefox

  1. #1
    Join Date
    Nov 2008
    Location
    NC, USA
    Posts
    29

    php formhandler only works in Firefox

    I have setup an HTML form which is to take the form info & email it to a specified user. The php coding works in Firefox but does not in Chrome or IE. I admit I am partial to Firefox, but there are some that will be submitting this form that may want to use something else. Example of the php code includes:
    $EmailFrom = Trim(stripslashes($_POST['email']));

    After trimming all the variables, the $Body of the email is then concatenated using the variables & constants. All statements are ending with the semicolon.
    Is there some validation coding that I need to include that will make it work with the other browsers? Thanks in advance for any help.

    Bob McP

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    877
    You really have to show us the code if you want help. Do you have error checking turned on? If not, please test it again with it on.

  3. #3
    Join Date
    Nov 2008
    Location
    NC, USA
    Posts
    29
    Sorry I did not include the code. Here is the non-redundant part of the HTML code for the form:
    HTML Code:
    <form method="post" action="../php/educationform.php">
      <table width="100%" border="0">
        <tr>
          <td width="42%" class="textright">Exhibitor Group Name:</td>
          <td width="58%"><input type="text" name="exhibitor" size="50" maxlength="50"></td>
        </tr>
        <tr>
          <td class="textright">Contact Person:</td>
          <td><input type="text" name="contact" size="50" maxlength="50"></td>
        </tr>
         <tr>
          <td class="textright">Email:</td>
          <td><input type="text" name="email" size="50"></td>
        </tr>
        </table>
        <p class="textcenter">
    <input type="reset" name="clearall" class="buttonsize" value="Clear" style="margin-right: 48px;"> 
       <input name='Submit' type='submit' class="buttonsize" value='Submit' />
       </p>
      </form>
    The php that corresponds is:
    PHP Code:
    <?php

    // Set posted data into local variables

    $EmailFrom Trim(stripslashes($_POST['email']));
    $Headers "from: " $EmailFrom "\r\n";
    $Subject "Exhibit Entry Form";
    $Exhibitor Trim(stripslashes($_POST['exhibitor']));
    $Contact Trim(stripslashes($_POST['contact']));

    // The following line sets who the email is sent to:
    $EmailTo "administrator@gmail.com";
    // validation
    $validationOK=true;
    if (
    Trim($EmailFrom)==""$validationOK=false;
    if (!
    $validationOK) {
      print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=educationform.html\">";
      exit;
    }

    // prepare email body text
    $Body "";
    $Body .= "From:    " $Exhibitor "\n";
    $Body .= "E-mail:  " $EmailFrom "\n\n";
    $Body .= "Contact: " $Contact "\n";

    // send email
    $success mail($EmailTo$Subject$Body$Headers);

    // redirect to success page
    if ($success){
        print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=../index.html\">";
      } else {
        print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=../judging.html\">";
       }  
    ?>
    There are other variables but I cut down on the duplicate code to save space & reading. I did put in your error coding that you recommended & that did point out a couple of errors that I had. I did fix those & the problem still exists. I am not well versed in php but have been successful in using this type app before. I have compared the code to a previous program that I used but cannot find anything that I can see will cause this issue. Thanks for additional help.

    Bob McP
    Last edited by NogDog; 08-26-2014 at 10:04 PM. Reason: added [php] tags around code

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,616
    Can you define "does not work"? What are you expecting to happen that is not happening or happening in an incorrect way?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Nov 2008
    Location
    NC, USA
    Posts
    29
    What is supposed to happen is the form data is emailed to a designated person. Firefox was originally handling the email & the correct success page showed up. After further testing, none of the browsers are working. The page is loading that shows the result to be unsuccessful. So for some reason, the email is not being sent. The code is redirecting correctly but I have no idea why the email is not going through. I am not getting any type of error message. Is it possible that the problem may be a php version issue. I have not checked to see the version of php on the server but I feel it is up to date. The hosting service is BlueHost.

    Bob McP

  6. #6
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    877
    I don't see the error handling code in your example. Please show us exactly what is running and then tell us exactly what you get in return.

  7. #7
    Join Date
    Nov 2008
    Location
    NC, USA
    Posts
    29
    The HTML form loads & the user completes it, then clicks the Submit button at the bottom. After a few seconds, the page that is set to display if the process is not successful displays. There is no error message. I did put in the error handling code that you sent me at the top of the code right after the <? php, I did get some error code in an error log file on the server & in looking at that code, found a couple of syntax errors which I corrected. When I copied the code to post here, I did not include the error code since I did not think it was needed for our purpose here.
    I know with other programming languages it is possible to put in code in various places throughout the program which will pause the program & display some message. Perhaps I need to include some type of message device in the code so it will pause at different places throughout the execution. I hope I have given sufficient information but let me know what else I can provide that I have not already.
    Thanks

    Bob McP

  8. #8
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,616
    The two quick and dirty approaches to debugging PHP are error_log() and die(), depending on whether you want to write a message to the PHP error log or stop the program at that point and display something in the browser (or STDOUT).
    PHP Code:
    // code...code...code
    error_log('$var is:'.PHP_EOL.var_export($var1));
    // code...code...code
    if( ! is_string($var)) {
        die(
    '<pre>$var is not  a string!'.PHP_EOL.var_export($var1).'</pre>');

    You can do some more powerful (and graceful) debugging with the FirePHP plugin for Firefox (works with FireBug), or some IDEs have XDebug support -- but I've generally just gotten by with the quick and dirty approach.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  9. #9
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    877
    I'd like to see your code WITH the error checking lines. I do not believe that what I gave you would put something into the error log but NOT on the screen. Therefore....

    As nogdog said - use the echo command frequently to show your progress, display var contents and in general to pinpoint exactly what's wrong. Debugging. Get used to it.

  10. #10
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,616
    I even have a macro in my editor that inserts this when I press Ctrl-Shift-D:
    PHP Code:
    die("<pre>".var_export($data1)."</pre>"); 
    Then I just replace $data with the variable of interest. Or if I copy the variable name of interest into the clipboard, I just type Ctrl-Alt-D and it automatically puts it where $data is.

    Komodo Edit macros:
    First version:
    Code:
    komodo.assertMacroVersion(3);
    if (komodo.view) { komodo.view.setFocus(); }
    komodo.view.selection = 'die("<pre>".var_export($data, 1)."</pre>");';
    Auto-paste version:
    Code:
    komodo.assertMacroVersion(3);
    if (komodo.view) { komodo.view.setFocus(); }
    komodo.view.selection = 'die("<pre>".var_export(';
    ko.commands.doCommand('cmd_paste')
    komodo.view.selection = ',true)."</pre>");';
    (both are saved as .js files)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  11. #11
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    2,500
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

  12. #12
    Join Date
    Nov 2008
    Location
    NC, USA
    Posts
    29
    Wanted to post an update & thank everyone for the help. I have FINALLY gotten the form working & sending email in at least Firefox, Chrome, & IE. From what I could tell, I had several problems & using some error trapping suggestions & echoing messages on screen as well as commenting out various sections of code finally nailed down the problem. Part of the problem, I think, was line feeds in the $headers variable. I think also I was building the $body variable incorrectly by beginning with a $Body .=
    I honestly changed so much stuff, turned things on & off, I am not 100% sure what other things I did. The important thing is that it works & I gained a little more experience with working through it. As an earlier post pointed out "Debugging. Get used to it." you were right on target. It does take some stick to it. Thanks again

  13. #13
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    877
    Quote Originally Posted by ginerjm View Post
    Debugging. Get used to it.
    So Very H T H!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles