View Full Version : Any PHP geeks here?
fisicx
5th March 2010, 09:14
I'm experimenting with hidden fields to solve a simple solution but it doesn't work (probalby because I'm pant's at programming).
A form has a hidden field that contains the email subject:
<input type="hidden" name="subject" value="some text string">
This gets sent to a php file that processes the form. I'm using:
$subject = $_POST['subject'];
then after validation the message gets sent:
mail("mail@domain.com", $subject , $message, "From: enquiry@domain.com");
$subject isn't getting picked up and processed. When I get the email the subject line is blank
What's missing? All the tutorials say the variables should get passed just like from a normal input but mine isn't.
fisicx
5th March 2010, 09:16
Cancel everything - found the pesky problem, a missing semi colon!
sysops
5th March 2010, 09:17
That should work fine - what is the method set on the <form>?
camweb
5th March 2010, 10:58
It's ALWAYS a semi colon. Those pesky things have caused me days of headaches.
dsigner
5th March 2010, 11:09
Well I got as far as buying the manual but you guys are not encouraging me.
fisicx
5th March 2010, 11:16
Indeed they are!
Got a new puzzle now that again should be fairly simple but I can't do it.
Suppost I want to do a calcuation on the page. The one I'm fiddling with is to add a 2% surcharge on card payments. I'd like a wee caculator thingy the where I can enter the cost of the item and click 'calculate' and the new value appears on the screen.
I can do the calculation but the results appears on a new page:
$cost = post['cost'];
echo $cost*1.02;
I'm sort of getting my head round the $_SERVER['PHP_SELF'] thing but not that comfortable yet.
Any suggestion would be most appreciated
edmondscommerce
5th March 2010, 11:26
worry about header injection with that code!
for your tax thing, just use javascript for this
NextPoint
5th March 2010, 11:27
I'm sort of getting my head round the $_SERVER['PHP_SELF'] thing but not that comfortable yet.
Don't rely on $_SERVER['PHP_SELF'] because it's not secure. Check the following:
http://www.mc2design.com/blog/php_self-safe-alternatives
fisicx
5th March 2010, 12:22
Ta muchly, didn't relalise the php_self thing was such a problem. I do however utilise a lot of validation which strips out anything iffy and there are two levels of bot blocking.
Joseph, I've had a look at JS and agree it looks much simpler. Only trouble is my JS skills are even worse than my PHP!
edmondscommerce
5th March 2010, 13:16
heh :)
ok try this: http://jsfiddle.net/Cm7cL/6/
fisicx
5th March 2010, 13:45
Thank you. I'll be at the bar in a couple of hours with a pint for you.