 |

07-13-2005, 06:30 AM
|
|
WebProWorld Pro
|
|
Join Date: May 2004
Location: Sydney
Posts: 146
|
|
forms and email style
I have created a dozen personal sites, but am finally doing my first paid one. So I want to do it properly.
I have a form, collecting around 20 input fields, and sending an email. Probably CCing to the sender. Whose email address will be entered. And I guess ideally should be validated.
1. Is it "better" to accept all input, and go to a new page with the thanks/success message. Or to stay on the same page, resetting all fields, displaying thanks/success message at the top/bottom of the page?
2. I have toyed with writing my own php code. It sends ok. But so far I'm not setting up the header info correctly. And I worry how resilient it is across platforms.
Am I reinventing the wheel? Should I persevere with the php, or is there a standard formmail bit of code that everybody uses? Or is that lazy/cheating?
Chris
|

07-13-2005, 08:21 AM
|
|
WebProWorld Veteran
|
|
Join Date: Apr 2005
Location: Winter Park, FL
Posts: 605
|
|
I work in a small web design firm and we have hosting options of NT or Unix. Depending on which the client requests, we have a couple standard procedures we follow for this situation. For Unix we have php script that handles it all on the same page and sends a thank you to the sender. For NT, we have it redirect to a thank you page and send a thank you. In both cases though, we have a javascript regular expression that processes the email address to make sure its not just someone putting in jibberish.
|

07-13-2005, 01:59 PM
|
|
WebProWorld Pro
|
|
Join Date: Mar 2004
Location: Pittsburgh, PA, USA
Posts: 114
|
|
Re: forms and email style
Quote:
|
Originally Posted by ozchris
I have a form, collecting around 20 input fields, and sending an email. Probably CCing to the sender. Whose email address will be entered. And I guess ideally should be validated.
1. Is it "better" to accept all input, and go to a new page with the thanks/success message. Or to stay on the same page, resetting all fields, displaying thanks/success message at the top/bottom of the page?
|
Definitely go to a new page (from the user's perspective - It really doesn't matter if your target is $php_self as long as the script is generating content that looks like a new page). If your users see the form again - whether blank or still filled out, they will get confused. Show them the text of the message they sent and a confirmation that it was sent.
As for validation, I'd suggest doing it in both JavaScript and PHP. JS will be more immediately responsive as mistakes are made and PHP will be more reliable in case they have JS turned off or are running a browser with a wonky JS impementation.
Quote:
|
2. I have toyed with writing my own php code. It sends ok. But so far I'm not setting up the header info correctly. And I worry how resilient it is across platforms.
|
Since php is processed on the server, the client platform doesn't matter a bit. If you mean 'will switching server platforms in the future cause a problem?', probably not. There are a few differences, but php runs fine on Windows, Linux, netBSD, and most other platforms.
Quote:
|
Am I reinventing the wheel? Should I persevere with the php, or is there a standard formmail bit of code that everybody uses? Or is that lazy/cheating?
|
I'd say there are quite a few "standard formmail" bits floating around. But will any of them do exactly what you want with all 20 pieces of data you've collected?
|

07-13-2005, 04:15 PM
|
|
WebProWorld Pro
|
|
Join Date: May 2004
Location: anchorage, alaska
Posts: 241
|
|
Many hosting companies offer built in form handler scripts. Check with yours. Some are also prohibiting FormMail scripts with glaring security holes so check before trying to install a script that may get your site suspended.
From a user point of view, send them to a thanks page. This makes it clear that the form submission worked. Any time you make it easy for the visitor, your site works better.
Make sure the thanks page has navigation allowing the visitor to get back to the main body of your site.
JM
http://www.probizhosting.com - You can do it sitebuilder.
http://www.crucibledesigns.com - Web Design & Development
http://www.jomaries.com - Do it yourself website makeover
|

07-14-2005, 08:52 AM
|
|
WebProWorld Pro
|
|
Join Date: May 2004
Location: Sydney
Posts: 146
|
|
Ok. So I'll goto a new page when successful, and start by validating in php. (Will try javascript validation when I've got this right).
I'm a relative oldie who left uni before object-oriented stuff came in, so please forgive the top-down approach. (Long live Pascal and PL/1)
The page to display the form will be formpage.php.
If they enter it right, it will redirect to newpage.php.
So in formpage.php:
if details-entered
then validate form.
if valid-form
then send-email
if email-sent-ok
then goto successpage
(header(location: newpage)
else set error message
else (invalid-form)
set field error messages
......
display form (action=formpage.php)
hidden field details-entered set to true
Is this how to structure it? The idea of validating before displaying the actual form seems wierd.
I'm learning PHP from a QuickStart book at home, so haven't been able to look over the shoulder of people coding PHP nicely.
When I re-enter formpage.php upon actioning the form, will I run into the problem that the fields entered will be reset to blank?
All this validation code at the top is so search-engine unfriendly, too.
Am I approaching this correctly?
|

07-14-2005, 03:58 PM
|
|
WebProWorld Pro
|
|
Join Date: Mar 2004
Location: Pittsburgh, PA, USA
Posts: 114
|
|
Quote:
|
Originally Posted by ozchris
Ok. So I'll goto a new page when successful, and start by validating in php. (Will try javascript validation when I've got this right).
[...]
Is this how to structure it?
|
Not quite. I think you're a little confused about the server-sidedness of PHP. Any validation that takes place before the form is submitted must be done on the client - that's where JavaScript comes in. So for the server-side, PHP portion, it would be more like:
The form is submitted
if (isset($submit_button)){
for each field in form{
if !validate(field){
generate a form with entered values pointing out where they messed up - or redirect back to form page with data on what they entered and how they messed up.
}
}
if send(email){
Generate Success page
}else{
Generate Error Page
}
}
Quote:
|
I'm learning PHP from a QuickStart book at home, so haven't been able to look over the shoulder of people coding PHP nicely.
|
Books are great, but don't forget there's a vast amount of info and code examples online too.
Quote:
|
When I re-enter formpage.php upon actioning the form, will I run into the problem that the fields entered will be reset to blank?
|
Yes. You'll have to use PHP to generate the form with the entered values.
Quote:
|
All this validation code at the top is so search-engine unfriendly, too.
|
It isn't. The PHP validation code is processed on the server and isn't visible to search engines at all.
|

07-15-2005, 09:11 AM
|
|
WebProWorld Pro
|
|
Join Date: May 2004
Location: Sydney
Posts: 146
|
|
Thanks for help so far.
I've got a cut-down version going at http://sydney-web-design.com/fergusons/test.php, going mostly well with PHP validation, but there are some problems.
I'm doing <input type=text name=ownername
value="<? print $ownername; ?>">
so the text field value doesn't get reset to blank when they hit submit. But I haven't worked out how to do that for radio buttons. Any tips?
Current radio html is:
<input type="radio" name="correspondent" value="Owner">Owner
<input type="radio" name="correspondent" value="Master">Master
<input type="radio" name="correspondent" value="Agent">Agent
Apart from that I think it's working.
Will try the javascript validation next month.
ta Chris
|

07-18-2005, 10:08 AM
|
|
WebProWorld Pro
|
|
Join Date: Mar 2004
Location: Pittsburgh, PA, USA
Posts: 114
|
|
Quote:
|
Originally Posted by ozchris
... I haven't worked out how to do that for radio buttons. Any tips?
|
Untested, but something like this should work:
<input type="radio" name="correspondent" value="Owner" <? print $correspondent="Owner"?"checked='checked'":"" ?>/>Owner
<input type="radio" name="correspondent" value="Master" <? print $correspondent="Master"?"checked='checked'":"" ?>/>Master
<input type="radio" name="correspondent" value="Agent" <? print $correspondent="Agent"?"checked='checked'":"" ?>/>Agent
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|