Home › Forums › Quform WordPress › Create a new form from php
- This topic has 4 replies, 2 voices, and was last updated 7 years, 3 months ago by
pczjrh.
- AuthorPosts
- June 3, 2018 at 12:41 pm #25933
pczjrh
ParticipantHi,
I’m writing a plugin that depends on Quform for personal use.
Is it possible to create a form (setting ID etc) and generate fields entirely in php?
If so, are there examples anywhere?
Many thanks,
Jason.June 4, 2018 at 11:54 pm #25943pczjrh
ParticipantOK, so I found out how to duplicate a form via the export function – that code can be c’n’p into another site, or page etc.
When that form gets duplicated elsewhere it will get a unique form_id…why does this approach not work?
//dynamically find the form id by searchng for the name $forms_array = iphorm_get_all_forms(); foreach($forms_array as $f) { if ( $f['name'] == 'Form Name Here' ) { $post_process = "'iphorm_post_process_".$f['id']."'"; } } add_action( $post_process, 'my_post_process_1');
June 5, 2018 at 6:19 am #25947Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
June 6, 2018 at 12:20 am #25964pczjrh
ParticipantThanks Ally, very helpful.
To follow up.. once I’ve got the form id and defined the action hook, I’ve defined a series of constants to construct the string used in the $form->getValues() call, as such
define("id1", "'iphorm_".$f['id']."_1'");
then using this within a callback function elsewhere
$var = $form->getValue(id1);
This results is an empty value for $var…
Can you point me the right way to get the form fields dynamically?Thanks in advance,
Jason.June 6, 2018 at 12:42 am #25965pczjrh
ParticipantDoh!
define("id1", 'iphorm_'.$f['id'].'_1');
is what is needed. I thought the call required an explicit string, but apparently not.
I’ll leave the reply above for others to see if it’s helpful.
Many thanks again for your help.
Jason. - AuthorPosts
- You must be logged in to reply to this topic.