Plugin development not going as expected
-
Hello,
I need help with my plugin development. I created a plugin named trial_user.php and it contains this code:<html> <head> <link rel="stylesheet" href="style.css"> </head> <body> <form method="POST"> <div class="form-wrapper"> <div class="container"> <div class="field firstname"> <label for="first_name">Your first name:</label><br> <input type="text" name="first_name"> </div> <div class="field lastname"> <label for="last_name">Your last name:</label><br> <input type="text" name="last_name"> </div> <div class="field email"> <label for="email">Your email:</label><br> <input type="email" name="email"> </div> <div class="field phone_number"> <label for="phone_number">Your phone number:</label><br> <input type="tel" name="phone_number"> </div> <div class="field company_name"> <label for="company_name">Your company name:</label><br> <input type="text" name="company_name"> </div> <div class="field country_location"> <label for="country_location">Where are you from?</label><br> <input type="text" name="country_location"> </div> <div class="field country_code"> <label for="country_code">Your country code:</label><br> <input type="text" name="country_code"> </div> <div class="footer"> <div class="submit_button"> <input type="submit" id="trial_user_button" value="submit" value="Try Now"> </div> <div class="note"> <p id="trial_user_note">By clicking the "Try Now" button you agree to our Privacy Policy and Terms of Use. </p> </div> </div> </div> </div> </form> </body> </html> <?php /* * Plugin Name: Trial User Creation API * Description: This plugin uses X company trial user API to create trial user. It was created for the purpose of showing error messages when something went wrong which none of the wordpress plugins I tried to use, did. * Version: 1.1 * Requires PHP: 8.2 * Author: Fake Name */ var_dump($_SERVER['REQUEST_METHOD']); if ($_SERVER['REQUEST_METHOD'] == "POST") { $test_api_url = ""; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $email = $_POST['email']; $phone_number = $_POST['email']; $company_name = $_POST['company_name']; $country_location = $_POST['country_location']; $country_code = $_POST['country_code']; $data = [ "first_name" => "$first_name", "last_name" => "$last_name", "email" => "$email", "phone_mobile" => "$phone_number", "company_name" => "$company_name", "website" => "$country_location", "country_code" => "$country_code" ]; $curl = curl_init($test_api_url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($curl, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json' ]); $response = curl_exec($curl); curl_close($curl); echo $response . PHP_EOL; }; ?>
.form-wrapper { display: flex; align-items: center; justify-content: center; height: 600px; } .container { display: flex; flex-wrap: wrap; padding: 0 1rem; gap: 0 2rem; width: 500px } .field { display: flex; flex-direction: column; margin: 0 -1rem; width: calc(50% - 2rem); padding: 1rem; } .footer { width: 100%; }
The above one is style.css for my HTML. I activated my plugin to test it out and see what it does but it did this instead:
My goal:
1. Activate plugin
2. Go to the page I want to
3. Insert shortcode
4. HTML form is shown
5. I write data to HTML form, click submit button and it sends data to the API url.
How do I accomplish my goal?
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘Plugin development not going as expected’ is closed to new replies.