Forums

Edit Form should contain dynamic data based on DB Table

mapme 21 Jan, 2011
Hi,
I need to use Chronoforms to edit existing user data.
I can build the query and I can set this up to point into an existing Chronoform for editing.

However my Chronoform is a flat structure and each time it is loaded it reverts to its original structure. This is not an issue for text fields, but is a huge problem for dropdowns and other selection form fields.

Basically, my user logs into to edit the item. I am using the UserID in the query to ensure that the user only updates his own value. The form contains a "Yes/No" checkbox. "Yes" is the default selection in the form. If a user selects "No" and saves the form then "No" will appear in the database. However if the user returns to edit this form then the default "Yes" selection will appear as there is no dynamic intelligence taking place to change the default selection to match the current database entry.

Is it possible using CC or CF to load the form with dynamic default selections to match the current saved data?

Thanks,

Brendan
GreyHead 21 Jan, 2011
Hi Brendan,

The profile plug-in has a go at adding values where appropriate. That's the easiest route. Otherwise you need to hand-code the values in the Form HTML.

Here's an example of the code to set the values of a radio array. The inputs are created from an array of $types and the data value is $d->ws_type.

foreach ( $types as $t ) {
	$checked = '';
	if ( $t->cf_id == $d->ws_type ) {
		$checked = "checked='checked'"; 
	}
	echo "<input value='".$t->cf_id."' title='' class='radio validate-one-required' id='ws_type_".$t->cf_id."' 
		name='ws_type' type='radio' $checked /><label for='ws_type_".$t->cf_id."' class='radio_label'>".$t->ws_name."</label>";
}

Bob
mapme 22 Jan, 2011
Thanks a lot Bob.
Really appreciate it.
Enjoy your travelling!
brendan
This topic is locked and no more replies can be posted.