Hello all
how i can add one more button beside the tow button on add page
i have used the following code
$(‘#btn-action’).before('<button class=“btn btn-primary ew-btn"type=“submit””>save as complete ');
if do submit on button save as complete where i should to write the code
in row_inserted i am written the code for the first button , what i meant exactly how i can write the code for row_inserted
if the submit from the button1 do this actions
and if the submit from button2 do this actions
thanks for help
You may try to add value attribute to your buttons and then check the submitted value on the server side.
highly appreciated for your response
could please write a sample code to differentiate
between the sumbit buttons
i want to user it in side row_insertedcan i use the following code?
// Row Inserting event
function Row_Inserting($rsold, &$rsnew) {
// Enter your code here
// To cancel, set return value to FALSE
$btn=$_POST['buton1'];
if($btn) {
$this->setFailureMessage("button name clicked is button1 ");
return FALSE;
}
return TRUE;
}
You may use var_dump($_POST); die(); to view the submitted values first.
i have tray this codes but it is not working
// Row Inserting event
function Row_Inserting($rsold, &$rsnew) {
// Enter your code here
// To cancel, set return value to FALSE
if( isset($_POST) ){
var_dump($_POST);
if( isset($_POST['button1 '])){
$this->setSuccessMessage("button1 is pressed");
return FALSE;
}
}
return TRUE;
}
SOHIB wrote:
if( isset($_POST['button1 '])){ // There is a trailing space
You may double check your buttons’ name attribute, or check what you see from the var_dump(). (Note that if you don’t put die() after var_dump() as suggested above, you cannot see the dump.)
this is the out put when i add die() after var_dump($_POST);
C:\wamp64\www\forders\classes\dailymonycollect.php:1075:
array (size=11)
'token' => string 'nF83i8ZTPic9dLVp5uY0xA..' (length=24)
't' => string 'dailymonycollect' (length=16)
'action' => string 'insert' (length=6)
'modal' => string '0' (length=1)
'x_date' => string '25/06/2023' (length=10)
'x_collectorname' => string 'ahmed' (length=5)
'x_city' => string 'ads' (length=3)
'x_w_area' => string 'north' (length=5)
'x_amont' => string '2222' (length=4)
'x_custom_no' => string '2' (length=1)
'x_notes' => string '' (length=0)
and here is the button which i add on client_script of add page
$(document).ready(function() {
$('#btn-action').before('<button class="btn btn-primary ew-btn"type="submit" name="button1">Calculate Total</button> ');
});
but the code is not working to get the button name which is pressed
function Row_Inserting($rsold, &$rsnew) {
// Enter your code here
// To cancel, set return value to FALSE
if(isset($_POST)){
var_dump($_POST);
$btn=$_POST['button1'];
if($btn){
$this->setSuccessMessage("button1 is pressed");
return FALSE;
}
}
return TRUE;
}
SOHIB wrote:
if do submit on button save as complete where i should to write the code
It actually depends on what is exactly did you want to achieve? From the caption of button you wrote above, it seems you want to calculate the total of something. If so, then you don’t need to add your own button.
Just include your code to calculate that total in Row_Inserting or Row_Inserted server event. It will be executed along with the built-in row inserting process that generated by PHPMaker.
Greetings
What I want to achieve is really something contrary to what is in the name of the button
What I want to achieve is how can I have more than one button on the same form
And discrimination in writing the code for each button
Inside the row_inserted eventI hope I have explained the idea exactly.Actually, I need to implement this in a special project
Please help me by writing an example of the required codethank you
If you use Ajax action, the form is submitted by jQuery’s serialize() which does not include tags. You may use the form’s event to add the button name to an hidden tag (you need to add one yourself) in the form, e.g.
$(dailymonycollectadd).on("beforesubmit", (e, args) => { // dailymonycollectadd is the add form of the table dailymonycollect
if (e.originalEvent.target.name == "button1") args.form.myHiddenTag.value = "calc";
});
Alternatively, you may simply use Api_Action server event along with Startup Script to make the connection between the event that happened in client-side (such as on click that custom button), with the server side event.