DMXzone Server Connect Support Product Page

Answered

Using Server Connect, how do you query database records from form post variables?

Asked 01 Apr 2016 23:59:36
1
has this question
01 Apr 2016 23:59:36 Steve Skinner posted:
I'm building a download application on a site that requires users to 1) indicate what files they want to download, and 2) fill out a form in order to be able to download the files they want. Both of these things happen on the same page, which lists the available downloads, each with a checkbox next to it. The checkbox field names & id's are unique (dynamic), and the values are bound to the record ID's of the available files. When the user submits the form (action = post), I want the new page to list only the files they selected with a download link.

How do you use Server Connect to query a list of only the records that were requested on the form submitted?

Replies

Replied 04 Apr 2016 09:04:29
04 Apr 2016 09:04:29 Teodor Kuduschiev replied:
Hello Steve,
Can you just specify if everything happens on the same page, or the user should be redirected to another page, after submitting the form?
Because first you say "Both of these things happen on the same page" and then you say "I want the new page to list "
Replied 04 Apr 2016 14:02:01
04 Apr 2016 14:02:01 Steve Skinner replied:
I have a form page, which posts to a download page. The form page has the fields to fill out and the list of files that can be selected. When the form is submitted to the download page, I want the files they selected to be listed with download buttons, but I don't know how to filter the list so only the files they selected are shown.
Replied 04 Apr 2016 14:45:26
04 Apr 2016 14:45:26 Teodor Kuduschiev replied:
Okay i see. So you can easily do this using the set session step.
On the form page:
1. Make sure your checkboxes have the same name, followed by: []
example: name="fileID[]"
2. Create a server action file:
- import post variables (checkboxes) from the form, under globals (multiple should be automatically selected)
- create an array under globals > session , name it for example - selectedFiles
save the action file
3. Create a step - Core Actions > Add Set Session
- use the same name here: selectedFiles
- use the checkboxes post variable as a value for this session
4. Create an executor, bind it to run on form submit and set the method to POST.
- add a Go To URL behavior, and redirect to download page, on success.

For the download page (action):
1. Create a server action file:
- create an array under globals > session , name it the same way - selectedFiles
save the action file
2. Database connection
3. Query
- select the columns you want to show
- go to Filters, select your ID column, and assign the session global array to it and use the IN condition.
4. After the query step, create a new step - core actions - remove session.
- use the same session name here - selectedFiles
5. Create your action executor on page load

that's all.
Replied 04 Apr 2016 15:00:13
04 Apr 2016 15:00:13 Steve Skinner replied:
I'm not certain of what you're describing in your step #1, but I think I understand. I'm using a prefix followed by the file ID. This is how I've built the checkbox form field within the repeat region.

<input type="checkbox" name="wpcheck{{wpID}}" id="wpcheck{{wpID}}" value="{{wpID}}">

Is this how you mean?
Replied 04 Apr 2016 15:19:35
04 Apr 2016 15:19:35 Steve Skinner replied:
I guess you must mean to use literally this in the checkbox field name: fileID[], so I'll try that.

I'm also not clear on your step #2. Do I need to first add variables under global > post and then do the global > session thing, or do I just set up the global > session? This new server connect seems very capable of many things but it is not at all intuitive to use. I appreciate the help.
Replied 04 Apr 2016 15:48:38
04 Apr 2016 15:48:38 Teodor Kuduschiev replied:
Your checkbox names must be the same, IDs should be different.

It doesn't matter if you first import the form variables or create the session ... it is just declaring them there.
Server connect is really easy to use, as you build everything fully visual in the tree, step by step
Replied 04 Apr 2016 15:51:39
04 Apr 2016 15:51:39 Steve Skinner replied:
I appreciate your input, but I'm not sure I'll be able to figure this out. There are several things I'm not sure about.

I understand server connect is really easy to use for you - since it's your product I would expect you to know it inside and out, but I'm having trouble putting it all together, and I'm no newbie to DW and server extensions.
Replied 04 Apr 2016 15:54:03
04 Apr 2016 15:54:03 Steve Skinner replied:
In your instructions, you only mentioned what to assign the checkbox form name field, you didn't say anything about the form field ID. If I use fileID[] as you instructed, by default DW assigns the ID as the same. Are you saying that the ID of the checkbox form field should be different than fileID[]?
Replied 04 Apr 2016 16:00:25
04 Apr 2016 16:00:25 Teodor Kuduschiev replied:
I don't know what is DW putting exactly but the HTML markup requires you to have different IDs for the elements on your page.
It is only the name that i mentioned, that must be the same and to contain [] ... fileID[] is just and example.
It could be "anyName[]"
Replied 04 Apr 2016 16:07:11
04 Apr 2016 16:07:11 Steve Skinner replied:
So, like this?
<input type="checkbox" name="whitepaper[]" id="whitepaper[]" value="checked">

What does the [] do?
Replied 04 Apr 2016 16:10:19
04 Apr 2016 16:10:19 Steve Skinner replied:
Maybe I should clarify.... I'm using HTML Data Bindings in my form to generate the list of available files. My form list of files is not static. I only have one checkbox field which is repeated using HTML Data Bindings. I know field names need to be unique, which is why I was binding the record ID's to end of the form field name for the checkbox. Does the [] effectively do the same thing somehow?
Replied 04 Apr 2016 16:12:41
04 Apr 2016 16:12:41 Teodor Kuduschiev replied:
No Steve,
IDs must be different, names - the same.
<input type="checkbox" name="whitepaper[]" " id="wpcheck{{wpID}}" value="{{wpID}}">

[] marks that you will use an array - [1,2,3] instead of a single value.
Replied 04 Apr 2016 16:14:53
04 Apr 2016 16:14:53 Steve Skinner replied:
Got it.

On the [] behavior... is this specific to DMXzone extensions, and how would anyone know this? Is it in your documentation somewhere or is this a coding thing that most programmers already know?
Replied 04 Apr 2016 16:18:22
04 Apr 2016 16:18:22 Steve Skinner replied:
Moving on... In creating the array, I assume I need to entered the linked field name and select the multiple checkbox, correct? (these are empty by default when creating the session array).
Replied 04 Apr 2016 16:25:42
04 Apr 2016 16:25:42 Teodor Kuduschiev replied:
Please just follow the exact steps i entered. If i didn't mention clicking anything, then it shouldn't be clicked. Just do exactly what i described in my post. Whenever you need to click on a checkbox - it will be mentioned.

[] is not our requirement, it is a coding thing that programmers already know.
Replied 04 Apr 2016 16:37:04
04 Apr 2016 16:37:04 Steve Skinner replied:
On step 3 of your download page instructions, I'm not able to select the global session I created on the other page. I just get this page when I click the bindings icon.



I followed your instructions exactly and saved my changes on the other page where the array and session stuff is created.
Replied 04 Apr 2016 16:43:57
04 Apr 2016 16:43:57 Teodor Kuduschiev replied:
For the download page (action):
1. Create a server action file:
- create an array under globals > session , name it the same way - selectedFiles
save the action file

2. Database connection
3. Query
- select the columns you want to show
- go to Filters, select your ID column, and assign the session global array to it and use the IN condition.
4. After the query step, create a new step - core actions - remove session.
- use the same session name here - selectedFiles
5. Create your action executor on page load
Replied 04 Apr 2016 16:51:30
04 Apr 2016 16:51:30 Steve Skinner replied:
I figured out what I was doing wrong at that step. I've got everything done, but not getting any results on my download page. Is there a private address I can show you my pages?
Replied 04 Apr 2016 19:34:34
04 Apr 2016 19:34:34 Teodor Kuduschiev replied:
Yes, please send the links to
Replied 04 Apr 2016 23:00:35
04 Apr 2016 23:00:35 Steve Skinner replied:
Thanks Teodor. I will. I'm going to take another shot at it from scratch and see if I get any different results. If not, I'll send you what I have to look at.

One other thing occurred to me - I'm going to need to send an email when the form submits so the client can be notified who is downloading files and which ones they selected. This is a requirement for this little piece of work. The SmartMailer extension hasn't been a very reliable one for me in the past, and I don't think it's even compatible with your server connect is it? What would you suggest - custom coding a solution or do you have a replacement for smart mailer ready?

Reply to this topic