I have a WordPress site with a form that I need to add a captcha to. The form isn't it's own template or even on it's own page but it is a single php file that is included on all of the pages. The actual form is in the shape of a drop down menu. When a user clicks on the "request info" link, the form drops down from the navbar. Do to the way it is set up I can't use a WordPress plugin.
Normally, I could I just add a php captcha script and be done with it but the form action is set to post to an external website. When the visitor submits the form, it goes to another website that collects the info, as you can see here:
<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST" name="contact" id="contact" onsubmit="return checkform(this);">
Because the form isn't verified with a php file on the sites server, I don't know how to verify the captcha and get it to work. Does anyone have any suggestions?
The only way to do it would be to make an ajax call on submit to your server where you check the captcha code. If the code is valid, then submit the form. If it isn't display the error and don't allow the form to submit.
If you are using Recaptcha, check this SO: using reCAPTCHA with ajax....javascript loading problem
If a general Captcha is what you are doing: jQuery ajax validate captcha
The answers are more focused that what you are looking for, but will at least get you pointed in the right direction.
Related
I have created a module where a form is added to the admin view order page using the function:
public function hookDisplayAdminOrderSide($params)
The form on that page posts data to the same url:
<form method="POST" action="#">
I then use the hook "hookDisplayAdminOrderTop" to capture the post data and submit to the API (this is done when the page posts to itself and reloads). I then collect the results of the api and assign it to $result. This then allows me to echo if the submission worked etc
This all works fine.
However, I'm pretty sure this is not the correct way to do this with Prestashop. Usually with a form I would send the user to another page e.g.
<form method="POST" action="/submit.php">
Then on that page once the data has been submitted, redirect the user to a confirmation page.
Whilst what I have done is working, what is the correct way to do this with prestashop (p.s. I'm new to Prestashop, this is my 1st module) so try and keep the advice easy to follow?
I looked at the other forms on the page e.g. status update form and private note form, they all seem to post to the same url but with a slight change e.g.
index.php/sell/customers/2/set-private-note
index.php/sell/orders/2/status
index.php/sell/orders/2/send-message
I'm assuming the "set-private-note" and "status" etc are linked to some form for submission form in the PS back end.
Finally, on a second note, if you create a 2nd php file in the module root folder, what needs to be added to keep this secure e.g. so someone outside of the admin can't run it etc?
Any help would be greatly appreciated.
Thanks in advance :)
This is going to sound like a dumb question, so I apologize upfront.
I have a PHP form, with its action posting to itself, so that I can do some validation to make sure text boxes, a few checkboxes and a couple radio buttons are selected. After I confirm there are no form errors, I need to let the user preview what they've entered before letting them submit the information to a database.
For previewing form submission details, logically page1.php would have <form action="page2.php"> and page2.php would allow the user to preview what they've submitted.
But for form validation, logically, the form should submit to itself so that it can validate all required fields are entered while on the same page.
So, is there a way that I can direct the user to a "next page" after the form has validated by submitting to itself, so that they can preview the information?
Note:
I am rewriting a classic ASP form, which does this:
if errorMsg = "" then
response.redirect "verify.asp"
else
session("errorMsg") = errorMsg
response.redirect "default.asp"
end if
I assume in the case of PHP, the "else" portion of a similar conditional would be unnecessary since it already posts to itself, it's only when the error message array is empty that it should redirect to the verify page.
You can use header to perform a redirect:
if(empty($errorMsg)) {
header("Location: verify.php");
exit;
}
Using Mark Heintz's answer and some googling, I figured out the best way to do it is with a combination of Javascript and a meta tag. The meta tag will account for when javascript is disabled.
Redirect in PHP without use of header method
Redirecting to a relative URL in JavaScript
There is also an AJAX way of doing it: Modify the URL without reloading the page
I've been looking ofr a while but I'ven't found any question that solves my question:
I've a php page with some forms, it's a long page and users may use one or some of the forms each time they connect to the website. When an users submits one of the forms the forms calls the same page but with the data updated (that works good for me).
The problem is that I would like that after submiting any form, the new page starts in middle of the scroll where the form submited is, so the user hasn't to go to the start of the page.
I'm not sure if this can be done with php or I need javascript (i don't know anything about javascript yet).
Use an id to navigate between elements in a page. Put # in action attribute when the user submits the form the browser will navigate to the form location
Example
<form id="example" action="yourpage.php#example" method=...>
<form id="example2" action="yourpage.php#example2" method=...>
I have a modal box that has a PHP form on it. When the form is submitted it closes the modal box and redirects back to the page. I want the modal box to stay open if there is an error.
It is ok if modal box closes when it is a successful submission because it redirects to my success url. This is only an issue if there is an error on the form. I am using php to check to see if there is a blank field and using the built in email validator.
Also worth mentioning if there is an error on the form and it closes the modal box if you open it back up you see the errors since it wasn't successfully submitted.
I am using this for my form action
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
I can post more of the code if necessary.
Is there anything that strikes anyone that could be a simple fix for this?
You can do Client Side (JavaScript/Jquery) validation. Which can be done by using onSubmit='return validateMyForm()' on the form element.
But, its good to have server side validation, so use AJAX for that.
Don't submit your form, use <input type="button"> instead of <input
type="submit">
Submit your form using $.post or $.get or $.ajax, get PHP errors as
return and show errors on the Modal Box
To do this you can use ajax...
Tutorial
I am using php to check to see if there is a blank field and using the built in email validator.
While it's good to perform validation on the server, you should deal with validation on the client side. Use javascript to validate so you don't hit the server and your modal screen won't close.
I spent a few days and got a form working on my website.
However whenever it is submitted, it does not reset and when I reload the browser it sends the form again using the previous submitted data.
How would I stop/prevent this?
I also want to get rid of the leave page warning that pops up when there is any data written in the form. So that users can leave the page without the pop-up even if there is data not submitted.
The form is commented out on this temporarily page: http://rikahiyuka.com/Template%20-%20index.php
(I don't have much time to type this question so I might change it later)
To clear your form on submit, you can add some Javascript to the form element itself, e.g.:
<form onsubmit="this.submit(); this.reset(); return false;">
To prevent the warning on page exit, have you tried:
window.onbeforeunload = null;
Check out the JavaScript onbeforeunload event. It's non-standard JavaScript introduced by Microsoft, however it works in most browsers and their onbeforeunload documentation has more information and examples.
<form action="MAILTO:contact#rikahiyuka.com" method="post" enctype="text/plain">
You cannot POST to a mailto: url. You should have the action set to a PHP page, which sent the email for you. There are many examples for a PHP contact form on the internet.