I've got this registration form: http://www.topgamedb.com/register
If you enter a captcha (the wrong or the right one, it does not display a message next to it)
If you click Register, it does not display errors, it submits the form.
http://www.topgamedb.com/css/registration.css
http://www.topgamedb.com/js/registration.js
I have this working on another website, but after copying it over to this new website, I can't seem to get it to work. I'm obviously missiong something 'obvious' - its late and I haven't slept and I'll probably kick myself when I see whats wrong.
Any help is greatly appreciated.
Number 1, firebug is giving me an error that jQuery.md5 doesn't exist. Do you have another library that you added on to make this work?
You need to prevent the default behavior of the button (submitting the form):
$(register_button).click(function () {
// do validation, etc.
// submit form using $(your_form).submit();
// if values are passing validation
// prevent the form from being submitted immediately
return false;
});
Related
I am trying to show a paper-toast when the user forgets to fill in some data in a form or when he submits a wrong e-mailadres.
I have this PHP-code that will print out an error message on the screen when the user submits the form and forgets to fill in the input or when he submits a wrong e-mailadres. This works fine. Here's a small part of the code:
<?PHP
if(isset($errorMsg) && $errorMsg) {
echo "<p>*",htmlspecialchars($errorMsg),"</p>\n\n";
}
?>
I want to make it so, that the error message appears in a paper-toast. Further, i want to display a paper-toast when the form is successfully submitted.
My question is: is it possible to call a paper-toast with the error message and appears when the form is submitted?
Thank you in advance,
The only way PHP can "trigger client side events" is by outputting HTML that will behave as you want. In your case, you basically need to output the HTML for a toast and make sure it opens as soon as the page is loaded. To do that, just set the opened attribute:
printf('<paper-toast text="%s" opened></paper-toast>', htmlspecialchars($errorMsg));
I have a contact form
(http://pastie.org/private/jkukpixcygibqkiipbu88w)
which used to post the input fields to a processing script in a separate php file that would then email them to me.
(http://pastie.org/private/iiakln02xfacvb58uuyyqq)
I've now added a Captcha (SweetCaptcha)
I've had to remove the "action="mailer.php" from the form so that the Captcha can validate on the same page, and it basically works like this.
If Captcha = successful > do this, else > do this.
My problem is, how can I put my mailing script inside the "Captcha = successful > do this" part? When i do it now, I get a ton of syntax errors/saying my functions aren't defined.
I hope I have explained this well enough
Thanks in advance for any help!
It would be helpful to get a code snippet, but you can either override the function you want in javascript or in the "do this" part you can change the action of the form and then "submit" it.
I have been working on this issue and it's driving me CRAZY!.
so I have a register POST form, when submitted , it redirects to same page , though I have the following:
if (isset($_POST['submit']))
{
//include validation and executing code... (another page)
}
now the code works perfectly , everything is nice , but I have one issue.
when a user clicks twice in a row , he gets a message that a user with same e-mail is already registered (where the first click has registered him and inserted the info in database)
Now I tried disabling the button with : Onclick="this.RegisterBtn.disabled=1;" in the button tags
and i also tried with : onSubmit="this.RegisterBtn.disabled=1;" in the form tags.
both stop the form from being submitted , no idea why. I also tried this:
onClick="this.RegisterBtn.disabled=1; this.form1.submit();"
Now i came up with an assumption that when a button is disabled the "isset" function will return false, if anyone experienced here can confirm that or help me fix this problem , i will be very grateful , am just abit new to php and all this :) ,
thanks alot in advance
EDIT: the form action is null (redirecting to same page), the code including is above the form.
EDIT: When I disable the button, isset($_POST['submit']) always returns false.
SOLUTION: Ok , i did solve it , in case anyone crosses over to my post facing same problem here's how i solved it:
first , when you disable the button, the isset($_POST['buttonname']) will return false at all times. so i have done the following:
instead of this condition I used : if (!empty($_POST)) ..... include the code
and i used the onsubmit (in form tags) .. this.button1.disabled=1; , and now everything works perfectly :-), and form cannot be submitted twice :D.
Try
<input type="submit" name="submit" value="Submit" onclick="this.disabled = true;" />
Forget about messing with the form. Use these simple checks on the server side:
If a second request to register the exact same email address occurs, ignore it.
If a different email address occurs, update it.
If there wasn't one before, then add it.
So here's my situation: I have a form that validates with PHP. I want to make it so that if the form fails validation, the user is forced to click through a confirmation dialog before they navigate to another page (the form is fairly large and they don't want to accidentally leave it before it's saved). I'm going about this like so:
see updated function below,
Basically use php within the function to either set the body to present the confirmation or do nothing depending on the error status of my form. Nothing happens when the form isn't submitted and I click a link, good. When the form is displaying errors and I click a link the confirmation dialog will appear but canceling it causes it to reappear. If I cancel it a second time the page request will go through even though it's not supposed to. I'm not that familiar with javascript so I'm not sure what's going on. Is there a better way I should be going about this?
Edit: I figured it out, it was a combination of things. The first was a really dumb mistake on my part: I was calling the onlick on both tags AND the tags for each link in my list, hence why the box popped up twice.
the second piece was that even though my function already returns bool, the onclick requires an explicit return declaration. I was doing:
<a onclick="forceConfirm();" href="somepage.html">Blah</a>
When it should have been:
<a onclick="return forceConfirm();" href="somepage.html">Blah</a>
Then just edit the PHP so that forceConfirm always returns true when the form hasn't been submitted, bypassing the confirmation:
function forceConfirm(){
<?php
if($form->errorStatus){
echo 'if(confirm("Are you sure you want to navigate away from this page? All unsaved changes will be lost.")){'."\n".
'return true;'."\n".'}'."\n".
'else{ return false;}';
}
else{ echo 'return true;';}
?>
}
Now I just need to figure out how to use jQuery to apply this to all links without having to put onclick events all over the place....
You can use confirm() like this:
if(confirm("Are you sure you want to proceed?")){
document.location = 'confirmed redirect url...';
}
else{
document.location = 'cancel redirect url...';
}
Then you'd wrap that in the same PHP block as in your example, displaying it if necessary and hiding it if not.
This is the whole source code, i would like to modify it to add a new column to show the
Client Mobile
Client Office Telephone
Client E-mail
in an another popup php pages.
What i have attempted is to add a form and a submit button to create a new column , when i press that submit button, the mobile, office,email information will post to another php page to print out. however, since there is a another form exist already, when i add a form ,the function in the following form will not work. (Don't worries , i will indicate where the problems happen.)
it is a complicated question. Thanks in advance
The source code is here:
https://docs.google.com/leaf?id=0B196kQ-9lu50OTI1NDZkMjktNzAzNi00MmM0LWIzMjgtNTQxMTIyZmYyM2I1&hl=en_US
the problem is at line 99
p.s. I just found out the form method can not get my job done, since it can not create a popup window for the information at the same time.
Looks like at line 126 there is an extra </form> tag. Delete it...that might help.
EDIT:
Ok. So it needs to look something like this:
$_SESSION['echoable'] = $aVar; //put any variable you want here, such as POST data
Then, in the popup window, write:
EDIT: forgot to say, add this to the TOP of your page.
session_start();
Then do this stuff later on.
if((isset($_SESSION['echoable'])) && (!empty($_SESSION['echoable']))) {
echo $_SESSION['echoable'];
}
else {
echo "whatever"; // whatever you want here
}
The above will print whatever var you want. Hopefully this helps...if not let me know.