LobsterBob
LobsterBob

Reputation: 1

Retrieving field data from Ninja Form

I have a wordpress website with a ninja form. In the confirmation page I would like to be able to use the values submitted in the ninja form by my users as PHP variables.

Any thoughts on how I should do this?

Let's say I use radiobuttons to ask someone if they are male or female. How do I echo the given value on the confirmation page?

Upvotes: 0

Views: 1807

Answers (2)

mindo
mindo

Reputation: 502

Ideally you should:

1) Create a new custom plugin (this way you will be able to update your Ninja Forms plugin, theme and still have you changes intact and easily transferable to other WordPress site).

2) Register a Ninja Forms Action:

public function register_actions( $actions ) {
    $actions['newsuccessmsg'] = new NF_XXX_Actions_NewSuccessMsg();
    return $actions;
}
add_filter( 'ninja_forms_register_actions', 'register_actions' );

3) Add an action class:

final class NF_XXX_Actions_NewSuccessMsg extends NF_Abstracts_Action
{
    protected $_name = 'newsuccessmsg';
    protected $_tags = array();
    protected $_timing = 'late';
    protected $_priority = 10;

    public function __construct()
    {
        parent::__construct();
    }

    public function save( $action_settings )
    {
    }

    public function process( $action_settings, $form_id, $data )
    {
        return $data;
    }
}

4) Method process will include action settings, form id and submission data. I personally just dump all details to file to see data format like this:

$f = fopen( ABSPATH . 'log.txt', 'a+' );
fwrite( $f, print_r( $data, true ) . "\n");
fclose($f);

Code snippet above will create a file log.txt in your WordPress root directory.

PS: I would recommend to refer to ninja-forms/includes/Actions/SuccessMessage.php and use it as example.

Upvotes: 1

Include_San_h
Include_San_h

Reputation: 1

You can "POST" the form data and access them by using their name attribute value

index.php

<form method = "post" action = "postValues.php">
<input type="radio" name="gender" value="male">Male
<input type="radio" name="gender" value="female">Female
<input type="submit" value="Submit"
</form>

postValues.php

<?php

/* Using the name attribute value to access the selected radio button
This should assign either male or female to the variable. */

$selectedGender = $_POST["gender"];
echo "$selectedGender";
?>

Note: The name attribute value for both the radio buttons should be same (It's like grouping together)

Upvotes: 0

Related Questions