Jump to content

Create a front end edit form for a page with ProFields Table field


Tyssen
 Share

Recommended Posts

I have a page that contains a single ProFields table field and I want to display the contents of the table on the front end and then for logged in users, they can edit certain columns in the table.

What I have at the moment is

$out = '<form
  action="'.$page->url.'"
  method="post"
>
  <table class="table">
   <tbody>';

    $count = 1;

    foreach($page->fieldName as $row) :

      $out .= '
      <tr>
        <td><input type="checkbox" name="fieldName_'.$count.'_columnName"></td>
      </tr>';

      if($input->post->submit) :

        $page->of(false);
        $page->set('fieldName_'.$count.'_columnName', $sanitizer->text($input->post->{fieldName_'.$count.'_columnName}));
        $page->save();

      endif;

      $count++;

    endforeach;

   $out .= '
   </tbody>
  </table>
  <button class="button" type="submit">Save</button>
</form>';

The two problems I have are:

  1. I get an error trying from $sanitizer->text($input->post->{fieldName_'.$count.'_columnName}), not sure how to make that dynamic. 
  2. If I change the above to just a static value, e.g. $page->set('fieldName_1_columnName', 'Testing') and save the form, it's not saving the values to the database.

Where am I going wrong?

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...