Wordpress Contact Form 7 pass POST vars to thanks page - php

I am trying to use Contact Form 7 to redirect the user to a new page that thanks them and offers more info once the form has successfully been filled.
How can I pass the $_POST[] vars through? I couldn't find anything on Google.
Edit:
I am also trying to use the form to pre-populate a PayPal buy it now button.

According to Contact Form 7 documentation you have to set a JavaScript action hook. By using this hook, you can specify a JavaScript code that you wish to run after the form is successfully submitted. You will find the Additional Settings field at the bottom of the contact form management page. Simply insert the following line into it:
on_sent_ok: "your javascript code;"
If you want you can use following code to redirect to a new page with variables but it will send the variables to the $_GET
on_sent_ok: "location = 'http://yourdomain.com?myVar=somevalue';"
You can retrieve the variable as follows
$myVar = $_GET['myVar'];
Read more, also check add_query_arg.

Related

Use URL parameter in Contact Form 7 Field

I would like to add some PHP in my form created with Contact Form 7, a WordPress plugin.
I've already tried this but it didn't work: Executing PHP Code in Contact Form 7 Textarea.
Every time I insert the function, my website crashes.
I have a variable stored in a $_SESSION. I have put that variable in a hidden input and now I would like to take the value of the hidden input and place it in the contact form.
How can I do this? Thanks!
Screenshot of the website and the hidden input
Screenshot of the back-end of the form
I think this approach can work for you.
Set a url param to the link. Example domain.com/more-info?previous-link=home-page
In your form add this field
[text* previous-link default:get default:post_meta "Previous link"]
You can see more examples in the docs

Can I define a variable using php outside Ninja Forms and pull it into the form? No QueryString

I want to send a form email to any one of about 75 people. This will depend on what page the user came from to get to the form page. I use URL QueryString to set that page value. An easy solution would be to put the email in the QueryString but then it is visable to the Public(User). Ninja Forms allows me to set form field to variable but I can only find the Ninja Form fields and the WP Admin variables to choose from. I can't modify those on the fly. I can pass a value through the QueryString and then use php to do a If Then to define the email. My challenge is, how do I get it into Ninja Forms. If I declared a Global Variable would Ninja Form show that on the choices of fields? Or maybe another Form plugin for WordPress would do this?
Thanks for any suggestions.

Custom wordpress Form submission

I want to insert data into database table through custom php form in wordpress. I don't want to use/create plugins/hooks. just simple form for client so he can edit himself whenever he want.
I tried
if($_POST['submit'])
{< submit to db >
} else {
< display html form ><br>
}
with action="" . this redirect to the same page without any error on page + in console. javascript validations on fields are working perfect.
I tried another solution by creating a php file in themes folder, and setting action="../that_file.php", which gave 404 error.
Any other solution?
You should use Formidable or ACF to build your form, you will lose less time for any update on your form, also, you could have a view in the dashboard to manage your user's response, that should be easier for you.
Thanks guys I found a way. I use Contact form 7 for form and CFDB plugin to save that form data to db.
I had to send confirmation email after submission so Contact form 7 did it for me.

Form check as a whole

Hello I'm trying to get back into coding and I've hit a problem that I need some help with. I've created a form with HTML5 so it has the built in required fields and i can get this to post to a database but I currently have the POST on a different page so that I can just have words saying Submit complete but currently you can just go to that submit page over and over and it will just send off blank fields to my database so I wanted to check the post as a whole to see if the whole thing is empty then not submit but I don't know if this is the best way to do it.
thanks if you need my current PHP just shout and ill put it on.
First of all validate your form fields with Javascript or Jquery validation for client side validation. Its very easy, you can use jquery validation plugin eg.
Jquery Form Validation
For Server side validation you can use php functions like isset($_POST['field_name']) and !empty($_POST['field_name'])
For PHP form validation please visit the link for reference : PHP Form Validation

How to access Ninja Forms user submitted values in WP

My client's WordPress site uses the Ninja Forms plugin for forms. There's a web page with a form that's set up to redirect to another page. I need to access the submitted form data from the redirect page, but the form values don't show up in a $_POST array on the redirect page.
Here's a Ninja Forms support page that I think provides instructions on how to achieve what I'm describing, but it's a bit over my head:
http://docs.ninjaforms.com/customer/portal/articles/1981023-processing-ninja_forms_processing
Do I need to add PHP to the form page? To the redirect page? To both?
I'd be grateful if someone who understands this page would have a look and tell me what I need to do to access the submitted form values from the redirect page.
If you want to access the values submitted/entered in the form fields on redirected page you can use [ninja_forms_all_fields].
It will out put all fields values there or if you want to show a specific field value you can use [ninja_forms_field id=93]. 93 can be the ID of any field you want to access.
If you have a template page in your theme you can write a function in your functions.php and can write what ever code you want.
To write a function there where you must have to put the global variable $ninja_forms_processing there. Then to access a field you can write the following code:
$value2 = $ninja_forms_processing->get_field_value( 152 );
In the documentation of Ninja Forms they have clearly mentioned not to use $_POST[].
It is the main function for interacting with both user submitted values and stored form data. Developers should use this instead of simply trying to access $_POST or $_REQUEST data. It has already been sanitized and values can be modified for use in other hooked functions.

Categories