Customize the commit button?

Is it possible to customize the commit button to have it redirect the user (in simple edit) to a certain page afterwards? Say you want them to get the "Thank you, you have been submitted" page instead of just refreshing the edit screen they are in. Is that possible to do?


I have already disseminated the commit button code but have not been able to add any extra variables in it (i.e. location.href) and have it still work. Any ideas or help would be appreciated… I figure someone has made this work already!

You would need JavaScript to do this, and I'm hopeless at JavaScript. We'll have to wait for someone else to come along. :slight_smile:

Presumably you still need the form to actually submit so the data that has just been added/edited is saved by Matrix? So unless you attempt to use Ajax to submit the form, then redirect after that, you'd have to somehow record that the page has been submitted.

Did you find a solution to this?


I'm trying to figure out best way of redirecting page when the user submits a comment.

I think Nic has done this by not actually using a Matrix-painted commit button, but rather creating his own using AJAX as Dan suggests.


Ok, I was just wondering if he had managed to customize the commit button from MSM rather then using Ajax.

No, I never did any javascript additions to the matrix commit button. A long time ago I tried, but it would always break submitting the form.

I just replaced the Matrix commit button with my own so that I never had to do a page refresh, and I use ajax to submit the form, and pull in the server response to the current page.

Hi Guys!


There is a way that you can do this without javascript using datasource assuming you are using a 3.16+ SSV version of matrix, however it is a little convoluted.



Remember that the commit button is just a button that submits the form, so we can create our own button.



Step 1:

Create your own button of type='submit', making sure to put a name attribute on the button, for this example, lets say name='clicked' and value='Go'



Step 2:

i) Create a datasource asset pointing to a database of some sort, it will not matter where, just as long as you can write SQL and execute it in that database.

ii) In the ds asset dynamic variables, create a new dynamic variable called 'ACTION'.

iii) Make it recieve an input of a get and post variable of name 'clicked' and set the default value to 'NULL'.

iv) Go into the query builder of the ds asset and change the query mode to 'edit manually'.

v) Insert the following SQL into the query textarea and commit your changes

    select true where LOWER('%%ACTION%%') = LOWER('Go') and '%%ACTION%%' <> 'NULL'

vi) Set the query builder query mode to execute



Step 3:

Create an asset listing that points to the datasource asset as a root node and lists datasource record sets. Don't worry about type formats, as we will not even be using the %asset_listing% keyword. In the results bodycopy nest in a redirect page to the page you want to go to after. Delete the default content div asset inside the no results bodycopy so that nothing will show if there are no results.



Step 4:

Nest in the asset listing to your simple edit layout. Probably best to put it at the bottom, I've not used this solution for simple edit before.



If you follow how this actually works, you probably don't need to create a new button, and you may be able to simply use the commit button that already exists in the code. I'm not too sure how simple edit works so you might not get any POST variables on a page you have just submitted to, in which case, it will not work. I have used this solution before for other form logic.



This solution can also be used to detect which type=submit button was pressed (i.e. save or cancel) and can be shortcutted to just bring out a post variable from the simple edit submit. So instead of using the button's name value you could use any of the form elements to detect when its name exists as a post variable and where its value <> 'NULL'.



BEWARE:: This solution will not work effectively if you are using <button> elements, as in IE6, the button element is submitted as a request variable upon form submit whether it is clicked or not.



Here's to my first real informative post!



Chris

Now why didn't I think of that! :lol:


Thanks Chris, I had forgotten all about this request but will give your solution a try as I have not implemented AJAX into our site.



FYI: I went ahead and implemented AJAX… it seemed easier (thanks to Nic!).