September 17, 200719 yr Ok lads and ladies. I am aware that some people are not scripters, so I though I would help y'all out. There are 4 files here, of which 2 are to show an example... So the files: * email.html - an example form * thankyou.html - the default "redirect" page. * mailer.php - the target for your forms NO EDITING REQUIRED * email.ini - where all your settings are held so what is this used for? simply put, its a fast and easy way to secure a FORM with some basic regexs (no experience required) and other stuff... how does it work? the FORM submitted to mailer.php is compared to the defined values in email.ini, and shown as such. how does it secure the form? in two ways: 1. you specify the type of content expected ( "mixed", "numbers" or "email" ), and the script checks them against this value. If it doesn't match, it isn't used. 2. the FORM only uses submitted data which has been named in the INI file. so how would I write the INI file? lets say we have this form: Full Name <input name='fname' /> Occupation <input name='job' /> Email Address <input name='email' /> Do you have a cat? <input type='radio' name='hascat' value='yes' /> Yes <input type='radio' name='hascat' value='no' /> No simple really... now the INI file: [settings] sendto = richthegeek@googlemail.com subject = Contact Form redirect = thankyou.html [fname] display = Full Name value = mixed [job] display = Their Job value = mixed [hascat] display = Has a cat? value = mixed [email] display = From value = email isfrom = true thats it... just submit the form to mailer.php and you will send a message to the "sendto" address like this: Full Name: Richard Lyon Their Job: Developer Has a cat?: no From: php_penguin@hotmail.com if you change the order in which the sections occur, the email will change to match. very simple to set up, very easy to understand... helpful? email.zip
September 18, 200719 yr This is SO useful! Many thanks, php_penguin. I'll second that Really useful information. Thanks Penguin
September 19, 200719 yr Author hi thomas.... attached an updated version, which allows "error messages" (see INI and HTML for example) The script contains 3 different regex's: - "Mixed" - allows letters, numbers, and a few standard characters - "Numbers" - allows numbers + whitespace - "Email" - allows a valid email address a possible improvement is the option to provide custom regex's (eg exactly 4 numbers). the "send to" address is stored in the INI file and is unchangeable by the user. from my testing, it seems pretty secure - and no PHP knowledge is required. email.zip
September 20, 200719 yr ah, yea. I see. the regex prevents any header injections. Nice script. I wasn't aware there was a parse_ini_file functions. (though I should have figured) /me goes to update one of his scripts...
September 20, 200719 yr Author yes, i forgot about it (the parse_ini_file() ) at the start, and wrote one myself - it is attached... parseini.php
September 20, 200719 yr Author yes, there is a built in function for reading+parsing INI files. what i meant was that at the start of writing the mailer script, I forgot that there was a built in function, and so wrote my own version - I attached it so people could see how it might be implemented.
January 4, 200818 yr This is very helpful, :-) How would i go about inserting radio buttons and getting them validated too?
January 4, 200818 yr Author hi mark, radio buttons have a value of "1" or "0" if no value is set, so you can validate against that (use "/^1/" for the regex). to add a validation you need to change the INI file, which shouldn't be too hard. Bear in mind that it is a while since I wrote this so adding the validation regex might not even work.
Create an account or sign in to comment