Viteazul
Viteazul

Reputation: 181

send multiple parameters using html GET method

Im trying to send 2 arguments to my controller method from my view using GET.
I don't know exactly how to add my 2nd argument to the action URL.

Here I am sending only 1 argument.

 action="/MVC/teacher/lookspecificMessage/<?= $details['person_receive_id']; ?>" method="GET">

However, I want to add this <?= $details['related_message']; ?>

I've tried using lookspecificMessage/<?= $details['person_receive_id']; ?>&<?= $details['related_message']; ?> but it dosen't work.

Upvotes: 0

Views: 4643

Answers (2)

Bor Laze
Bor Laze

Reputation: 2516

If URL rewriting is used, url should follow declared template.

In your case it can be

action="/MVC/teacher/lookspecificMessage/$person_receive_id/$related_message"

or

action="/MVC/teacher/lookspecificMessage/$person_receive_id/lookrelaredMessage/$related_message"

or any other form.
You should check rewriting rules to find correct template for url.

Upvotes: 1

Jeremy Harris
Jeremy Harris

Reputation: 24549

Using URL rewriting, you can have parameters in the main URL structure like that. Although, typically, GET parameters are passed at the end after a question mark like so:

example.com/path/to/page?param=1

If you want more than one parameter, you use the ampersand to separate them:

example.com/path/to/page?param=1&foo=bar

In your case, it looks like your .htaccess file is doing some URL rewriting or your framework is doing some magic, which is automatically extracting the parameter and setting it in the $_GET array.

And to be clear, here is how you could do yours:

<?php

    // Get params
    $receiveId = (int) $details['person_receive_id'];
    $message = (string) $details['related_message'];

    // Build URL
    $url = "/MVC/teacher/lookspecificMessage/$receiveId?related_message=$message";

    // Encode URL (in case message has weird values)
    $url = urlencode($url);
?>

<form method="GET" action="<?php echo($url); ?>">
     <!-- REST OF FORM HERE -->
</form>

Upvotes: 0

Related Questions