Tushar
Tushar

Reputation: 166

Issues in working of PHP form submit with GET data

I am working with PHP forms. The opening form tag looks like this:

<form name="adv_search_form" action="<?php echo $targetpage; ?>" method="GET">

This generated the following HTML:

<form name="adv_search_form" action="index.php?&amp;rel=common_listing&amp;module=company&amp;sort_option=&amp;search_option=&amp;show_max_row=15" method="GET">

When I submit this form, I land on a URL:

http://localhost/projectcode12may2014/ampanel/index.php?field%5B%5D=broker_name&adv_operation%5B%5D=LIKE&value%5B%5D=&query_type%5B%5D=AND&submit=Submit

But what I want is that

?field%5B%5D=broker_name&adv_operation%5B%5D=LIKE&value%5B%5D=&query_type%5B%5D=AND&submit=Submit

should be appended to the action URL on the landing page. Can anyone suggest any good method for doing this? Thanks in advance.

Upvotes: 0

Views: 75

Answers (3)

V&#225;clav Hodek
V&#225;clav Hodek

Reputation: 668

This is a normal behavior. Using GET method discard all parameters specified directly in action attribute.

Use POST method instead or move parameters from action attribute of the form to input fields with type="hidden".

Upvotes: 0

TiMESPLiNTER
TiMESPLiNTER

Reputation: 5889

That is your from data.

You have method="get" in your form tag. This means that the form data is concatinated to the URL. Use method="post" to have send form data as a POST request and keep your URI clean.

So change this line

<form name="adv_search_form" action="<?php echo $targetpage; ?>" method="GET">

to this

<form name="adv_search_form" action="<?php echo $targetpage; ?>" method="post">

Then you can access your form data in PHP with the global $_POST var which holds an array with the submitted data.

Upvotes: 0

colburton
colburton

Reputation: 4715

If you are using method="get" the parameters in action are overwritten. Only what is in the from will be transmitted.

You need to add hidden fields for all these values. For example:

<input type="hidden" name="module" value="company" />

Upvotes: 2

Related Questions