I'm just setting up a small contact form, but seeing as my knowledge of PHP is all through copypasta, I need help. Everything was sending fine until I tried to set up an HTML email format... now the code just shows up in my email without any of the values filled in. In addition to fixing that, I was hoping to redirect users to a thank you page, and perhaps make the error boxes popups without reloading the entire form (Javascript?), and bring democracy to Cuba. If this is not possible, just help with the HTML thing would be much appreciated. Code:

EDIT2 : $headers = 'From: $POST['$fromname']\r\'; ... surely you meant either $POST['name'] or $fromname, not the amalgamation of both...

cpradio
—
2013-04-01T21:52:13Z —
#3

StarLion said:

EDIT2 : $headers = 'From: $POST['$fromname']\r\'; ... surely you meant either $POST['name'] or $fromname, not the amalgamation of both...

Lastly, you can't use $_POST['name'] within single quotes, nor can you use \r\ as single quotes means to output the literal character, don't parse it. You need to use double quotes and you really should put $POST['name'] within curly braces {$POST['name']}

Lumekuninganna
—
2013-04-03T17:07:29Z —
#4

Well, I really appreciate the responses. I tried to implement the changes you guys mentioned, but like the thread title says... In any case, per divine intervention and a lot of research, I put together this Frankenstein's monster of code that actually works! Everything works. It brings tears of joy to my eyes. Though I do have two questions (which I'm still poking around on the internet for the answers).

I have a drop-down menu with a blank value as its first choice. How do I get the PHP to read this as a blank value and NOT send the form when it's chosen? The field is already required, but the PHP is still reading it as a valid choice.

Out of curiosity, is there a way to make required fields optional... as in, "email OR phone" required?

For 1., if the posted value from your form is what you set your value to be for your first option in your drop down menu, then don't accept the submission.

Hmm... I guess I don't understand how to do this. I tried giving the blank selection its own name/id, with and without the <select> tag having a name. I just repeated the code I used for $robotest, which I thought would catch that specific field. So, I thought something like?

No combination of what I'm doing works. If any option on the drop-down menu is selected, it gives the pop-up error.

EDIT: Oh, it gives the error, sends the form anyway, and then goes back to the page per the history.go script. Haha.

dresden_phoenix
—
2013-04-06T04:38:46Z —
#7

What you are missing is that the form has nothing to do with PHP.

PHP may ( or may not, as you can hard code HTML) output the HTML to a for, and PHP can process the data that is return , but the behaviour of a form is in the realm of HTML. In other words, dont look for an answer to #1 in PHP

Speaking of which, your HTML is invalid. the name attribute goes in the SELECT not the option, and the OPTION holds the value.

SELECTs ( what you are calling "drop down") send values upon submission. After submission , you can USE PHP to validate the form.. and go back to the original document if any required fields are missing.

An alternative which I find less palatable, is to use javascript (if you think you are struggling now... ). You can disable the form onSumbit, so that its only triggered via a .js you would then attach to an onclick even on a form button, the onclick event would then call a script to see the value of form.location (and any other required fields you code it to check for ) is blank and and return false, if the reason I find it less palatable is because the user can turn off javascript in his/her browser and then you'd be back where you started.