๐๐๐๐ผ-๐ฃ๐ผ๐ฝ๐๐น๐ฎ๐๐ฒ ๐๐๐ณ ๐๐ถ๐ฒ๐น๐ฑ๐ ๐ฉ๐ถ๐ฎ ๐๐ฃ๐
You want to fill form fields using an API. You have a field like a company number. You want the address to appear automatically.
Do not call the API from your browser. This shows your API key to everyone. People will steal your key and use your money.
Use a proxy instead. Here is the flow:
- User types in the field.
- JavaScript sends a request to WordPress.
- WordPress calls the API using your hidden key.
- WordPress sends the data back to the browser.
- JavaScript fills the other fields.
Follow these rules for a safe setup:
- Store your API key in wp-config.php.
- Use WordPress AJAX endpoints for both logged-in and guest users.
- Verify nonces to stop abuse.
- Use a debounce function. This stops the form from sending a request on every single keystroke.
- Trigger a change event after filling fields. This tells CF7 the data is there.
This keeps your keys safe and your form fast.