Site icon Hip-Hop Website Design and Development

WordPress and API (rapidapi) request

I need assistance with the following problem:
I would like to trigger a transaction from a wordpress page. A special, but not yet functioning page template was built for this (see next page). There are 3 input fields on the page. These are to be filled in with a text, a language selection and a selection of the translation strength. Afterwards, the transmission is to be triggered with the help of a "send button".

The entered data is to be transferred to an API, which then automatically converts this data and returns the result to the WordPress page. However, the previously entered data should remain in order to either enter/modify it again and/or to be able to check the result.

The URL where my API with the desired function is located is this one:

https://rapidapi.com/smodin/api/rewriter-paraphraser-text-changer-multi-language

I would like to use PHP cURL.

The following questions:

  1. how is the transfer done respecting the three input fields?
  2. what is the string for the transfer?
  3. what is the code for rebuilding the page so that the values previously entered can be seen, including those converted by the API?
  4. how to display my example text "This form of enterprise resembles ….." (this does not currently work)?

Thanks in advance

Ulrich


<?php
/*
Template Name: XYZ
*/

get_header();
?>

  <div id="primary" class="content-area">
    <main id="main" class="site-main">


        <form action="" method="post">
<textarea name="text" rows="14" cols="100" wrap="soft"> </textarea><br>
<text name="language"> </text><br>
<text name="strength""> </text><br>


        <input type=submit name="senden">
</form>

      <?php
$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => "https://rewriter-paraphraser-text-changer-multi-language.p.rapidapi.com/rewrite",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => "{r
    "language": "en",r
    "strength": 3,r
    "text": "Dies ist ein Test"r
}",
    CURLOPT_HTTPHEADER => [
        "content-type: application/json",
        "x-rapidapi-host: rewriter-paraphraser-text-changer-multi-language.p.rapidapi.com",
        "x-rapidapi-key: XYZ"
    ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response;
}

        $pageHTML="<h2>$response</h2>";


      ?>

    </main><!-- #main -->
  </div><!-- #primary -->

<?php
//Show the footer of the WordPress site to keep the page in context
get_footer();
?>