How to store/save a previous set of form inputs as a 'save search' function?

You can submit the form even on click of the Save Search button.

  1. Just add another hidden field say “savingSearch”.
  2. On click of the button, first set this fields value to “1”.
  3. Then in the same click event, also configure form.submit() event.
  4. In the server action, perform both conditionally using this input.
  5. On success of the form submission, if the “savingSearch” == “1”, just reset it and show user appropriate message, else it will do what regular form submission success would do.

Got it, thanks sid, and that’s smart and would do the trick.

I’d like to try and avoid adding additional step to the main form submit server actions, however as the ratio would be something like 1,000 to 1 in terms of uses for search vs uses for save search but with this I can get it working before finding another option!

I saw you other comment in the data store topic. So indeed, why not use data store for this? Define your data store schema (i.e. 29 variables - one for each input).
You can either:

  • store the inputs values on server connect form submit
    or
  • store the inputs values on some other dynamic event like button click

Both are using the same logic. On (dynami_event_here) use insert, or if the search can be edited by the user use update or insert option:

There you can bind dynamic values to the data store variables:

Select your input > value:

So do this for all the inputs :slight_smile:

Then on the page use dynamic values for the inputs and assign the values from the data store.

How would this data store be sent to a server connect then? To save in the DB?

Why store in the db at all?

Myself, @max_gb, @Antony and @ben (and a few others) have had success.

That should get you on your way @sid

1 Like

Thanks for the links. I think I read Ben’s answer a while ago. Had forgotton. :sweat_smile:

The context in which @Teodor provided this as a solution, I was hoping there was a direct way to do this, instead of the repeat work-around.
I haven’t seen a reply from the Wappler team on this.

In context of the requirement here, it would be much much simpler to create a single hidden variable and use that in a condition on server action end.
With data store, first the user will have to create a new data store, setup the schema, then insert the values on click of the button, then setup the repeat logic that everyone has suggested, then build another server action to actually process that data and save in the DB.

Although there would be some similar steps with the solution I have suggested, but its any day simpler than Data Store in my opinion, for this context at least.

That’s what the requirement of the question is.

I got confused by his two posts the one here and the other one here:

So it was not really clear to me if he wants to store everything in a database or in a data store :slight_smile:

I think he got confused too - trying to explore the options. :sweat_smile:

But if you could please confirm - the repeat is the best approach to store data-store in a database for now?

Yes

Hey there @mgaussie

If I understand correctly, then I would just have a server action I call via GET.

So if your form is like this:

form id=mega_search
   input id=mega_search1
   input id=mega_search2
etc...

Then I’d have a server action / server connect “save_search” with $GET parameters like this:

form_field1
form_field2
etc...

Then when they click the [Save Search] button it just calls the server connect and passes in the values of:

save_search.load({form_field1: mega_search1.value, form_field2: mega_search2.value...})

Which you then save to the database in the server action.

I hope that helps!

Antony.

Hey all, thank you for all the input in this post.

@sid - I didn’t get confused at all, just looking for the right solution with limited info/documentation. I know what I need to achieve but the problem is the values aren’t passing through to the Server Connect, and i’d like to avoid the overhead included in the Server Connect with your suggestion (although your suggestion will work).

Thanks @Antony - this seems like the perfect solution, but the problem is the values just won’t pass through to the server action.

I’ve setup a new Server Action, trigger the action on button click, load the form values into the $_GET fields and then choose those new $_GET fields for the input, but it just won’t pass the values!

@Teodor - I was just exploring the Data Store as an option to solve this, I need somehow to get the form values into ‘something’ that I can then use as values in a Server Connect action, so data store seemed like a good option to temporarily hold these values to complete the action, or in advance of a user completing the action.

Hey @mgaussie

I think the problem is you need to specify the input values in the format

formname.inputname.value

1 Like

Hey @Antony - I believe I am doing that:

Form.card1_collapse1.input_currentTitle.value

I’ve even checked data on the page using dmx.app.data to ensure that the value does indeed get attached to the input, and it’s there - and uses the exact same structure - so i’m a little lost!

@Antony - got it. When using the data pickers, it was including the card1_collapse1 in the path, as the input is within the card1_collapse1. However, removing this made it work. Thank you for your help!!

@Teodor - i don’t know if this is worth looking into as a potential bug? Using the data picker - this failed, but when manually changing what the data picker creates (as above) it works.

1 Like

@Teodor - still looking at DataStore for other use cases - in your image, you show the values I can input into - no doubt you created those in the Data Store schema?

I’ve created variables in the Schema, but when I go to input - it’s empty. Is this a bug?

My schema created in the Data Store:

Available inputs when I do a Dynamic Event:

Does this look like another bug? If so - I’ll add.

The data store does not support nested structures like objects and arrays. It supports flat structure only.

1 Like

Ok, got it - thank you!

The other option would then be what Antony has suggested. One improvement on that could be that you don’t really have to set all the variables at the time of calling “LOAD” function. If you just set those GET params in the definition of the server connect, and later just call sc.load(), it will automatically bind and send all values.
But this means you will have to configure a separate server action.

I don’t think there is any other way for now, since one set of fields can only be put inside one Form.

1 Like