Multiple submit buttons with unique ids - asp.net-mvc-3

In my application, I am trying to create a form that has some text fields and a collection of attachments. The user will have the ability to load an existing form from the database, and edit the fields and also add/remove individual attachments from the attachment collection.
For this purpose, in my view I have a foreach loop that renders the attachment details (id, name) AND also a submit button to remove the attachment. There is also a main submit button at the bottom of the form that the user can click once they have finished editing the form.
I have followed this solution to implement multiple submit buttons in my form. However the problem I have is when the user wants to remove an attachment, I would need to pass the attachment ID as a parameter to the "RemoveAttachment" action when the user clicks the submit button next to the attachment. But as it is, the application passes the main form ID to the RemoveAttachment action. Is there a way to pass the attachment ID when the user clicks the button?
Many thanks

Using a little javascript, first add a hidden field to your form:
<input type="hidden" name="attachmentID" id="attachmentID">
Then, on each of the submit buttons:
<input type="submit" onclick="document.getElementById('attachmentID').value='#ATTACHMENT_ID'" />
Of course, you replace ATTACHMENT_ID with whatever variable contains the id.

You can make a separate <form> for each remove button, with a hidden input (or URL parameter) specifying the ID.
Beware that <form>s cannot be nested.

Related

PowerApps Portal--> After Record is created (Insert Form) show that record as Edit Form

I have a Insert form for Account Entity.
Once user create Record, I want to move to another page and show same record as Edit Form.
Does anyone have idea way to achieve this?
You should be able to redirect the user to desired page using OnSuccess of form submission.
On success: Select one of the following options:
Show success message: Requires a message to be displayed to the
user on successful submission of the form. You can also select Hide
form on success to hide the form upon successful submission.
Redirect to webpage: Redirects the user to the selected webpage
in the portal. You must select a webpage from the Redirect to webpage
list.
Redirect to URL: Redirects the user to the specified URL. You
must enter a URL in the Redirect to URL field.
Read more
Out of Box configuration helps!!!
There is a field on "Entity Form" records named "Append Record ID to Query String". This is to configure passing the id of the record to the page after form submission. This screenshot shows it in the Redirect Section in the classic interface
You can do this several ways. What I do, is use Navigate() to go to the new screen, and I pass in a context variable to the new edit screen.
Assuming you're using OnSelect() on a button to call SubmitForm(), you can do the Navigate() call via the OnSuccess() property of the form.
And within Navigate(), you just pass whatever data you need to in order for the next screen to properly bind it to the Edit Form. This is the UpdateContextRecord optional param. You'd have the Edit form take its values from a Context Variable.
Passing variables between screens has been discussed here, as well.

How can i get data from database for dropdownlist in Form in Laravel using laravel collectives?

I have used usual dropdown list and it's not worked,
when i click the submit button for all the data in the form except drop down value were sent to database.how can i fix it??
Your <select> is missing a name="foo" attribute.
A form will only submit elements with a name as part of the request.

Prevent from changing the page when there are form validation errors

I have few forms with several validation rules in a separated file named form_validation.php. One of them is an edit form that has the URL /usuario/painel/editar that receives the user id from the session, populating the form without the need to pass the id by GET, for security reasons.
The problem is that when I submit the form, the action is different, and when there are any errors, the URL changes to the action, making several errors to show when rendering the form, since the view is different and there are no id to receive.
<form action="/auto/usuario/edit/<?php echo $id_usuario; ?>" method="POST" id="editar_formulario_fisica_1" enctype="multipart/form-data">...</form>
For example: localhost:8000/auto/usuario/edit/8
Is there a way to refresh the same page and the same form, and show the errors? Or perhaps to prevent the URL from changing when there are errors?
put the id in a hidden form field
echo form_hidden('userid',$id_usuario);
then get the user id in your controller or model
$userid = $this->input->post( 'userid') ;
edit ======
yes the URL can now be the same, because you are not adding the user id to the end of it. you don't need to because the user id is being passed in a hidden form field.
the form itself is in a view file. to show the form, you are first getting the user id, then you are calling/loading the form view file. in a similar way, if the form validation fails, then you are showing the form view file again. this all happens in your controller. also if you use codeigniter form helper, and form validation, it makes showing the error messages, etc, much easier.

Dynamic list for MailChimp checkboxes

I have a newsletter sign up form on my website that presents the user with a list of checkboxes to select. The checkboxes are generated dynamically from my database. Other standards newsletter sign up fields, such as email, name, phone number, address, etc. exist in the sign up form, as well.
In MailChimp, I have created a List and have added custom fields to match my sign up form (e.g. phone number, address). I then looked at the Embedded Forms -> Naked to see the generated markup. It's easy enough to set the name attributes of the text fields on my sign up form to match those in MailChimp's.
The struggle for me now is the checkboxes. I cannot put the list of items for the checkboxes in MailChimp as they need to be dynamically generated from my database. I have added a checkbox field in MailChimp to see what name attribute it generates in hopes I could use it in my form; I see something like this:
<input id="mce-group[15757]-15757-0" name="group[15757][1]" type="checkbox" value="1">
In my sign up form, I tried something like this:
<input name="group[15757][]" type="checkbox" value="Apple">
When I signed up, "Apple" was not carried over.
How do I capture checkbox items from my signup form into MailChimp?
It looks like you're using interests -- you won't be able to pass custom values to those, as they are simply yes or no. You'd probably be better off using a merge field. Alternately, you can create the interests dynamically, but you'll need to write a script to do that, you won't be able to use the form builder directly.

Custom "Next" Buttons for Spring MVC AbstractWizardFormController

Currently, a spring application I am working on has several wizards that it is using with Spring's AbstractWizardFormController. During the early stages of development(pre-design phase), the type of "next" button did not matter.
Just to refresh, the Next and Back button are submit buttons with target attributes. So a next button on the first page of a wizard would look like the following.
<input type="submit" name="_target1" value="Next"/>
This is the standard way Spring does wizards on the view. This works fine, given that you want your Next button to be a standard HTML submit button. Otherwise, in my case, If I want a custom button, I am not sure how to do this. I know it is possible, but haven't found any documentation.
I imagine I will need to do a javascript submit, but I am not sure how to set the name of the button, of if something else needs to be done.
I just need to know how I can still extend AbstractWizardFormController, and use custom buttons.
When clicked, HTML submit button submits a form with additional parameter {name}={value}, that is _target1=Next. I guess the value doesn't matter here, controller looks at the name. So, if you want to emulate this with Javascript, you may, for example, dynamically add a hidden field with name = "_target1" before submit.

Resources