Update Form using the Form Generator plugin

By Twocans - February 2, 2017

Hi yea,
The form Generator plugin is all working well at creating forms, have you any idea as to when one will be able to update forms, as I don't have much use for it with only the option of inputting.

I understand you do not want to commit yourselves but even if you had a ballpark date is better than nothing.

I am aware you guys do private work but I do not want to go that direction, I just like to have an understanding as to when I can actually make use of the this great plugin.

cheers

kenny

By ross - February 2, 2017

Hi Kenny

Thanks for posting.

The current version of Form Generator supports "edit" forms already.

Keep in mind that it's an advanced feature and requires some extra work beyond the basics of the code generator.

To get started, when you are in the code generator, make sure you check off the option for "Allow editing existing records (advanced feature)".

From there, copy and paste the code as you have been and get your basic input form setup.

By default, the form is always an "add" form. Let's say your form is called "myForm.php".

To change your form into an "edit" form, you need to use this URL: "myForm.php?num=123".

Just change the number at the end to match one of your existing record numbers.

Does that make sense?

I recommend starting with just this part.  Let me know how you make out.

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By ross - February 2, 2017

Hi Kenny

Great. You've seen the options.

And what you are also finding is that hooking up Website Membership to Form Generator is going to require some manual coding.

Do you have an idea of how to set that up?

Get it as far as you can and let me know where you end up.  We can discuss it further once you get there.

Keep me up to date with how you are making out.

Thanks!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By Twocans - February 6, 2017 - edited: February 6, 2017

Thank you Ross,

I believe this is what I was needing. I left the other two commented out lines for others (and myself) in the future

// 'where' => 'createdByUserNum = '. mysql_escape($_REQUEST['num']), //filtered by whatever is passed in the url aka ?mypage.php?num=123
//'where' => "`createdByUserNum` = '222'", // filtered by what ever you enter in between the '' where the 222 is
'where' => whereRecordNumberInUrl(1). " AND createdByUserNum= '". $CURRENT_USER['num'] ."'", // filters by current user

The above filters the recordset by the current_user logged in.

If I made any error I would be more than grateful for any input.

regards

kenny

By ross - February 7, 2017

Hi Kenny

That sounds ok to me.  I don't have a complete picture of your setup so there could be adjustments possible.

Is your current setup working for you?

If everything is working, I think you can just keep moving forward.

Let me know any questions.

Thanks!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By Dave - February 7, 2017

Hi Guys, 

But when checking the "Allow editing existing records (advanced feature)"
and checking the "Require users to be logged in (requires Website Membership plugin)"
it does not give me the option of filtering by current user

If you check those options it does it automatically, you don't need to add it again.  You can see this in the generated error checking code for that on the form: 

  // ERROR/SECURITY CHECK
  $formRecord     = $FORM_RECORD_NUM ? mysql_get($FORM_TABLE, $FORM_RECORD_NUM) : [];
  $userOwnsRecord = @$formRecord['createdByUserNum'] && $formRecord['createdByUserNum'] == @$CURRENT_USER['num'];
  if      (!function_exists('fg_util_isPluginEnabled')) { die("You must activate the Form Generator plugin before you can access this page."); }
  else if ($FORM_REQUIRE_LOGIN && !@$CURRENT_USER)      { die("You must login to use this form!"); }
  else if ($_IS_ADD_FORM && !$FORM_ALLOW_ADD)           { die("Add record - access not permitted!"); }
  else if ($_IS_EDIT_FORM) {
    if      (!$FORM_ALLOW_EDIT)                         { die("Modify record - access not permitted!"); }  
    else if (!$formRecord)                              { die("Modify record - record doesn't exist!"); }  
    else if ($FORM_REQUIRE_LOGIN && !$userOwnsRecord)   { die("Modify record - you can only edit records you've created!"); }
  }

Hope that helps!  Let me know any questions.

Dave Edis - Senior Developer
interactivetools.com