You can call the 'Submit' data connection in your InfoPath code-behind to submit your form to library (alternative way if you do not want to submit via InfoPath Rules).
Under SPSecurity.RunWithElevatedPrivileges you will call instantiate
DataConnection class and call Execute() method to submit the form via code.
No need to write an event receiver code to submit the form that would probably won't work in case of InfoPath Form. Simply put this logic into your InfoPath code-behind (Code Editor)
In the below code "Submit" is my Submit data connection name. You should write your Submit data connection name. If you have similarly named it as "Submit" then no need to change it.
Ensure in InfoPath Designer under Submit Options you have configured the data like this:
The code-behind logic to submit form under SPSecurity.RunWithElevatedPrivileges
public void FormEvents_Submit(object sender, SubmitEventArgs e)
{
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
// your business logic.
// any code
DataConnection spConn = DataConnections["Submit"];
spConn.Execute();
e.CancelableArgs.Cancel = false;
});
}
catch (Exception ex)
{
e.CancelableArgs.Message = "The form cannot be saved" + ex.Message;
e.CancelableArgs.Cancel = true;
}
}