Support » Plugin: Admin Page Framework » Including an API call within a Form

  • Resolved edwardcox

    (@edwardcox)


    Hi. Apologies if this is a dumb question. I’m new. So, I will be using the amazing APF Plugin and I have code that needs to be called upon Form Submit which uses Fields from the Form in the process.

    So in my Form i will call below and insert Form Fields i.e. $username, $password into the API call.

    Can someone please show me how this might look in my Form?
    Thank you kindly,
    Edward

    <?php
    
    // Server credentials
    $hst_hostname = 'server.hestiacp.com';
    $hst_port = '8083';
    $hst_username = '<redacted>';
    $hst_password = '<redacted>';
    $hst_returncode = 'yes';
    $hst_command = 'v-add-user';
    
    // New Account
    $username = 'demo';
    $password = '<redacted>';
    $email = '<redacted>';
    $package = 'default';
    $first_name = 'First';
    $last_name = 'Last';
    
    // Prepare POST query
    $postvars = array(
        'user' => $hst_username,
        'password' => $hst_password,
        'returncode' => $hst_returncode,
        'cmd' => $hst_command,
        'arg1' => $username,
        'arg2' => $password,
        'arg3' => $email,
        'arg4' => $package,
        'arg5' => $first_name,
        'arg6' => $last_name
    );
    
    // Send POST query via cURL
    $postdata = http_build_query($postvars);
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, 'https://' . $hst_hostname . ':' . $hst_port . '/api/');
    curl_setopt($curl, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
    $answer = curl_exec($curl);
    
    // Check result
    if($answer === 0) {
        echo "User account has been successfuly created\n";
    } else {
        echo "Query returned error code: " .$answer. "\n";
    }
    • This topic was modified 1 month, 1 week ago by Yui. Reason: unnecessary possibly sensitive data redacted
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.