mmarquiscreative / agx-hearing-test

MIT License
1 stars 0 forks source link

Adding Email functionality #3

Open mmarquiscreative opened 6 years ago

mmarquiscreative commented 6 years ago

Hey @see8ch, from your last message: Email: Sounds good!

Database Dump: This was the method I suggested above. The database submission can be skipped entirely and the emails to the user and admin would still be sent (You can read more about that here: https://ninjaforms.com/ninja-forms-feature-spotlight-save-action/).

Error: If the email to the user did not send, then the admin notification would not send either. The database of submissions is the catch all solution unfortunately. The closest error message we would get if the emails did not go through would be in the server error logs. This is highly unlikely though as it would have to be something server wide that would bring down the email server and the other sites would also notice an outage.

Submission Method: Ninja Forms allows for AJAX submissions or PHP (page reload). When you embed a test form, make sure to check AJAX and debug with that method first since it would be a better user experience from within a popup.

Misc: Some questions from above that got skipped:

Are any of the sites that will have this plugin be on a host besides WPE? How many sites total?

----- Answers -----

Any non WPE sites? Nope, looks like they all are WPE.

AJAX vs PHP: David and I both think the AJAX thing, though we would need you to build it in there (as we don't know how to)

If this all looks good, and you have what you need to start with the email functionality then let's go ahead and start actually building that out.

see8ch commented 6 years ago

This is the embed code for the form that you'll need to add to the template you want. I kept getting 500 and JS errors on the results and exit templates and wasn't able to view them, so I couldn't really tell where it should go.

<?php echo do_shortcode('[ninja_form id=1]'); ?>

It would be great if the form id (1 in this case) was a variable linked to a plugin settings page. It would just need to have that one option so the user could update it in case the form id is different on another site/environment. You can read about how to add that page here: https://developer.wordpress.org/plugins/settings/custom-settings-page/

The form has an email input field and submit button along with a few hidden fields for the test results. Below is the js that you'll need to set the hidden test result fields. You will probably need to adjust a few things (especially the actual value variables) to make it work within your angular framework, but it shows what values should be set to which class.

$('.nf-quiz-message').val( resultsCopy() );
$('.nf-hearing-results').val( results.quizScore.percentScore );
$('.nf-tone-results').val( results.toneScore.percentScore );
$('.nf-speech-results').val( results.speechScore.percentScore );

The hidden fields all have a class of nf-hidden and the CSS to hide them is below.

/* ---------  Ninja Forms Styles --------- */
.nf-hidden { display: none !important !important; }

Questions

Also, can you have Austin ping me or you can message me in Slack if you don't hear back on quick enough. I don't get any notifications for this repo so I sometimes don't catch your updates.

mmarquiscreative commented 6 years ago

Hey @see8ch we're running into some potential issues with trying to run shortcode from within an angularJS template. Is this what you mentioned before about maybe needing to use AJAX? If so, do you have an idea of what we need to add and where to help load the form in the right place/step?

mmarquiscreative commented 6 years ago

Sorry, to clarify, the shortcode calling the ninja form.

mmarquiscreative commented 6 years ago

I'm also wondering if part of the issue is that the shortcode, if used in the template, would be read as if it were on an HTML page instead of PHP?

see8ch commented 6 years ago

The form submission via AJAX is separate from the form display itself. I would reach out to Ninja Forms support and see if they have any suggestions on how to embed the form via shortcode in an Angular template or possibly with some JS script functionality that they haven't documented.

mmarquiscreative commented 6 years ago

@see8ch: so NinjaForms basically is saying they don't have support for angularJS framework integration. I don't think the issue is that the form isn't displaying, I think the issue is that the shortcode is being read as a string, instead of being executed on page load/template load.

Is there a way to test an AJAX request to run the shortcode after page load? What's involved with that?

mmarquiscreative commented 6 years ago

Or, is there a way to run a filter/action when a button with a specific id is pressed or something?

mmarquiscreative commented 6 years ago

I may be onto something. I figured out I can split the html being echoed in the add_filter function, so I actually can call the form in a nested DIV, in that initial html we're loading. Don't worry about figuring out the AJAX stuff or anything yet, while I play around with this.

Thanks Chris!