Try our conversational search powered by Generative AI!

Change XForm From Address from code MVC

Vote:
 

I am some troubles trying to change the from address on an xformpostedData object.  My action is XFormPost(XformPostedData xformPostedData)  and inside, i see that xformposteddata has a SelectedSubmit object but all the values are readonly.  This object has a Sender which is readonly as well.  Has anyone had a simliar experiance and/or a resolution to set this.  Thanks in advance.

#82574
Mar 14, 2014 15:47
Vote:
 

Just an idea, haven't tested:

protected override bool ProcessXFormAction(Controller controller, XFormPostedData xformPostedData)
{
    var copy = new NameValueCollection(controller.Request.Form);
    copy["from"] = "new sender";
    xformPostedData.SetSelectedSubmit(copy);

    // rest of body
}

    

#82606
Edited, Mar 16, 2014 19:58
Axy
Vote:
 

Hi  Joshua,

any updates about this issue? I have the same problem and I haven't manage to figure out how to do it.

Thanks

#119988
Apr 08, 2015 15:29
Vote:
 

Seems like code fragment above is not working :)

#120012
Apr 08, 2015 21:49
Axy
Vote:
 

Nope, I already tried that, it doesn't seems to work.

Aparently, everyting that is on SelectedSubmit object is read only. Would that be other way to change the sender before posting the form?

Thanks

#120017
Apr 08, 2015 21:56
Vote:
 

One hacky workaround would be to change "from=" parameter in submit action button in the form on client-side. As it turns out after model binder XFormPostedData object is readonly.

#120048
Edited, Apr 09, 2015 10:53
Axy
Vote:
 

Thanks Valdis for the reply.

Since the "from=" parameter cannot be change, do you know if is there any posibility to add to the form another parameter like "Reply To" and not to try to hack the "from=" parameter.

It will be very usefull for me !

Thanks again!

#120052
Apr 09, 2015 11:07
Vote:
 

Looking at the model binder don't think it will be available for you in action (will be ignored by xform fragment parser).

#120053
Apr 09, 2015 11:13
Axy
Vote:
 

Well, if at this point is not possible to add/update properties for the SelectedSubmit object, is there any other way to customize the form.

What I have, is a very basic form with an input field for customer email and a submit button that saves into db and sends email, witch is working now, but I want in that email to have the "Reply To" the email that customer inserts into that input field.

Do you know if that would be possible?

Thanks

#120055
Apr 09, 2015 11:22
Vote:
 

Hi, Axy,

Can you clarify a bit "I want in that email to have the "Reply To" the email that customer inserts into that input field.", it's a bit strangly formed sentence, so I am not entirely sure what you want to do?

What you could do is not use the XForm email sending. Instead, just save to the DB and put the rest of the properties that are normally on the XForm (such as sender and recipient, etc) on a block which contains the XForm (or page) and then do whatever you want on submitted action. // That is, if I understood your requirements :)

BR!

Marija

#120070
Apr 09, 2015 16:49
Axy
Vote:
 

Hi Marija,

well sorry for the wierd explanation of the situation.

The thing is that I have a simple form in a episerver block and that simple form has a input, where customer can insert his email address called "Customer Email", and a submit button that saves informations into DB and sends an email.

Now according to the form basic functionality, the sender and the receiver for that email are seted from the "Properties for button" when editing the form. What I want is to add the email address that customer inserts in the "Customer Email" input field to the sending email functionality as a "Reply to". I hope it's more clear now.

I'm not sure if something like that is handled by the xforms, as far as I saw it doesn't, but would that be any workaround for that? Or should I consider not to use xforms for that...?

Thanks

#120113
Apr 10, 2015 10:59
Vote:
 

I guess, if form shouldn't be modifed by editors - fastest workaround would be to implement just pure simple form. If editors are modifying form - you could handle sending XForm as email manually then.

#120116
Apr 10, 2015 11:11
Vote:
 

Hi Axy, 

Were you able to find a solution to this? I need to intercept the form-sending and update the recipient email address before proceeding.

I am hoping you didn't end up developing the form outside XForms.

Thanks,

Nicola

#131466
Jul 28, 2015 9:10
Axy
Vote:
 

Nicola,

I didn't manage to figure it out, so I end up developing a custom form without XForms.

If you find something, can you please can you share some ideas here..? I'm still curous if it's possible.

Thanks,

Axi :)

#131488
Jul 28, 2015 14:58
Vote:
 

I don't think you can switch out the recepient of the build in XForm send email functionality. But instead you can set the form to not send any emails and only save the data to the database. Then do this:

http://www.frederikvig.com/2009/10/sending-confirmation-email-to-the-user-when-using-episerver-xforms/

By intercepting the after post event you can code your own send Email functionality that can take whatever field value from the posted xform, e.g. the UsersEmail field.

Regards,

T

#131495
Jul 28, 2015 19:42
Vote:
 

I agreed with @Toni and in our implementation, we leave user free to create/edit form with whatever action on submit. Hooked up to XFormActionHelper.AfterSubmitPostedData and send email with your template and recepient

#131517
Jul 29, 2015 10:56
Vote:
 

Hi everyone, 

I was able to intercept the form sending by registering a handler to the event BeforeSubmitPostedData in the global.asax.

XFormActionHelper.BeforeSubmitPostedData += FormBlockController.BeforeSubmitPostedData;

And then inside the BeforeSubmitPostedData method, I had to do something like:

// Change MailFrom property
e.FormData.MailFrom = formValues.Get("EmailAddressFrom");

// Change MailTo property
e.FormData.MailTo = formValues.Get("EmailAddressTo");

However, the message body of the email could not be updated programmatically (there is no way currently as per EPiServer 8 documentation).

Our client requires a specific email body format, so I ended up removing the sending of email from the ChannelOptions and used SmtpClient to do the message sending.

Works perfectly now. Thanks for everyone's input!

Cheers,
Nicola

#131524
Edited, Jul 29, 2015 13:39
Axy
Vote:
 

Cool, looks nice.

Thanks for sharing :D

Axi :)

#131541
Jul 29, 2015 21:02
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.