What happened to Week 5 was that I got caught up in other projects and sidetracked -- a hazard when one doesn't do web design for a living! But I'm all read up now, and I'm happy to report that I have a PHP script live on my website: a contact form. It was a little harder than I imagined. Coding the form was not too hard, though it still needs some polish from the CSS side. The script itself was also not hard to get (with a little modification) from tele-pro.co.uk. What was hard was making the form and the script play nicely together. Here's that story.
1. I downloaded the script wholesale into the folder for my site, and added a call to the script in the markup for the Submit button. This seemed like a logical place to put it, since that's where a mailto command would go. I uploaded the result to my site and tried to send myself the feedback "Watson, come here, I need you." The page refreshed itself, and my inbox remained empty.
2. Okay. Maybe there's a problem with the script. I had set the email to originate from the address stop@nothing. Maybe it doesn't like that "nothing" isn't a real domain name. I changed it to nothing.com. Same result.
3. Serious debugging time. I set the script, if successful, to redirect the submitter to Google, and if unsuccessful, to redirect to Yahoo. That way -- I reasoned -- I can figure out whether the problem is that the script isn't working (Yahoo), or whether it's working but isn't doing what it's supposed to (Google). Instead, I got another page refresh -- no Google or Yahoo!
4. Wow, all right, so something is really wrong: the script is not getting called at all. Perhaps MyWeb doesn't support PHP. I looked that up in the tech support FAQs, and it turns out that PHP is the one and only supported scripting language -- lucky me, but it doesn't explain my problem!
5. Well, if the problem is not server-side, and it's not the script, it must be the XHTML. I finally stumbled on putting the call to the script inside the form tag instead of the Submit button's tag. On reflection, this made more intuitive sense. I tried it again and was rewarded with a trip to Google and an email from stop@nothing.com in my inbox! I threw together a quick "thanks for submitting your feedback" page to replace Google in the script, and that concluded my first sally into PHP!
Full congratulations and possibly a Congressional Medal of Honor are due to me for figuring all this out, but it's also interesting to observe how much I'm relying on the work of other people at every stage -- tele-pro, Dreamweaver, Chrome, the PHP team, Tim Berners-Lee's successors, whoever wrote the CSS template I'm using, and others. It takes decades of work from thousands if not millions of web developers before I can so easily put one silly script on my website. I am beginning to understand the fierce sense of community among Web developers and GNU enthusiasts!
No comments:
Post a Comment