I created an website that calculates an amount of money that can be returned. Now I need to create a contact me form that will send not only users name and email in that ws put in the form, but that email also needs to contain the values that where put in the calculator inputs, by the user (currently I am holding that data in an obj). From what I read there is a way to use PHP to send emails from contact me form. But as I am new to WebDev I do not know of any way to convert data put in the calculator forms by the user (that I store in js object for lack of better way that is known to me) to text in email that can be sent back to my mailbox each time user clicks "contact me" button. Does anybody has any guidelines where I can look to find some tips for how to crack it? This is the last functionality that I need to add and as of now I am completely lost...
Any feedback is very much appreciated.
Put data in hidden inputs inside your form using javascript.
So with lack of any sample code or what you tried ill try to answer as best as i can.
Option one would be to put the entire calculator form and the contact part into a single element where on the submit it will contain all the form data and you can use php $_POST to retrieve all the input values and send out the email.
If the data is in a javascript object and your form for contact is seperate you can take the data from javascript and insert that data into a Hidden input element and use javascript to insert the data as the value for that element by ID or name. Then when you submit the contact form you will have that hidden element show up in the $_POST
Related
I have a form that the user will submit multiple values to PHP via POST.
The PHP takes the input and if the data entered is valid, it will display a second form for the user to fill out.
After the user has filled out the second form, I need to process the data that was entered in the first form again as well as the data entered in the second form.
What is the best way to access the form data from the first PHP form?
Should I put each value into its own SESSION variable and access it when I need it again later?
I just wasn't sure if this is the best/cleanest way to accomplish this task.
Thanks!
I like the idea of sticking it in the $_SESSION, but depending on your validation needs, it might be better for you to simply use client-side (javascript) validation and some conditional logic to reveal additional form fields. Then you only have one efficient post to the server with all necessary information.
I think it should go without saying, but nevertheless, once it does post to the server you want to re-validate and sanitize the data.
I have worked on very large form and it’s submitting results to mysql very well. But I want to show confirmation of the entered form data so users can update it if there are any changes required before submitting it to mysql.
What should I use to achieve this? $_POST or $_SESSION? Please let me know your suggestions.
Definitely $_POST is the choice as it will not required to store again in sessions.
Just show the confirmation, if user selects yes, then you can insert them from the $_POST variable which you already have stored.
A combination of both?
When the user submits the form, use $_POST to get the parameters and prolly some validation if you don't let javascript do it for you.
Display those parameters in another page together with the confirm button.
You can keep the input in the $_SESSION for a while and when the user confirms, send it to mysql.
You should use JAVASCRIPT validation for check validation of this form and if all fields having valid values then Submmit form via POST method.Now you will get all your fields in $_POST.
Thanks.
use POST for the non-cookie, non-javascript solution
the confirm page will have the previous form data in hidden field and the data will be submitted again with the Yes button
here is a simple sample using jquery http://jsfiddle.net/robx/QBt5L/. Not formatted for anything, but you can get an idea from it, plus as mentioned, you should also consider JQuery validation for form validating to increase error submissions in required fields.
I have a ton of data collection forms on my website, and I wrote a PHP script to handle all the data. All the forms have that one script as their action, and POST as the method. The handler emails a copy of the data to me, and I'd like for the emails I get to contain the URL of the form where they originated. Is there any way in PHP to get the url of the form which was submitted to the script? Or do I have to add an extra hidden field in every form with its URL?
Send the following variable in the email as well:
$_SERVER['HTTP_REFERER']
If you want to ensure that posts only arrive from your own form, you could put a one-time token on the form in a hidden field to validate.
I've been trying to use jQuery to grab the information from $_POST and return the user back to the actual form if their email address already exists in the system, however I can't seem to get jQuery to grab the php variable $post (which has all the information from $_POST) and spit them back to the original form. Could someone help me out please? :)
**************** EDIT ****************
So here's the basic structure.
Form: Name, Email, Address.
Submitting the form calls a php function to check if user exists in the database. If the email address is in the database, I want it to say "sorry this email already exists, click here to try again".
After clicking on the link to try again, I want the form to re-display with the fields they just typed in to display again. <- this is what I thought jQuery could do to re-post the information back to the form page..?
If the user doesn't exist, the user is saved into the database.
Does that make more sense?
From the sound of your question what you're trying to do doesn't make sense. This is because PHP is a server side language while Javascript is a client side (in the browser). This means that Javascript, and therefore jQuery, don't have access to PHP's variables ($_POST included).
There are two common ways to solve this:
Have PHP generate the form. You would output the values from $_POST, or another data location, into the form (ex., echo the variable into the input tag's value attribute). This is by far the easiest method. For example: printf('<input type="text" name="foo" value="%s"/>', $someCleanVariable);
Have the PHP generate JSON or XML, and use AJAX to get the data from the PHP script. You would have to parse out the values into the form. This is basically the same as the previous example, except it's more portable: you can have any source consume the data instead of just your form.
However, make sure that you protect your users when doing this: you need to clean the data that you're sending back to the user to make sure that there is no HTML, Javascript, or other malicious code in it. You don't want people being able to alter the look of your page by passing it data. See Cross-site Scripting Attacks.
Cheers.
Hi I'm a relative newbie.
Have a mail contact form set up with a captcha image generator.
When the captcha is verified, on submitting the form, a php page is actioned which further validates the input data (checking against spam).
Challenge: would like to retain form data in case of error in enterred capthca code and needing to return to form.
If I use a sticky form with the form sticks okay but I cannot see how I then direct http to the php script for form data validation.
So I figure the answer is a javascript function to validate the captcha and stay within the same page where the form appears, ideally just having a pop up message (alert ...) if the enterred code is wrong, before sending the http to the php script page.
I have seen that this can be done but I cannot adapt the code to the captcha I use (i.e. webspamprotect.com) Could any body suggest a generic js function useable with any captcha ?
Would be most grateful for any input.
MANY THANKS
Steve
It doesn't make sense to be able to validate the CAPTCHA with javascript on the client. If you made it possible to validate with Javascript a scammer could use the validation function to test their guesses before they sent them to the server, so they would always be able to get the answer right.
You could implement an AJAX call requesting the server to validate the attempt instead of requiring a full page refresh, but the validation must still be done on the server.
When the captcha is generated the written word is usually stored inside the session or written into a hidden input field, so it can be validated against the user supplied word, when the form is submitted back to the PHP script.
You could pass the session variable holding this to your JavaScript (or read it from the hidden input if present) when rendering the page holding the form and captcha. Then, when the user clicks submit, intercept the call and check if the entered word matches the expected word.
As for retaining the values: just add the values to your HTML form value attribute. Make sure you escape the output in case users supply malicious code.
EDIT: agreeing with everyone who says you still have to validate the input on the server side as well. Client Side validation can easily be tinkered with and is nothing but a convenience feature for users, so they can fix their input before submitting.
simply check the value of "g-recaptcha-response"
if($('#g-recaptcha-response').val()==''){
alert('captcha not ticked');
}else{
alert('captcha ticked');
}