Jump to content

Running a counter script


This topic is 7357 days old. Please don't post here. Open a new topic instead.

Recommended Posts

If I have a counter script that is used to count how many times a record was chosen from a list of records, how can I make a button using CDML to run the script and display the new results while sorting the list from smallest to largest?

Basically what I want to do is have the viewer choose a from a list of general topics.

Then a list of choices is displayed for each topic.

Then by clicking on a button they get to vote for their favorite choice. The counter script tallies the voting for them.

Any help would be appreciated. Thanks in advance.

Link to comment
Share on other sites

osubuckeye,

If you want to run a script from the web just use:

<input type="hidden" name="-script" value="scriptname"/>

And to make the button trigger the script you would just have:

<input type="submit" name="-find" value="submit"/>

For the sorting from largest to smallest:

First specify the field that will be sorted:

<input type="hidden" name="-SortField" value="Field">

Then the order:

<input type="hidden" name="-SortOrder" value="descend">

So all you would do is combine all of these in a form.

Justin Grewe

Link to comment
Share on other sites

Ok I'm using the script tags. The list of choices is now displayed on the page with the Counter button next to it.

When you click on a button, the first choices gets the vote. No matter which button you click on, the first choice's voting tally changes.

The sorting works. If I go into the database and vote for different choices to change the tallies, and then go back onto the web page and refresh or vote again, then the choices change position according to number of votes.

Here is the form I'm using:

<form action="FMPro" method="post">

<input type="hidden" name="-DB" value="vote.fp5">

<input type="hidden" name="-Format" value="vote_results.htm">

<input type="hidden" name="-script" value="vote1Counter"/>

<input type="hidden" name="vote1" value="f010" size=3>

<input type="hidden" name="-SortField" value="vote1Count">

<input type="hidden" name="-SortOrder" value="descend">

<input type="submit" name="-find" value="submit"/>

</form>

I'm not sure how to make each button displayed specific to that choice. Hopefully some can assist me.

Thanks,

KT

Link to comment
Share on other sites

I'm not exactly sure how the script is working. Maybe you can give us the script. I think what you are needing is a for-each statement that will make a button for each record. This would be:

[FMP-Record]

<form>

</form>

[/FMP-Record]

And then when the user clicks the button for the corresponding record it would tally that record only. But again, I don't know how your script is set up.

Justin Grewe

Link to comment
Share on other sites

Osubuckeye,

This script is working fine for me over the web. I have in my html page:

<html>

<head>

<title>New</title>

</head>

<body>

[FMP-Record]

<form action="FMPro" method="post">

<input type="hidden" name="-DB" value="QualityEnhancementPlan.fp5">

<input type="hidden" name="-Format" value="thankyouQualityEnhancementPlan.xsl">

<input type="hidden" name="-script" value="d"/>

<input type="text" name="vote" value="[FMP-Field: vote]">

<input type="submit" name="-find" value="submit"/>

</form>

[/FMP-Record]

</body>

</html>

Where the thank you page is in xsl at the moment but that can also be an html page with cdml. So when they click on the button for the choice they want to vote for, it applies the script to that individual record.

Hope it works.

Justin Grewe

Link to comment
Share on other sites

The blind leading the blind.

Are either of you aware of the problems with running a ScriptMaker script on the web? Those problems have been widely discussed in this forum for years. You both should devote some time to reaserch this forum and read up on that.

For a solution to "count how many times a record was chosen", you should research the Sample Files forum.

Link to comment
Share on other sites

Unable,

I am aware of the scripting problems over the web and that is why I am now working with php. I am sure osubuckeye knows about these problems as well. But sometimes during the development process you might want to check to see if a FileMaker script works so that you can see the process better in your mind.

I thought these forums were for helping people, not insulting them. I don't understand why you would make such a comment unless you are trying to show people how intelligent you think you are and how unintelligent everyone else is?

If so, I don't think these forums are the right place for you. FM Forums in my opinion is about sharing knowledge among everyone in a incredible atmosphere. Even if you are a newbie, you can post in these forums and learn from your mistakes. You should not have to be a know-it-all in order to post. Are you saying that the only thing a newbie should be allowed to do in these forums is to browse the past posts? Even if there are old posts that include everything a newbie is asking now, they shouldn't be insulted, or told to search the past posts. If that was the case then all we would be seeing eventually when all the new, unique questions that could be asked were asked, would be "Go look in the sample files and you will find what you need." Why should people be turned away from help? We are experts - we should help them even if there are past posts that discuss this. They should have a quick and efficient response because that is what this forum is about.

Justin Grewe

Link to comment
Share on other sites

Hi, buckeye! I thought I had an answer for you but I couldn't finish. Here was the concept, though... In your db have a number field called "votes" and calc field "nextvote"=votes+1. Then, in your search results list, have a VOTE button next to each choice that will EDIT the value of "votes" to the value of "nextvote".

[FMP-record]

<form ....>[FMP-field:choice] ([FMP-field:votes] votes) <<VOTE BUTTON SUBMIT>> </form>

[/FMP-record]

I could not figure out how to EDIT from a SEARCH RESULTS LIST, though. I had the -recID=[FMP-CurrentRecID] in there and it showed properly but it would not work. I then looked at [FMP-link] to use a link to -edit instead of a form & button but gave up. I tried researching the posts, but did not find much. I saw Garry helped someone using JavaScript but I do not know JS and could not follow too well (but was a good read!).

I suppose one could link to a "blank" detail page or temporary "entering your vote.." page, perform the edit, and recreate the original search to restore the list (saw several posts on storing the URL to do this), but that may be more trouble than it's worth.

Good luck. Sorry, I couldn't quite get there.

--ST

(Hmm... my link to the post seems to be visible. Oh, well.)

Link to comment
Share on other sites

Steve,

When you say that you had -recID=[FMP-CurrentRecID]in there but it would not work, how did you have it in there. Did you just have on the html page -recID=[FMP-CurrentRecID], or did you have it in the form as in <input type="text" name="-recid" value="[FMP-CurrentRecID]? If you had the latter than there would be no reason why this would not work.

Justin Grewe

Link to comment
Share on other sites

Hi, Justin! I didn't think there would be a problem, either. Maybe I did something else wrong, but I don't think so, and after searching the posts it "seemed" like this was an issue with others, too. But if you can get it to work, please confirm this. I'm not so interested in knowing what I did wrong as knowing that it can be done.

<INPUT TYPE="hidden" NAME="-recID" VALUE="[FMP-CurrentRecID]">

[FMP-CurrentRecID] <!-- this one's just to display what value it was using -->

Plus, I'm at home so I'm using FMP4.0 as-is out-of-the-box with no updates installed, so it could be that. Let me know if you get a working model, though! Thanx.

--ST

Link to comment
Share on other sites

Here is what I have come up with so far. I am using scripts whether it's bad or not. Maybe there is a better way, but for now this works.

I have re-written the counter script to include a sub script, that finds and sorts.

Vote1Counter script:

SetField["vote1counter", "vote1counter+1"]

Perform Script [sub-scripts, vote1Find]

Find/Sort script:

Is a simple find and sort script.

Then on the htm page:

I use the code:

<form action="FMPro" method="post">

<input type="hidden" name="-DB" value="vote.fp5">

<input type="hidden" name="-Format" value="vote_results.htm">

<input type="hidden" name="-RecID" value="[FMP-CurrentRecID]">

<input type="hidden" name="-Script" value="fault1Counter">

<input type="hidden" name="vote1" value="f010" size=3>

<input type="submit" name="-find" value="Vote">

</form>

Link to comment
Share on other sites

Steve,

I think the reason you are not getting this to work is that you are not entering a default value for vote. You see the calc. script is vote + 1. So if you have no value in vote then when you edit the record, it wont be editing nothing because you have nothing in the vote field or the nextvote calc. field. If there is a 0 in all the records in the beggining then it will work. I have tried it out myself and it works perfectly.

Justin Grewe

Link to comment
Share on other sites

Justin...

That's great! Actually, I had pre-assigned a default value of 0 on record creation (for field "votes"), too, so it must've been somethng else or the version/non-update thing, but I'm glad to know it works, though... I worked on it for 2-3 hours trying this-and-that and reading online. I hope it comes in handy for folks. THANX !

osubuckeye...

Sounds good. The script-over-the-web thing probably isn't a big deal in your situation, anyway. I think what happens is that scripts can only execute for 1 web user at a time, so if you have another user execute the script before the previous script has finished, the 2nd execution will be ignored. Since you have a short script, what are the odds people will execute it near simultaneously? Pretty low, I'd imagine, but that depends upon your site and how often they'll be voting. If you change your mind, though, the calc-field solution Justin and I worked on should serve you well.

Link to comment
Share on other sites

osubuckeye,

Here's the whole html. The thank you page I have is just a random thank you page, this could be anything. Remember to have a default value for the vote field in filemaker. The field text in the form is the text of what the user will be voting for.

<html>

<head>

<title>New</title>

</head>

<body>

[FMP-Record]

<form action="FMPro">

<input type="hidden" name="-DB" value="QualityEnhancementPlan.fp5">

<input type="hidden" name="-Format" value="thankyouQualityEnhancementPlan.xsl">

<input type="text" name="Text" value="[FMP-Field: Text]">

<input type="hidden" name="vote" value="[FMP-Field: nextvote]">

<input type="text" name="-recid" value="[FMP-CurrentRecID]"/>

<input type="submit" name="-edit" value="submit"/>

</form>

[/FMP-Record]

</body>

</html>

Justin Grewe

Link to comment
Share on other sites

Here's a copy/paste of my test page minus a little of the formatting code like FONT. I work in Dreamweaver and although I always keep the Code Inspector up, I primarily work in the layout/WYSIWG mode. I now see what I had wrong (stupid, stupid)... I was trying to assign a value to an output... duh.

<INPUT TYPE="hidden" NAME="[FMP-field:votes]" VALUE="[FMP-field:nextvote]">

and should have had this

<INPUT TYPE="hidden" NAME="votes" VALUE="[FMP-field:nextvote]">

Sorry... my bad. I was so focussed on what I thought was wrong I made an elementary mistake. Comical now that I look at it but invisible to me as I searched for other reasons it wasn't working... Oh, well. Glad it wall worked out in the end. Thanx for the save, Justin. Good luck, osubuckeye. Perhaps I can redeem myself on the next one. wink.gif

<HTML>

<HEAD>

<TITLE>Untitled Document</TITLE>

</HEAD>

<BODY BGCOLOR="#FFFFFF" TEXT="#000000">

<P>testbase.fmp</P>

<P></P>

[FMP-record]

<FORM NAME="testform" METHOD="post" ACTION="http://localhost:8080/testbase/FMPro">

<INPUT TYPE="hidden" NAME="-db" VALUE="testbase.fmp">

<INPUT TYPE="hidden" NAME="-lay" VALUE="weblayout">

<INPUT TYPE="hidden" NAME="-format" VALUE="searchresults.html">

<INPUT TYPE="hidden" NAME="votes" VALUE="[FMP-field:nextvote]">

<INPUT TYPE="hidden" NAME="-recID" VALUE="[FMP-CurrentRecID]">

<P>[FMP-field:firstname] [FMP-field:lastname] ([FMP-field:votes] votes)

<INPUT TYPE="submit" NAME="-edit" VALUE="vote">

</P>

</FORM>

<P></P>

[/FMP-record]

</BODY>

</HTML>

P.S. I should mention that I was using the same page again for the -format page so it would come back to itself. Hmm.. I wonder if that is a problem, too. Lately, I seem to be thinking a little fuzzy, I guess... (2-3 minutes later)... OK, just checked and it works but only shows the record voted for, not the whole list. You may have to go through the trouble of storing the URL or recreating the search after all unless it's okay if they aren't taken back to the list. Sorry.

Link to comment
Share on other sites

I did'nt know you all wanted to go back to the list. After you perform any action on a record, the results will always be that record only, as if you performed a find. All you have to do to counter this is have a meta refresh redirect on the thank you page to the list page url.

Something like:

<meta http-equiv="Refresh" content="4;url=http://www.domain.com/link.html">

with the 4 being the number of seconds you want to wait in order to be redirected and the url of the list page.

Justin Grewe

Link to comment
Share on other sites

Mr. Grewe, There is a lot to running scripts on the web. It has been widely discussed. From the thread I had no way to ascertain that you or osubuckeye were aware of the problem or that there might be a solution. I am not psychic. Perhaps you should have advised osubuckeye of the problem and how to handle the solution in php.

Rather than attempt to regurgiate all that has been posted on the ScriptMaker/Web issue, I suggested where you both could find more on the issues. Like I say, I am not psychic and have no way to know what you do or don't know, and since the thread had contained no cautions of the issues, I thought I should mention them. If that offends you, well, tough beans.

Will people be turned away from help when the help requires a little effort on their part? Well if they are, then I suppose they can struggle with the problem.

When a problem has been discussed, that data is available to the interested. To the uninterested I can provide no help.

When a solution has been posted as an open source offering and refernce is made to that, the person looking for help may well take that advice. How freakin' hard can it be, after all, to search a specifically mentioned forum for a solution which has related refenences in its title? Do you think I have a responsibility beyond the reference to the free solution which I have already posted? Do you think I have an obligation to repost a free solution which already exists because someone is too freakin' lazy to look for it?

Thank you.

Link to comment
Share on other sites

Hey guys,

Easy. It was a question. If you don't want to answer it, don't. As far as the remark for looking, I did look and sometimes unless you know how to look for your answer you never seem to find it.

As far as being too freakin' lazy, I don't feel the need to address that remark, sir.

I thank everyone who helped, appreciate it.

Link to comment
Share on other sites

Unable,

I feel that I might have blown things out of proportion with my post. My post was not an attack on you or anything of the sort. It was a response to more and more posts that I find that are not as helpful as I feel they should be for FM Forums.

You say that YOU do not feel like "regurgiate" valuable information to newbies. Well, I guess I am diffrent as are many other developers out there. Even though an issue has probably been discussed recently in other posts, I LIKE to answer posts with the most helpful information that I can provide. In that way I am getting better at what I do because I am teaching it to others. How hard is it to look at others posts and say to a newbie, "Go look in the sample files, I did." This seems that you do not know anything about it or too LAZY to spend a few minutes to answer the newbies post with helpful original information.

Another thing about your post was that osbuckeye did not ask for php help, or if scripting on the web was advisable. He asked about a particular cdml syntax question. This forum is specific, thats why they are catagorized. This is a cdml forum therefore we only talk about cdml.

You do have the right to throw stuff in a post that we did not ask for. Freedom of speech right? But we have a right to respond. A point to consider though is that many of us want a pleasant experience with FM Forums and do not like to be insulted. With your comment, I felt like you were insulting me as well as many other new developers.

You also talk about responsibility. Yes, I believe you do have the responsibility to answer questions with the best of your ability. That was a responsibility that you accepted when you signed up with this forum.

Justin Grewe

Link to comment
Share on other sites

Dear osubuckeye,

Re: I did look and sometimes unless you know how to look for your answer you never seem to find it.

I guess they don't teach basic reference research at osu. I learned it in high school. Here is a search lesson:

What was it you were trying to accomplish? I read in your original post that it was to "count how many times a record was chosen". I also understood that this was a web solution, a CDML solution or a CWP solution.

So you might search the Sample Files forum to look for thread titles about "web", "CDML" or "CWP". And titles with those clues might have some additional clues about "record counts" or "record hits".

And if you are interested in the ScriptMaker issues in this forum, you might search this forum for Scriptmaker.

Link to comment
Share on other sites

This topic is 7357 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.