Custom Action on View page

I would like to perform a Custom Action just like on List Page
on the view page also.
View → PageLoad
echo “

<a class="btn btn-primary" href="#" onclick="return ew.submitAction(event, {action: ‘start’, method: ‘post’, msg: ‘Do you want to Start?’, key : ‘new’});"> Start
”;How to pass the View records values in the key
and
how can I run my code if the action is “start”.I have just put the following code in the View Page Load as
if(IsPost() && Post(“useraction”) == “start”){
//my code here
}
Is this the correct way to perform and how can I get the key value pass from the link.

Since there is only one record in the View page, you may simply post back to the page with URL Parameter (e.g. action=start) and then check it in Page_Load server event and do what you want.

singh wrote:

echo “

<a class="btn btn-primary" href="#" onclick="return ew.submitAction(event, {action: ‘start’, method: ‘post’, msg: ‘Do you want to Start?’, key : ‘new’});"> Start
”;

From this I can Pass the useraction=start and also on the view page load I can access the data as
if(IsPost() && Post(“useraction”) == “start”){
}Here I need to pass one more value which is not the Primary Key and not included in the view records.
type=5how do I pass this value type=5 from the
echo “

<a class="btn btn-primary" href="#"onclick="return ew.submitAction(event, {action: ‘start’, method: ‘post’, msg: ‘Do you want to Start?’, key : ‘new’});"> Start
”;and want to access it on PageLoad of View Page.

You may see in more detail regarding ew.submitAction from ew.js template file:

/**
   * Submit action
   *
   * @param {Event} e
   * @param {Object} args - Arguments
   * @param {HTMLElement} args.f - HTML form (default is the form of the source element)
   * @param {string} args.url - URL to which the request is sent (default is current page)
   * @param {Object} args.key - Key as object (for single record only)
   * @param {string} args.msg - Confirm message
   * @param {string} args.action - Custom action name
   * @param {string} args.select - "single"|"s" (single record) or "multiple"|"m" (multiple records, default)
   * @param {string} args.method - "ajax"|"a" (Ajax by HTTP POST) or "post"|"p" (HTTP POST, default)
   * @param {Object} args.data - Object of user data that is sent to the server
   * @param {string|callback|Object} success - Function to be called if the request succeeds, or settings for jQuery.ajax() (for Ajax only)
   * @returns
   */

  function submitAction(e, args) {
      ...
  }

Thanks, now I can pass the data by add the data key.On the view page below the view table I have made a design to display some data which is not related to the view records.
So I use the pageDataRendered for and pass the data to the footer variable as

public function pageDataRendered(&$footer)
    {
        // Example:
        //$footer = "your footer";
        $userlist = ---------------------------- // my codes to displays are here
        $userlist .= "<div class='col-2'>";
    	$userlist .= "<a href='#' onclick=\"return ew.submitAction(event, {action: 'ticketcancel', method: 'post', msg: 'Do you want to Cancel the Ticket?', key : 'new', data: {type:&quot;5&quot;}});\"><i class='fa fa-times-circle text-danger'></i></a>";
    	$userlist .= "</div>";
    	$footer = $userlist;
    }

Here when I click the icon to execute the ew.submitAction
I got a error on console as -
Uncaught (in promise) TypeError: Cannot read property ‘createDocumentFragment’ of undefinedSo, I put the $userlist = “”; at the beginning and the $userlist = “”; at the end
and try again
Now their is no error and command is executed but the data are not passing as $_POST
it is passing as $_GET and url has been added as ?useraction=ticketcancel&type=5I have put the method to post and how can I pass the data as post.

If you have included your own form, then you should add the textbox by using input type = hidden including its value inside that form tags.

Now their is no error and command is executed but the data are not passing as > $_POST > it is passing as > $_GET > and url has been added as ?useraction=ticketcancel&type=5

still the useraction is also not going on POST

Because in that case, your code will be executed as useraction, which will be loaded again in Page_Load server event.You may then get the value in Page_Load server event from that URL in order to execute your own business logic (perhaps by saving it into the database).

singh wrote:

I put the > $userlist = “”; > at the beginning and the > $userlist = “”; > at the end…

I assume you meant you use a HTML form to enclose your button. Note that if you pass method: ‘post’ as argument, that means the function will use the form to submit (because the function is designed to be used in List page to submit selected records, in the List page there is a form to be submitted by POST), so if you want to use POST, you should add method=“post” to your form.

When I put the I got an error as

400
Bad Request
The server cannot or will not process the request due to an apparent client error.

https://discourse.hkvstore.com/t/invalid-post-request/4084/1