I have my html template page which displays my charts. Im trying to have a contact form which submits to some php code (which emails the form to an address).
I cant seem to get even the javascript validation, let alone submitting the form. I get no errors, it just refuses to do anything. Ive tried removing the validation code and stripping the form back to absolute basics, but it doesnt do anything.
How can I have an html form which submits to some php?
It's a bit hard to tell what could be happening. Can you provide a bit more detail about this and a short example?
Depending on how your app and html template is structured, my first guess (or element to check) is that there may be some missing css classes in your form which shiny uses to link the client and server. For example, shiny-bound-input or action-button. But it's a bit hard to tell. Are you injecting shiny elements into the template as described here or are you using your own html markup? You may also want to check your message handlers to make sure all the element IDs and message names match.
If you have some sample code that you can share, I'd be happy to take a further look.
At the moment I cannot get it to fire anything on submit (youll see Im trying to fire a js alert on submit). The first step is to get this working. Then I can try targeting my php file.
This is a bit odd. Everything looks right according to the docs and it should work. Although, I'm not sure how jQuery implements client-side validation. Are you tied to using ("#contactForm").submit(...). My only suggestion is to move the event from the form and attach it to the submit button.
$("#sendMessageButton").click(function(event){
// do something here...
})
Maybe this is a weird artifact when using htmlTemplates? But who knows. Perhaps someone else may have a better idea.
So that solves that issue. But now it tries to saves contact_me.php to disk. My contact_me.php file resides in the www directory (which I believe is the correct place for it). So how can I execute the php code?
Submit is an event listener. You will need to define a function that sends collects and sends the data to your php file. POST might be a good option. Something like this might help get you started.
Is there are specific reason for using php? If it is not a requirement for your project, shiny's built in validation (https://shiny.rstudio.com/articles/validation.html) might be a good alternative. If the form has sensitive information, it might be a better option to process the data within the shiny server.