-2

I'm after a little advice. Someone has asked if I can help with a form system they use. Basically at the moment a user fills out a form (large over 150 fields) when submitting it is all validated with jQuery and PHP then it shows the form on a confirmation page. At this point the user is asked to Print off the form and give it to the client. The data is not stored anywhere. I have been asked if I can adapt it to email the form and that's where I need some advice. The form at the moment is all formatted with CSS and like I said it has over 150 fields. The client wants that exact report emailed so will I need to covert every line of code for which there are 650 odd lines to php so it can be emailed? The code is a mix of HTML, JavaScript PHP Echoing values and then of course css stylesheets are attached.

I suppose what I am basically asking is there any easier / better / quicker way of emailing the whole page with values?

Thanks for your help.

Mark H
  • 589
  • 2
  • 11
  • 20
  • There isn't an "easier" way, you have to capture the POST values in PHP, build the email body and use the [mail](http://php.net/manual/en/function.mail.php) function. – Revent Aug 20 '13 at 00:44
  • possible duplicate of [PHP POST values to another page](http://stackoverflow.com/questions/18316077/php-post-values-to-another-page) – Funk Forty Niner Aug 20 '13 at 00:45
  • @Revent That's what I've been telling the OP in this question and the other question he posted, but no response. I sure hope FULL CODED responses aren't what he/she is looking to get. (I've retracted my suggestion to the OP, not worth leaving a good suggestion on here, if it's not going to be used or responded to. I hate wasting my breath/time). – Funk Forty Niner Aug 20 '13 at 00:46
  • @Fred -ii- what you first commented has helped a lot. But it looks like you have removed it now. This was to email a form not just post it like in the other post. Before it was for a confirmation all I wanted to know this time was there a simpler way that was all and no I'm perfectly happy to code away, I just learning like everyone has to. I apologise for asking. – Mark H Aug 20 '13 at 00:49
  • @MarkH So why don't you just respond and communicate then? Usually when someone gives a suggestion, you can either say "no, that's not what I was looking for", or "yes that could work but how can I make it work with my CODE"? <= to that affect. Others and I don't mind helping, but you have to work with what people suggest to you and the preverbial "what have you tried?" – Funk Forty Niner Aug 20 '13 at 00:51
  • @Fred -ii- I have responded. I always pick an answer or give feedback to my questions. I just don't do it instantly because to be honest I often ask a question late at night like now (2am in UK) and then go to sleep and wake to peoples great suggestions. I often don't get an instant response sometimes though after a few hours I do. – Mark H Aug 20 '13 at 00:55
  • @MarkH Ok. Now from what I gathered so far is that you want to email each of the 150 fields filled in a form PLUS the HTML contents codes as well? I find that a bit strange but that's none of my business. What you will have to do is capture everything using the `ob_start()` function. I can't tell you any more than what I already know, I have done it before by using someone else's code, but that's basically what you need to do, and that should get you on the right track. If I could help you any more, I would. – Funk Forty Niner Aug 20 '13 at 01:00
  • @MarkH Here is a basic example of `ob_start()` on SO http://stackoverflow.com/a/4401992/1415724 and the function itself on PHP.net => http://php.net/manual/en/function.ob-start.php and you can Google "ob_start PHP" and find some examples from there. I wish you well, *cheers.* – Funk Forty Niner Aug 20 '13 at 01:02
  • @Fred -ii- Thanks for the response. I shall go and have a read of ob_start() function and determine if it is better to try this method or just create the full email body as Revent said. I do sincerely apologise again, and will change my method of conduct when using Stack Overflow in the Future. Thanks for your help :) – Mark H Aug 20 '13 at 01:06
  • @MarkH You're welcome Mark. One thing though, about `"...650 odd lines to php"...`, I was under the impression you wanted to email the HTML/PHP codes themselves also, or did I get the wrong impression? – Funk Forty Niner Aug 20 '13 at 01:08
  • @Fred -ii- Basically the page has HTML with Divs surrounding the $_Post['value name'] to give the page structure and set it out like a paper form that you would fill in. The client wants that exact format emailed to them so I was trying to work out a way to say email the following:

    (POST Value)
    and basically do that for every field. I thought there may be a better way that re-writing all the code into a format for the PHP email function.
    – Mark H Aug 20 '13 at 01:18
  • @MarkH Ok, I have the full picture now, thanks. Well, either do what `Revent` suggested or use `ob_start()`. I have a feeling that `ob_start()` will be what you need. Try a low level test on a smaller scaled form, once you get satisfactory results, then you can make a COPY of your working code and implement it in there. It will work, you just need to start testing. – Funk Forty Niner Aug 20 '13 at 01:33
  • @Fred -ii- Yeh I shall have a go with a test form and ob_start() function in the morning and have a read of the Output Control Functions too. Then if that isn't working out right I'll manually code it as I take Revents point regarding malicious code. Thanks for your help again Fred, much appreciated. – Mark H Aug 20 '13 at 01:42
  • @MarkH You're welcome Mark. You will achieve your goal, "set that" in your mind. `$the_mind="Is a powerful thing";` ;-) – Funk Forty Niner Aug 20 '13 at 01:45

1 Answers1

0

If you want to email exactly what's on the confirmation page, then @Fred -ii-'s suggestion might work. Since you probably already have PHP code that is forming the output to the page, you could use the output buffer and get its contents prior to flushing it to the page. See PHP's Output Control Functions.

Keep in mind however that there is no sanitizing or verifying of data this way! If you get any kind of error message or invalid input data (like malicious code), then that's what will be displayed and consequently also emailed. That's why I would personally still go through the trouble of coding it myself. If they have named their input fields well, then you should be able to use a loop in PHP to go through all the POST data. At the very minimum, I would do some sort of sanity check on the POST data prior to trying to use it.

Revent
  • 2,091
  • 2
  • 18
  • 33
  • thanks for the suggestion I shall be having a look at the link you sent "Output Control Functions" and use Fred's suggestion of trying out a test form first. Failing that I shall manually code it as I understand your point regarding the malicious code that could be entered. Thanks again Revent. – Mark H Aug 20 '13 at 01:45
  • You're welcome and best of luck with your project. If you need help, contact me via my website. – Revent Aug 20 '13 at 20:07