Forums

CF4 form not submitting to dbase when using custom code.

ajw3208 05 Feb, 2012
Hi Bob and Max,

Having resolved some of the basics, I'm now turning my attention to porting some of my forms from CF3 to CF4.

I have a couple of forms that grab $POST's, modify the content, and then post it to jos_content.

the attached form is the one I'm having trouble with. The CF3 version of this works fine. The CF4 version creates an entry in jos_content but none of the fields are submitted. The emails are working fine. The form is submitting into the custom code as I'm seeing the test output on the screen but the d/base commit is not working correctly

Why?

Are the events of the form in the incorrect order or is there something wrong with the custom code

Pls help as this is stopping me going live with CF4.

regards

Anthony
GreyHead 05 Feb, 2012
HIAnthony,

CFv4 uses the $form->data array for all form data and to save to the database. The $_POST array is only used to load the data into the array when the form is submitted. After that it is ignored. So this custom code
//Post to d/base
$_POST['catid'] = '94';
$_POST['sectionid'] = '4';
$_POST['state'] = '0';
$_POST['created_by_alias'] = $_POST['articleReporterName'];
$_POST['publish_up'] = $publishStartDate;
$_POST['publish_down'] = $publishEndDate;
$_POST['title'] = $articleTitle;
$_POST['publish_down'] = $publishEndDate;
$_POST['fulltext'] = $articleFullText;

needs to look like
//Post to d/base
$form->data['catid'] = '94';
$form->data['sectionid'] = '4';
$form->data['state'] = '0';
$form->data['created_by_alias'] = $_POST['articleReporterName'];
$form->data['publish_up'] = $publishStartDate;
$form->data['publish_down'] = $publishEndDate;
$form->data['title'] = $articleTitle;
$form->data['publish_down'] = $publishEndDate;
$form->data['fulltext'] = $articleFullText;


There's also a Submit Article action that might do some of this work for you.

Bob
ajw3208 05 Feb, 2012
Thanks bob,

Worked first go.

now, as you can see from the code, I am trying to capture the name of the image that is uploaded. I am allocating a variable, but it is not being passed. Why ? again, the code worked under CF3, why not CF4 and what value is returned if there is no picture/image uploaded so I can test for it.

Also, how do you set a default date in the datepciker (i.e. today's date to be used in the Article submit date?)

Thanks

Anthony
GreyHead 05 Feb, 2012
Hi Anthony,

You can set the allowEmpty:false option to force a datepicker to show today's date. See this post

For the image, add an Upload File action and drag it before the Custom Code action and that should add the image name into the $form->data array. You can see the array contents by dragging a Debugger action (or actions) into the on Submit event.

Bob
ajw3208 12 Feb, 2012
Hi Bob,

Thanks for the help on the image question. I had missed one key parameter in the event which I have resolved. The image is now being uploaded and the image name is in the array. All good so far
Just one small thing.
How do I get the image name out of the array? Apologies, as I know this is probably programming 101 but I don't code often enough to remember most of this, but just enough to be very dangerous. 🙄

As for the date picker. I didn't understand what the info was trying to tell me. In the datepicker itself, there is an option to set a default value, can this be used with a value in php date format to set today's date? If so, what's the syntax.

Thanks,

Anthony
GreyHead 13 Feb, 2012
Hi Anthony,

To get the value use $form->data['input_name'] or {input_name} depending on the context.

For the date picker settings you can probably use the DatetIme Picker config box at the bottom of the form General tab (click the form name link in the Forms Manager to open it). Here's the help text:

add Enter any extension config to the default datepicker classes loaded, this will affect all the default date fields in the form, custom ones will not be affected, e.g:
days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], startView: 'decades'


In your case add allowEmpty: false

Bob
ajw3208 18 Feb, 2012
Thanks Bob,

Both worked OK.

is there any way to set one datepicker to have a default value (i.e. todays date)?

I want the first instance to have a default and the second instance to be a required field.

Any thoughts?

-Anthony
GreyHead 18 Feb, 2012
Hi Anthony,

You an use the Custom DatePicker sction to give individual settings to a datepicker or a group of datepicker. Uuse the class settings to identify the pickers that you want to configure.

Bob
This topic is locked and no more replies can be posted.