Custom Button

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.

Custom Button

Postby Schind » Mon Jan 08, 2018 7:09 am

I have Made a button using :
// Page Data Rendering event
function Page_DataRendering(&$header) {
// Example:
$header = "<button class='btn ewButton' name='convertapp' id='convertapp' type='submit'>Convert to Application</button>";


}

what i want the button to do is take the data from the the current record and insert it into another table. the Tables are leads and applications. all the fields in the lead table are in application, there are however more fields in the application table.

any idea where to add the :

INSERT INTO `applications`(`CustomerID`, `UserID`, `AssignTO`, `Name`, `Surname`, `ID_Number`, `Address`, `Contact_number`, `Email`, `Bank`, `Salary_amount`, `Salary_Frq`, `Salary_method`, `Employer`, `Occupation`, `Employment_type`, `start_date`, `Drivers_license`, `VehicleSelect`, `credit_bureau`, `payment_explained`, `advertising_explianed`, `DebtR`, `CreditCheck`, `AppCreated`, `AppUpdated`, `LeadSource`, `DVL`, `Bank_sta`, `POA`, `ID_Copy`, `Status`) VALUES ([value-1],[value-2],[value-3],[value-4],[value-5],[value-6],[value-7],[value-8],[value-9],[value-10],[value-11],[value-12],[value-13],[value-14],[value-15],[value-16],[value-17],[value-18],[value-19],[value-20],[value-21],[value-22],[value-23],[value-24],[value-25],[value-26],[value-27],[value-28],[value-29],[value-30],[value-31],[value-32]).

and where would i get the Values varibles ? sorry still noob on phpmaker.

my general understanding would have been the form creates a varible $name and i can pull this if my button submits to a convertapp.php.
Schind
 
Posts: 7
Joined: Wed Jan 03, 2018 12:26 pm

Re: Custom Button

Postby sangnandar » Mon Jan 08, 2018 9:27 am

It depends on what Page are you using.
On List Page, you need to move the button into ListOptions_Load/Rendered() instead of Page_DataRendering(), since there are records (with s). Then you need to do row custom action.
On View/Edit Page, Page_DataRendering() is applicable for this case.
On Delete Page, you don't need this button. You better put your "INSERT INTO" inside Row_Deleting/Deleted() server event.

Here are the general ideas:
1. Since you want an onclick event, then these whole things need to be done on client side.
2. Pass your field values to client side, using ew_SetClientVar() function inside Page_Render() server event, that is:
Page_Render()
ew_SetClientVar("yourVarName", $this->(fieldname)->CurrentValue); // for each fields.
3. Wrap these values inside ajax call when onclick event is fired, that is:
$('#convertapp').onclick(function(){
// call Ajax with these values namely ewVar.yourVarName
});
4. This ajax will be "received" by Page_Load() server event, there you put your "INSERT INTO".

You can find reference about Ajax in help file: Lookup Table -> Ajax by Server Events and/or Client Scripts
sangnandar
 
Posts: 283
Joined: Mon Sep 19, 2016 2:04 am

Re: Custom Button

Postby sangnandar » Mon Jan 08, 2018 10:06 am

You can do this directly inside Page_Load()
if (@$_POST["myajax"] == ... && @$_POST["value"] != "") { // see Example 4, Lookup Table -> Ajax by Server Events and/or Client Scripts
$values = ew_ExecuteRow("select * from move_from_table where id=".$_POST["value"]); // fetch values.
ew_Execute("INSERT INTO move_into_table .... "); // insert values, the corresponding field value variable is $values["(fieldname)"]
}
sangnandar
 
Posts: 283
Joined: Mon Sep 19, 2016 2:04 am

Re: Custom Button

Postby Schind » Mon Jan 08, 2018 1:05 pm

Hi im getting lost with this, every time i follow the code the edit page becomes unavailable. could you be more specific on how i need to add the code?
Schind
 
Posts: 7
Joined: Wed Jan 03, 2018 12:26 pm

Re: Custom Button

Postby sangnandar » Mon Jan 08, 2018 1:52 pm

Please post your code for discussion.
Also you need to explain "unavailable" ? Does the browser throw error (press F-12) ?
sangnandar
 
Posts: 283
Joined: Mon Sep 19, 2016 2:04 am


Return to General Discussion (PHPMaker)