Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS PHP form works on one website but not the other

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #244685
    Phlegmbot
    Participant

    Hi, everyone! I am by NO mean a coder and have built a previous website w/a little self-teaching and a lot of trying and re-trying (and some crying and re-crying).

    I’m trying to create another website now, so I DL’d a free template. I had to add a contact/php form and cannot seem to get it to work.

    I tried this test: http://old.webasyst.net/support/help/test-mail-function.html

    And I DID get an e-mail with the test, so I guess it’s possible to get it working…

    So what I tried next was removing the coding that I had, and instead added the contact form from my old website. That website, and it’s form, are here: http://www.buddyrhodespresents.com/contact.shtml

    I figured if I just copied that form, pasted it in, and saved a new php (also taken from my old site), it’d work fine. But nope!

    For a while I was getting the “Thank you” window but no e-mail ever comes through. Now I’m getting a blank page and still no e-mail.

    I’ve tried different e-mail addresses. The test above works, but actually integrating the form never does. I’ve gone through some tutorials and tried different coding, looking for errors, and a few other things that I’ve forgotten, and none of it seems to resolve the problem.

    It’s probably something stupid I’m missing, so hope someone can help.

    Hopefully I used CodePen correctly.

    Here’s a portion of my index.html page:
    http://codepen.io/anon/pen/RRddPo

    This is the php page:
    http://codepen.io/anon/pen/ZOPPbP

    It’s important to me to have the contact form right there on the home page. Ultimately, I would like to add radio buttons for priority level, and I’d like to change the code so that the “Thank You” or the form errors appear on the SAME page rather than open in a new window, so if anyone is in a giving mood….

    Anyway, thank you for any help y’all can provide!

    PBot

    #244687
    Beverleyh
    Participant

    The thing that stands out immediately is the use of the ereg() function in the PHP code, which was deprecated in v5.3 so it looks like your old website is running in a much older PHP environment.

    You can replace ereg() with preg_match() https://www.google.co.uk/search?q=convert+ereg+to+preg_match Maybe that’s all that’s needed, but I would check your server error logs just to be sure. They’ll give more details of the errors that your site is generating, and where they’re happening, and so make it much easier to troubleshoot.

    The error logs can be in different places depending on the web host; They might be auto-generated in the folder that holds the processing script, or in a log folder outside of the website’s root folder (depending on if you can go that far), or they may be accessible via a reporting section in your web hosts control panel.

    Good luck – hope that helps

    #244733
    Phlegmbot
    Participant

    Hi, Beverley!

    Thanks for the reply. OK, so I tried the change. I think I did it right:
    $email_exp = “^[A-Z0-9._%-]+@[A-Z0-9.-]+.[A-Z]{2,4}$”;
    if(!preg_match($email_exp,$email_from)) {
    $error_message .= ‘The E-mail Address you entered does not appear to be valid.<br />’;
    }

    $string_exp = "^[a-z .'-]+$";

    if(!preg_match($string_exp,$name)) {
    $error_message .= ‘The First Name you entered does not appear to be valid.<br />’;

    <h2> }</h2>

    If that’s incorrect, please advise. As I mentioned, I’m not a coder, and the link you offered and the Google results is gave me were just beyond my understanding. But I looked around for further instruction, and the above was the recommended change to one person over on Stackoverflow for “eregi” changes.

    I also found my logs. I grabbed a few lines which began w/a reference to the PHP doc. Other lines I ignored. I’ve also removed some info for privacy.

    69.203.197.XX – – [17/Aug/2016:20:11:45 -0600] “POST /sendemail.php HTTP/1.1” 200 298 “http://__back.com/&#8221; “Mozilla/5.0 (Windows NT 6.1; WOW64; rv:48.0) Gecko/20100101 Firefox/48.0”

    184.154.36.1XX – – [17/Aug/2016:20:35:34 -0600] “GET / HTTP/1.1” 200 9071 “http://www.google.com/url?url=www.__back.com&yahoo.com&#8221; “Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/6.0)”

    184.154.36.1XX – – [17/Aug/2016:20:35:35 -0600] “GET /sendemail.php?=1&email_from=1&message=1&name=1&submit=submit HTTP/1.1” 200 173 “-” “SiteLockSpider [en] (WinNT; I ;Nav)”

    184.154.36.1XX – – [17/Aug/2016:20:35:35 -0600] “GET /sendemail.php?=1&email_from=1&message=1&name=1&submit=submit HTTP/1.1” 200 173 “http://www.__back.com/sendemail.php?=1&email_from=1&message=1&name=1&submit=submit&#8221; “Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/6.0)”

    184.154.36.1XX – – [17/Aug/2016:20:35:35 -0600] “GET /generic.html HTTP/1.1” 404 570 “-” “SiteLockSpider [en] (WinNT; I ;Nav)”

    184.154.36.1XX – – [17/Aug/2016:20:35:35 -0600] “GET /send_form_email.php?=1&email=1&message=1&name=1&submit=Submit HTTP/1.1” 404 577 “-” “SiteLockSpider [en] (WinNT; I ;Nav)”

    184.154.36.1XX – – [17/Aug/2016:20:35:35 -0600] “GET /send_form_email.php?=1&copy=1&email=1&message=1&name=1&priority=1&submit=Submit HTTP/1.1” 404 577 “-” “SiteLockSpider [en] (WinNT; I ;Nav)”

    ====
    No clue if any of that says anything to you. I sure hope so. If you need more, please let me know.

    And THANK YOU!

    #244734
    Phlegmbot
    Participant

    P.S. Those H2 tags were inserted by the site, not by me. The gray highlighted line ($string_exp = “^[a-z .’-]+$”;) was also added by the site, not me.

    #244741
    Beverleyh
    Participant

    Unfortunately, the logs you’ve posted aren’t error logs – they look like access logs. Access logs show who/what is accessing the site and where from.

    Your error logs will look more like this (lots of these kinds of lines: [date] – [error] – [problem] – [location] – [line]). Example;

    2016-02-06 15:48:05 (UTC) 8 Notice Undefined variable: thumbdownloads File: img_process_script.php Line: 342

    When you convert ereg() to preg_match() you need to use unique delimiters at the start and end of your regex – then you can additionally put the ‘i’ (case-insensitivity) modifier after the last delimiter, making the equivalent of eregi(). Untested, but this;

    $email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";

    should look more like this;

    $email_exp = "#^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$#i"

    See the # at the start and end? And the ‘i’ after the last #?

    You don’t have to use # as your delimiters. You can use other characters too, like a forward-slash, ‘at’, or exclamation-mark – as long as it isn’t a character that appears in the regex. So, you couldn’t use the ‘at’ because you’re matching it as part of the email address.

    This one could use the ‘at’ as a delimiter;

    $string_exp = "^[a-z .'-]+$";

    Becomes

    $string_exp = "@^[a-z .'-]+$@i";

    I’m not 100% sure if these will work because I haven’t tested – I’m just working from memory. You’ll be able to test from your side and if they spit out more errors, the error logs will say what and where.

    #244782
    Phlegmbot
    Participant

    Ohhh. I see. OK. I’m still figuring this all out — I’ve found a few tutorials, but most of them are awful (e.g., one changed the ENTIRE format of the PHP file in the last step, leaving out any context of why and all the explanation of how the new additions change things — which was reeeeally great to see happen in the LAST step! sigh).

    But, alright, I found the error logs. Couldn’t figure it out — compared the line for which it indicated an error w/other coding and PHP forms online, and it looked exactly like other forms I’m seeing. And since you’re “working from memory,” I’m just going to start over and see if that gets me anywhere.

    #244784
    Beverleyh
    Participant

    I found the error logs. Couldn’t figure it out

    What did the error(s) say? (just the ones relating to this particular form submission). We can’t say how to fix them if you don’t say what they are.

    compared the line for which it indicated an error w/other coding and PHP forms online, and it looked exactly like other forms I’m seeing.

    You can’t really play it like that. Code will work in one environment and not another – the difference isn’t necessarily going to be with the code (you’ve established this already). You need to use the error logs to establish what it is that isn’t working – they’ll tell you if that’s related to the code or the environment. If it’s the code, you either fix it (could be something as simple as a missing semi-colon) or write something else (such as using PHP5-friendly code rather than defunct PHP4 stuff). If it’s the environment, you might be able to change a setting (such as enabling an extension in your php.ini file) or, if you can’t change a setting yourself, you take your findings to your web host (could be that they’ve disabled something until you pay to upgrade the account or could be that they’ve made a mistake themselves – it happens). The error logs are vital in tracking down the problem.

    “Working from memory” means that I made an educated suggestion based on my experience of having converted ereg() to preg_match() many times before. But there are other factors to consider and unfortunately I can’t troubleshoot and test for you in your environment.

    Good luck with your project

    #249121
    Phlegmbot
    Participant

    Hi, Beverly,

    Came back to the site to post another topic and saw there was no reply by me above. I’m almost certain I did (attempt to) post a thank you — not sure what happened.

    So thank you, albeit belatedly.

Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘CSS’ is closed to new topics and replies.