Jump to content

Recommended Posts

Posted

Hi all,

I'm having trouble saving a table field modified programatically. I tried save() on the page but the change isn't being saved.

Here is the code:

        foreach ( $event->event_data as $ed )
          {
            // update the signup id so we don't have to look for the file again                                                                      
            if ( $signup_id != 0 )
              {
                var_dump( $ed->signup_id );
                $ed->signup_id = $signup_id;
                // $event->save( $event->event_data );                                                                                               
                $event->save();
                var_dump( $ed->signup_id );
              }

The two var_dumps() produce this output:

NULL 

int(8045148)

This tells me that the field is being set to the correct value. However, when I visit the page, the signup_id field is still NULL (that is, nothing is displayed).

$event is a page, $event->event_data is a table, and signup_id is one of the table columns.

Thanks for any help!

Julio

Posted

If you want to save a pagefield value to the database you need to set outputformatting false, otherwise the value is only valid during runtime.
http://processwire.com/api/ref/page/of/
In your case:

$event->of(false);


This should work:

$event->of(false);
foreach ( $event->event_data as $ed )
          {                                                                     
            if ( $signup_id != 0 ) $ed->signup_id = $signup_id;
          }
$event->save('event_data');

 
  • Like 2
Posted

What did work was to change the save() call to $event->save( 'event_data' ) where event_data is the name of the field (in this case a table).

Oops! I just noticed that passing the field name was suggested by Kixe! Sorry I didn't notice!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...