Array to string conversion error shows when saving data from form to db.
Array to string conversion error shows when saving data from form to db.
Sorry, but I don’t understand what you are doing …
It looks like you are doing something very strange, trying to mix some third party code blindly into Yii framework.
Could you tell us the big picture of your project?
What do you want to do, and with what kind of library are you trying to do it?
the following controller code doesn’t shows the db values in form
[code]public function actionEntries( )
{
$entries_helpers_obj = new EntriesHelper();
$column_labels = array( );
$form_entries = array( );
$form_id = '';
if ( isset( $_REQUEST[ 'id' ] ) ) {
$form_id = (int) trim( $_REQUEST[ 'id' ] );
}
$user_id = Yii::$app->user->id;
$formdetail = Formdetail::findOneRow( 'form_id=:form_id and user_id =:user_id ', array(
':form_id' => $form_id,
':user_id' => $user_id
) );
if (count( $formdetail) >= 1) {
$this->layout = 'inner';
$column_labels = $entries_helpers_obj->get_column_labels($form_id);
[b] $form_entries = $entries_helpers_obj->get_entry_values($form_id, $column_labels, $entry_id='');[/b]
return $this->render('entries',[
"column_labels" => $column_labels,
"form_entries" => $form_entries ,
"form_id"=>$form_id
]);
} else {
return $this->redirect(['index/manage' ]);
}
}[code]
i have one form in that form i am getting only blank fields but values are not coming,what should i do? Below is my code and form also attached.
[code]
public function get_entry_values( $form_id, $columns, $entry_id = ‘’, $is_form_populated = false )
{
$form_values_obj = new FormValues();
$entry_sql = ( !empty( $entry_id ) ) ? "and form_entry_id ='{$entry_id}'" : '';
$form_entry_rows = FormValues::findAllRow( "form_id = '{$form_id}' {$entry_sql} Group By form_entry_id", array());
$entries = array( );
if ( count( $form_entry_rows ) > 0 ) {
foreach ( $form_entry_rows as $frm_entry ) {
$entry_id = $frm_entry->form_entry_id;
$entries[ $entry_id ] = array( );
$form_entry_values = $form_values_obj->getFormValues( $form_id, $entry_id );
$ele_index = 0;
foreach ( $columns[ 'name' ] as $key => $value ) {
$entries[ $entry_id ][ $key ][ 'entry_id' ] = $entry_id;
$element_index = explode( "_", $key );
$type = isset( $columns[ 'type' ][ $key ] ) ? $columns[ 'type' ][ $key ] : '';
if ( $type == "date" ) {
$selected_row = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key . "_datepick" );
} else if ( $type == "phone" ) {
$row1 = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key . "_1" );
$row2 = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key . "_2" );
$row3 = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key . "_3" );
$phone1 = isset( $row1[ 0 ][ 'form_values' ] ) ? $row1[ 0 ][ 'form_values' ] : '';
$phone2 = isset( $row2[ 0 ][ 'form_values' ] ) ? $row2[ 0 ][ 'form_values' ] : '';
$phone3 = isset( $row3[ 0 ][ 'form_values' ] ) ? $row3[ 0 ][ 'form_values' ] : ' ';
if ( $is_form_populated ) {
$entries[ $entry_id ][ $key . "_1" ][ 'default_value' ] = $phone1;
$entries[ $entry_id ][ $key . "_2" ][ 'default_value' ] = $phone2;
$entries[ $entry_id ][ $key . "_3" ][ 'default_value' ] = $phone3;
}
$selected_row = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key . "_1" );
} else if ( $type == "money_dollar" ) {
$row = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key . "_1" );
$row2 = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key . "_2" );
$amount = isset( $row[ 0 ][ 'form_values' ] ) ? $row[ 0 ][ 'form_values' ] : '';
$conversion_rate = isset( $row2[ 0 ][ 'form_values' ] ) ? $row2[ 0 ][ 'form_values' ] : '';
if ( $is_form_populated ) {
$entries[ $entry_id ][ $key . "_1" ][ 'default_value' ] = isset( $row[ 0 ][ 'form_values' ] ) ? $row[ 0 ][ 'form_values' ] : '';
$entries[ $entry_id ][ $key . "_2" ][ 'default_value' ] = isset( $row2[ 0 ][ 'form_values' ] ) ? $row2[ 0 ][ 'form_values' ] : '1';
}
$total = intVal( $amount ) * intVal( $conversion_rate );
} else if ( ( $type == "time_noseconds" ) || ( $type == "time_24hour_noseconds" ) || ( $type == "time_24hour" ) || ( $type == "time" ) ) {
$row1 = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key . "_1" );
$row2 = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key . "_2" );
$row3 = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key . "_3" );
$row4 = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key . "_4" );
$hrs = isset( $row1[ 0 ][ 'form_values' ] ) ? $row1[ 0 ][ 'form_values' ] : '';
$minutes = isset( $row2[ 0 ][ 'form_values' ] ) ? $row2[ 0 ][ 'form_values' ] : '';
$secs = isset( $row3[ 0 ][ 'form_values' ] ) ? $row3[ 0 ][ 'form_values' ] : '';
$meridan = isset( $row4[ 0 ][ 'form_values' ] ) ? $row4[ 0 ][ 'form_values' ] : '';
if ( $is_form_populated ) {
$entries[ $entry_id ][ $key . "_1" ][ 'default_value' ] = $hrs;
$entries[ $entry_id ][ $key . "_2" ][ 'default_value' ] = $minutes;
$entries[ $entry_id ][ $key . "_3" ][ 'default_value' ] = $secs;
$entries[ $entry_id ][ $key . "_4" ][ 'default_value' ] = $meridan;
}
$selected_row = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key . "_1" );
} else {
$selected_row = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key );
}
if ( count( $selected_row ) <= 0 ) {
$entries[ $entry_id ][ $key ][ 'value' ] = "";
$entries[ $entry_id ][ $key ][ 'type' ] = $type;
$entries[ $entry_id ][ $key ][ 'text' ] = "";
$entries[ $entry_id ][ $key ][ 'default_value' ] = "";
} else {
$device = UtilityHelper::recursive_search( $form_entry_values, 'element_id', 'user_agent' );
$selected_row = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key );
$entries[ $entry_id ][ $key ][ 'value' ] = isset( $selected_row[ 0 ][ 'form_values' ] ) ? $selected_row[ 0 ][ 'form_values' ] : '';
$entries[ $entry_id ][ $key ][ 'default_value' ] = isset( $selected_row[ 0 ][ 'form_values' ] ) ? $selected_row[ 0 ][ 'form_values' ] : '';
$entries[ $entry_id ][ $key ][ 'type' ] = $type;
if ( ( $type == "checkbox" ) || ( $type == "radio" ) || ( $type == "matrix_radio" ) || ( $type == "select" ) || ( $type == "matrix_checkbox" ) ) {
$option_val = $selected_row[ 0 ][ 'form_values' ];
if ( $type == "radio" || $type == "matrix_radio" || $type == "select" ) {
$entries[ $entry_id ][ $key ][ 'text' ] = isset( $columns[ 'option' ][ $element_index[ 1 ] ][ $option_val ] ) ? $columns[ 'option' ][ $element_index[ 1 ] ][ $option_val ] : '';
} else {
$entries[ $entry_id ][ $key ][ 'text' ] = isset( $columns[ 'option' ][ $element_index[ 1 ] ][ $element_index[ 2 ] ] ) ? $columns[ 'option' ][ $element_index[ 1 ] ][ $element_index[ 2 ] ] : '';
}
} else if ( $type == "phone" ) {
$row1 = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key . "_1" );
$row2 = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key . "_2" );
$row3 = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key . "_3" );
$phone1 = isset( $row1[ 0 ][ 'form_values' ] ) ? $row1[ 0 ][ 'form_values' ] : '';
$phone2 = isset( $row2[ 0 ][ 'form_values' ] ) ? $row2[ 0 ][ 'form_values' ] : '';
$phone3 = isset( $row3[ 0 ][ 'form_values' ] ) ? $row3[ 0 ][ 'form_values' ] : ' ';
$entries[ $entry_id ][ $key ][ 'text' ] = $phone1 . "-" . $phone2 . '-' . $phone3;
} else if ( ( $type == "time_noseconds" ) || ( $type == "time_24hour_noseconds" ) || ( $type == "time_24hour" ) || ( $type == "time" ) ) {
$row1 = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key . "_1" );
$row2 = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key . "_2" );
$row3 = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key . "_3" );
$row4 = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key . "_4" );
$hrs = isset( $row1[ 0 ][ 'form_values' ] ) ? $row1[ 0 ][ 'form_values' ] . " : " : '';
$minutes = isset( $row2[ 0 ][ 'form_values' ] ) ? $row2[ 0 ][ 'form_values' ] : '';
$secs = isset( $row3[ 0 ][ 'form_values' ] ) ? " : " . $row3[ 0 ][ 'form_values' ] . " : " : ' ';
$meridan = isset( $row4[ 0 ][ 'form_values' ] ) ? $row4[ 0 ][ 'form_values' ] : '';
$entries[ $entry_id ][ $key ][ 'text' ] = $hrs . $minutes . $secs . $meridan;
} else if ( $type == "date" ) {
$selected_row = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key . "_datepick" );
$entries[ $entry_id ][ $key ][ 'text' ] = $selected_row[ 0 ][ 'form_values' ];
$entries[ $entry_id ][ $key ][ 'default_value' ] = isset( $selected_row[ 0 ][ 'form_values' ] ) ? $selected_row[ 0 ][ 'form_values' ] : '';
} else if ( $type == "extra_date" ) {
$date = new DateTime( $selected_row[ 0 ][ 'form_values' ] );
$entries[ $entry_id ][ $key ][ 'text' ] = strVal( $date->format( 'd-m-Y' ) );
} else if ( $type == "user_agent" ) {
$selected_row = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key );
$entries[ $entry_id ][ $key ][ 'text' ] = '';
if ( isset( $selected_row[ 0 ][ 'form_values' ] ) && ( preg_match( '/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $selected_row[ 0 ][ 'form_values' ], $matches, PREG_OFFSET_CAPTURE ) ) ) {
$entries[ $entry_id ][ $key ][ 'text' ] = isset( $matches[ 0 ][ 0 ] ) ? $matches[ 0 ][ 0 ] : '';
}
} else if ( ( $type == "latitude" ) || ( $type == "longitude" ) ) {
$entries[ $entry_id ][ $key ][ 'text' ] = '';
$selected_row = UtilityHelper::recursive_search( $form_entry_values, 'element_id', $key );
if ( isset( $device[ 0 ][ 'form_values' ] ) && ( preg_match( '/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $device[ 0 ][ 'form_values' ], $matches, PREG_OFFSET_CAPTURE ) ) ) {
$entries[ $entry_id ][ $key ][ 'text' ] = ( isset( $matches[ 0 ][ 0 ] ) && ( $selected_row[ 0 ][ 'form_values' ] ) ) ? $selected_row[ 0 ][ 'form_values' ] : '';
}
} else if ( $type == "money_dollar" ) {
$entries[ $entry_id ][ $key ][ 'text' ] = $total;
} else if ( $type == "file" ) {
$file_list = explode( "|", $selected_row[ 0 ][ 'form_values' ] );
$display_list = array( );
if ( count( $file_list ) > 0 ) {
foreach ( $file_list as $formatted_list ) {
$file_display_name = explode( "#", $formatted_list );
if ( isset( $file_display_name[ 1 ] ) && ( $file_display_name != '' ) ) {
$display_list[ ] = $file_display_name[ 1 ];
}
}
}
$entries[ $entry_id ][ $key ][ 'text' ] = implode( "<br/>", $display_list );
$entries[ $entry_id ][ $key ][ 'default_value' ] = $selected_row[ 0 ][ 'form_values' ]; //implode("<br/>",$display_list);
} else {
$entries[ $entry_id ][ $key ][ 'text' ] = $selected_row[ 0 ][ 'form_values' ];
}
}
$ele_index++;
}
}
}
return $entries;
}
[code]
[color="#006400"]/* Warning from a moderator */[/color]
Please don’t start new topics with the same problem, even when you get no reply.
And please consider the following if you want to get a help from other people:
The markup for code snippet is not [code]… [code], but [code]…[/code]
No one knows exactly what you are doing, so you have to state your problem as clear as possible.
The forum is for discussion. You have to answer the questions when someone asked about your problem.
i am not getting the values from DB to my form but it prints the blank fields. The foreach loop works 12 time but last one stored in index means index overlapping. this is my problem
I have to repeat again. The way you are trying to do looks very strange to me. I don’t want to offend you, but the code you wrote looks like ignoring all the functionalities of the framework. In fact, it looks totally irrelevant to Yii. Is it from some third party library meant to be used with plain PHP?
yes,it is from some third party library.
I see. May I ask you some questions?
What is it?
Is it meant for Yii2? Or, is it for other framework or plain PHP?
Why do you want to use it? What do you expect from it?
What do you want your user to do in your page? I’d like to know the design of your page in an end user’s words.
Have you already tried to create the skeleton using Gii?
Sir i am using yii2 to do this project and the main thing is i am new to yii2. I don’t know yii. In my company they already done the project in yii and they told me to convert that to yii2. The above code i had show to was not written by me, just i am converting that to yii2. Any way now i have cleared that error. just put one “\” i have taken 3 days…and i am very thankful to you coz, you shown interest to answer my question. sorry for my bad english, Thank you.
I see.
It should be a difficult situation for you, but please spare as much time as you can in learning Yii 2.0 (and possibly Yii 1.1). I believe it will be the shortest way to accomplish your task.
Fortunately Yii 1.1 and 2.0 have very good documentation … the definitive guides. They will not take much time. In fact you could have read through them in 3 days.
“Make haste slowly”
Thanks for your suggestion.