Tepken Vannkorn
Tepken Vannkorn

Reputation: 9713

Query String in form does not work

I have the following form in my form.php file:

<form action="operation.php?part=dictionary&operation=<?php echo (($_GET['action']=='addword')?'save':'edit&id='.$_GET['id'])?>" method="get">
.....
....
</form>

And in my operation.php file:

if($_GET['operation']=='save'){
        echo "This is true";
    }else{
        die(mysql_error());
    }

And it shows the message that it does not recognize the operation parameter. So if anyone have any idea of how to distinguish the operation between save and edit would be really appreciated. Thanks you

Upvotes: 0

Views: 536

Answers (3)

TRD
TRD

Reputation: 1027

Setting a form's method to "GET" results in ignoring all GET-parameter added to the action of the form. In order to get those parameter to work you will have to add them as hidden input fields otherwise you switch your form's method to "POST". This results in setting POST-parameter according to form fields and setting GET-parameter according to the link additions made at form's action.

Upvotes: 2

Nahydrin
Nahydrin

Reputation: 13507

You need to use hidden parameters to submit values to your form, like so:

<form action="operation.php" method="GET">
    <input type="hidden" name="part" value="dictionary" />
    <input type="hidden" name="operation" value="<?php echo (($_GET['action']=='addword')?'save':'edit&id='.$_GET['id'])?>" />
</form>

Upvotes: 1

Tobias
Tobias

Reputation: 9380

You can try using:

<form action="operation.php" method="get">
    <input type="hidden" name="part" value="dictionary">
    <input type="hidden" name="operation" value="<?php echo (($_GET['action']=='addword')?'save':'edit&id='.$_GET['id'])?>">
</form>

Upvotes: 2

Related Questions