| Post |
|
Member | sarahann posts 10 3:05 pm June 11, 2009
| |
|
|
So, I am creating a website that has various products (each a WP entry) that the user can then fill out a form to customize. The form then emails their information to the designer who handles the rest.
But, I have several different products that have different requirements for what fields I want to have in the form. Some need 5 text fields and 2 file uploads. Others need one text field and 6 file uploads, etc…
I know c-forms has the ability to dynamically create custom forms, but what is the best way to load that info? I'd like not not create unique forms for 20+ products, but use a few that are more dynamic. Can I store the info in wp custom forms, or maybe an xml file?
I know this is probably a pretty simple question, but I'd appreciate advice from others more expert than me.
(and oliver, thanks, as always for a great product. This is the second site I've deployed c-forms on, and appreciate what it offers!)
sarah
|
|
|
Admin
| Oliver Munich, Germany posts 6237 8:21 pm June 12, 2009
| |
|
|
you could probably get away with one form only and (like you pointed out) use the dynamic form feature.
see the example on the "Help!" page.
you need store the info what fields and how many with the product and when your PHP page template renders the page you need to pull that data from the product entry (e.g. custom fields) and build your form on the fly.
|
|
|
|
|
Member | sarahann posts 10 4:27 am June 13, 2009
| |
|
|
Thanks Oliver.
I'll work on coding up something this week. One other question as I decide how to make things flow…
Is it possible to put one dynamic form on a page (called from insert_custom_cform), and direct it to another dynamic form as part of a multi-page form? I'm thinking that the insert_custom_cform call and code for the first form would go in the page.php template for the particlar entry, but then where would I put the custom code for the next dynamic form in a string?
Thanks!
|
|
|
Admin
| Oliver Munich, Germany posts 6237 6:47 pm June 17, 2009
| |
|
|
Is it possible to put one dynamic form on a page (called from insert_custom_cform), and direct it to another dynamic form as part of a multi-page form? I'm thinking that the insert_custom_cform call and code for the first form would go in the page.php template for the particlar entry, but then where would I put the custom code for the next dynamic form in a string?
not sure, I've never tried, but why not?
the forms should be setup as if they were non-dynamic forms incl. the multi-form configurations.
your page template with the 'insert_custom_cform' should then have different IF clauses to check the $_SESSION array for the current form ID and dependent on that put the proper form fields array together which will be used by 'insert_custom_cform'.
note: you should not need to change the form ID that is being called by 'insert_custom_cform', cforms ought to pick up the 'next' form ID per the setting from the actual form configuration (multi-part / next form setting).
|
|
|
|
|
Member | sarahann posts 10 12:24 pm June 18, 2009
| |
|
|
Thanks Oliver. I'll try that and share my experience if I get it to work.
(and sorry for the double post.. .I saw this one was marked as "resolved," so thought it might not be reviewed again when I asked a new question.
|
|
|
Member | sarahann posts 10 5:21 am June 19, 2009
| |
|
|
Oliver,
A few questions in the right implementation of this. first off, is the session variable I need to pull for the form id "$_SESSION['cforms']['current']"?
So, if I'm understanding what you are saying, my php code on the wordpress page template would include the dynamic form fields for all of the multi-page forms I want to create, like this:
<?php if($_SESSION['cforms']['current']=3) {
(create form fields….)
}
if($_SESSION['cforms']['current']=4) {
(create form fields….)
}
insert_custom_cform($fields,3); ?>
But, if i do that, does the page ever run back through to recreate the second form? I've set up the non-dynamic forms in the wp-admin with the settings all as they should be, but it seems like I'm missing something in the php that triggers the page to re-load and run back through the code to generate subsequent forms.
I'm sure i'm missing something obvious here, but appreciate any thoughts you have.
|
|
|
Admin
| Oliver Munich, Germany posts 6237 7:30 am June 19, 2009
| |
|
|
sarahann said:
Oliver,
A few questions in the right implementation of this. first off, is the session variable I need to pull for the form id "$_SESSION['cforms']['current']"?
yes.
So, if I'm understanding what you are saying, my php code on the wordpress page template would include the dynamic form fields for all of the multi-page forms I want to create, like this:
yes
<?php if($_SESSION['cforms']['current']=3) {
(create form fields….)
}
except that your IF must use "==" instead of "="
if($_SESSION['cforms']['current']=4) {
(create form fields….)
}
insert_custom_cform($fields,3); ?>
But, if i do that, does the page ever run back through to recreate the second form?
since the form is a nonAjax form, it'll reload to display the success message, now if you configured form #3 and #4 correctly (multi-page settings!) reloading the same page will make cforms move on to the next form, and pick your dynamic fields on the fly.
I've set up the non-dynamic forms in the wp-admin with the settings all as they should be, but it seems like I'm missing something in the php that triggers the page to re-load and run back through the code to generate subsequent forms.
I'm sure i'm missing something obvious here, but appreciate any thoughts you have.
|
|
|
|
|
Member | sarahann posts 10 10:07 am June 19, 2009
| |
|
|
I'm still not able to get the reloaded page to set the next form ID as the current form. No matter how I set it up, echo $_SESSION['cforms']['current'] still shows 3 (the first form, set in "insert_custom_cform) as the current form ID.
I did try the multipage setup with a non-dynamic setup to make sure I have my multi-page setup correct there, and it works okay. But when I pull the forms in dynamically, I always get the first form field array. It submits okay, displays the user message, but then reloads the same form field.
Any more thoughts on how to move along the variable for the session's form ID?
|
|
|
Member | sarahann posts 10 10:11 am June 19, 2009
| |
|
|
Here's the code I have in my wp post template, if it helps:
<?php if ($_SESSION['cforms']['current']==3) {
$i=0; $fields['label'][$i] ='Your Name'; $fields['type'][$i] ='textfield'; $fields['isreq'][$i] ='0'; $fields['isemail'][$i]='0'; $fields['isclear'][$i++]='0';
$fields['label'][$i] ='contact number'; $fields['type'][$i] ='textfield'; $fields['isreq'][$i] ='0'; $fields['isemail'][$i]='0'; $fields['isclear'][$i++]='0';
###I'm using custom WP fields to show how many of these fields i need to capture based in that particular post's requirements $headlineNumber = get_post_meta($post->ID, 'fields_headline', true); $topLimit = $i+$headlineNumber; $boxNumber = 1;
while($i<=$topLimit) { $fields['label'][$i] ='Headline ' . $boxNumber; $fields['type'][$i] ='textfield'; $fields['isreq'][$i] ='0'; $fields['isemail'][$i]='0'; $fields['isclear'][$i]='0'; $i++; $boxNumber++; }
$textboxNumber = get_post_meta($post->ID, 'fields_text', true); $topLimit = $i+$textboxNumber; $boxNumber = 1;
while($i<=$topLimit) { $fields['label'][$i] ='Text Box ' . $boxNumber; $fields['type'][$i] ='textarea'; $fields['isreq'][$i] ='0'; $fields['isemail'][$i]='0'; $fields['isclear'][$i]='0'; $i++; $boxNumber++; }
}
if($_SESSION['cforms']['current']==4){
$i=0; $fields['label'][$i] ='Photo 1'; $fields['type'][$i] ='upload'; $fields['isreq'][$i] ='1'; $fields['isemail'][$i]='0'; $fields['isclear'][$i++]='1'; }
insert_custom_cform($fields,3);
### calling in current variable, just to see where it is echo 'current variable: '.$_SESSION['cforms']['current']; echo 'pos variable: '.$_SESSION['cforms']['pos'];
?>
|
|