its just like any other input from a user. Validate it. Then send it thru, but you haven't shown any of the logic for the api. I assume you have that part figured out?
Jan 17, 2023
3
Level 3
Passing form values to external API
I need to pass a value ($cust_id) that a user enters into a form to an http request of an external API.
This is my controller. Because I have no $cust_id value set the API defualts to my customer ID.
public function member_Yearly()
{
//@param integer ['cust_id'] Defaults to the authenticated member.
//@return mixed
$yearly = $this->service->stats->member_yearly();
dd($yearly);
}
This is my very basic form
<form action="#" method="POST">
@csrf
<div class="mb-6 max-w-md">
<label for="search" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Your
Customer ID</label>
<input type="custid" id="custid"
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" required>
</div>
<button type="submit"
class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm w-full sm:w-auto px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800">Submit</button>
</form>
Can someone explain the best or preferred method to do this? Thanks in advance.
Level 11
Just use the custid from request and pass into your api client, something like:
public function member_Yearly(Request $request)
{
$yearly = $this->service->stats->member_yearly($request->input('custid'));
dd($yearly);
}
And change your input type to text add name on your input so its passed on request to your controller:
<input type="text" id="custid" name="custid" ... />
1 like
Please or to participate in this conversation.