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.
Related
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.
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.
I have output from a page (Uploader.php). Now i go to some other page and have a button on that page to reroute to this page (Uploader.php). I want the input of the page to be seen rather than reprocessing the page.
From what I can infer of the question you want to have a form that allows the user to upload whatever information. After they submit, you want to either show a 'review' page (for the user to confirm or deny the action to be performed), or a 'results' page to review what was performed/uploaded/input.
For easy of programming I would have two PHP files, Uploader.php and Uploader-View.php
Uploader.php would have your form and post to whatever form action script you have for processing it. The action script could then redirect to Uploader-View.php with the form values placed in the page as text, rather than as form fields.
If you wanted to re-use Uploader.php you could have some variable to determine the state of the workflow and decide whether to show form fields or variable values.
This is my first post, so be kind ; )
I'm wanting to create a multi page form with php.
The form will spread over 3 pages, each page will need to validate on the data entered into the form on the client (using jquery validation) and if javascript is disabled, on the server, where error messages need to be displayed beside the related form field.
Upon validation, the data needs to be passed to the next page in the form, preferable using session variables.
The main problem I'm having is that most validation scripts now leave the action="" as being self referring to the current page, and as such post variables cannot be passed onto a different page in the chain of forms.
I want to have a validation script that will validate, and then post to a new page upon clicking the submit button.
Thanks
Peter
You don't have to post to the next page.
You can validate the form fields on the current page, store them in a session, then use a header("location: nextPage.php"); exit(0); redirect to go to the next page.
generally, you can do something like
<form onsubmit="return validateForm();" method="post" action="/wherever">
And this will call your javascript validation form, not submitting the form if the validation form returns false.
You will also need to do server side validation, and I suggest that you store the previous forms validated results into the session, rather than re-posting them (as these wont have to then be re-validated each time!)
You should use the post redirect pattern. Post the variables to the next page (control page), If validations pass then that page does a
header("Location: /page2.php");
after saving the posted variables to the session. If the server side validation fails, then you do a header to the page1.php with the error. pThis way you can use your back button.
I reccommend this JS validator. Very easy to use and doesn't depend on the action="" parameter at all, so you can still set it to whatever you want.
I have a Drupal module page where I am populating a form with a drop-down that contains a list of available parts of a set of files that the user can upload. Once the user uploads a file of a certain type, it removes that option from the list, and when all the available files are uploaded the form will not be rendered.
The problem is that Drupal is drawing the form before it carries out the submit action, so it appears to the user that the operation didn't work until they reload the page.
What is the common way to deal with this? Setting form_state['redirect'] to go to the page doesn't seem to work.
You modify your form so that it saves some information on the state of the form. Then you add a new case to the beginning of the submit function that returns immediately if you're not done uploading all the files, and it will redraw the form.
function modulename_uploader_form(&$form_stuff=null) {
//the function that sets your form array
$stuff = (isset($form_stuff['values'])) ?
$form_stuff['storage']['done_uploading'] :
false; //if values isnt set, this is the first visit.
$form_stuff['storage']['done_uploading'] = done_uploading();
.... the rest of your form creation function.
function modulename_uploader_submit($form, &$form_stuff) {
if($form_stuff['storage']['done_uploading']) {
return;
}
... rest of the function
make sure to unset the storage variable when you're done processing the form. You can also google multi page forms in drupal.
Setting $form_state['redirect'] in your submit handler will just cause the form to reload, fresh, without the old data. It's a way of clearing out the form so that old values don't hang around as defaults.
You probably want to use $form_state['rebuild'], which gives your form-building functions an opportunity to rebuild the form's actual structure, adding more fields or removing options from other fields after the form submit handlers run.
This blog post has a rough tutorial on doing multiple-stage forms in D6, and the Drupal 5 to 6 upgrade docs on Drupal.org contain a useful overview of how $form_state works and what its various flags are for.
The problem is that Drupal is drawing the form before it carries out the submit action, so it appears to the user that the operation didn't work until they reload the page.
I cannot believe it. Are sure about that?