I'm trying to add a "preview" button/page to my app.
Is there a way to add a different value to both my "post" and "preview" submit buttons that get passed in the params hash so that I can check which one was pressed in the controller and render the view accordingly?
Is this the best way to do this?
Value. An <input type="submit"> element's value attribute contains a string which is displayed as the button's label. Buttons do not have a true value otherwise.
You have to pass the parameter in the request. Since you are having a form, and submitting the form, you can have a hidden field in the form called, say "submitType", and populate it whenever you click the button, using javascript. Then this will be available in the next request.
Add type property with submit type="submit" to button tag this will submit the form then receive the form inputs value in php script with super global variable $_POST['input name'] or $_GET[] wdepends on from action property value by default GET.
The form will be submitted to the server and the browser will redirect away to the current address of the browser and append as query string parameters the values of the input fields.
The keys of the params
hash are just the name
value of an element.
If you had two buttons named "submit", one with value="post"
and value="preview"
, then you could do something like:
if params[:submit] == "preview"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With