Quantcast
Channel: Toolset » All Posts
Viewing all articles
Browse latest Browse all 20145

CRED Form to Pass Field Values to PHP Function and Display Result

$
0
0

I have a simple CRED form (id = 9718) that only requires input to one text field. On submission I would like to: (a) continue to display the form, (b) execute php code to display content below the form that is dependent on the text submitted and (c) create a custom post with

post_title

corresponding to text submitted. (a) and (c) are standard CRED features and work fine; I understand (b) requires some extra work on my part but form actions really confuse me.
At it's simplest I think/hope I should be able to make use of your fine actions and hooks API to do something like:

add_action('cred_submit_complete_9718', 'action_9718', 10, 2);
function action_9718( $form_data ) {
   echo '<p>Phrase submitted: ' . $_POST['post_title'] . '</p>';
}

There are at least two problems with this:
1.

echo

is printing to a 'waiting' screen, not the form/post; and
2.

$_POST

is apparently not available – text submitted does not print.
But I have a sense I am missing something more fundamental.
Can you help? Or perhaps this is not what CRED was designed for?
Here is the form from the CRED editor:

[credform class="cred-form cred-keep-original enterphrase"]
	[cred_field field="form_messages" value=""]
	<div class="cred-field cred-field-post_title">
                <div class="cred-label">Enter Phrase: </div>
		[cred_field field="post_title" post="phrase" value="" urlparam=""]
	</div>
	[cred_field field="form_submit" value="Submit" urlparam=""]
[/credform]

Form settings are to "Create content" and "Keep displaying this form".
As a bonus I would also like to understand how the

urlparam

option works. It would be great to have the text entered appear in the query string of the URL.
Thanks in advance for your thoughts.
Jon


Viewing all articles
Browse latest Browse all 20145

Trending Articles