开发者

PHP/MySQL - how to combine variables from separate forms to build a query?

Please see the code in this pastebin: http://pastebin.com/5gKwb7gi

It is quite a lot of code but I think all you gurus on here will understand it!

Basically what I have just confused myself is, I had a search form, and I then created an advanced search form which is dynamic.

I just got it finished and now I am attempting to include the simple search criteria (if it is filled out) in the advanced search query but obviously these variables are never set because the simple se开发者_开发问答arch form is never submitted :S

Does anyone have any hints, tips or ideas on what to do? Not sure if I want to combine the forms or not so I would appreciate some advice and opinions.

Thanks.


If anyone reads this question and would like to know how I solved it, I used hidden inputs and some JQuery to copy the values from the simple search form to the hidden inputs like so:

<input type="hidden" name="hiddenfilename" id="hiddenfilename"/>
<input type="hidden" name="hiddenfilesize_min" id="hiddenfilesize_min"/>
<input type="hidden" name="hiddenfilesize_max" id="hiddenfilesize_max"/>
//etc

<script type="text/javascript">
$("#filename").change(copyFilename);
$("#filesize_min").change(copyFileSizeMin);
$("#filesize_max").change(copyFileSizeMax);

function copyFilename()
{
   var valueToCopy=$("#filename").val();
   $("#hiddenfilename").val(valueToCopy);
}

function copyFileSizeMin()
{
   var valueToCopy=$("#filesize_min").val();
   $("#hiddenfilesize_min").val(valueToCopy);
}

function copyFileSizeMax()
{
   var valueToCopy=$("#filesize_max").val();
   $("#hiddenfilesize_max").val(valueToCopy);
}
</script>


I will not read 600 lines of code to help you. Make the example smaller that you can express it with some words and less then 50 lines. That is always possible! Anyway, I answer from what I read here without the code.

If you want to get Data for a multipage form you have several options. You can evaluate each page of your form server side, and then just put them back where you want to have them in the second step (use hidden import tags for variables, which should not be rendered). Another choice is to put the values into a cookie and take it from there when you need it. Also you can change the structure of your form with Javascript according to the user inputs and then just send the whole thing, when he is finished (maybe per AJAX). The most basic but often also most elegant one is the first one. For learning purposes I advice that one. Combining cookies and AJAX should be the highest level and the one used most often, but also the most complicated one, because you need to learn how your server and your php code handles cookies and also how to apply Javascript correctly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜