Jump to content

spacebiscuit

New Members
  • Posts

    8
  • Joined

  • Last visited

spacebiscuit's Achievements

Newbie

Newbie (1/5)

1

Reputation

  1. So what about this line: $(function() { This is an anonamous function right? Would it be possible to name it. Why does it open with $( The dollar sign would suggest to me that a variable name should follow. I want to purchase a book to help me better get to grips with this, I was looking at one of the Dummies series. Should I be looking at JQuery or Ajax - what is the difference as I'm not clear on this. If anyone knows of any good books please let me know. Thanks, David.
  2. Thanks that works perfectly. As I said. I did manage to get it working last night by changing the submit to a button and using a onclick event handler. The ajax request then called the form submit directly which had no form validation and so the captcha check was by-passed. It worked but I knew it wasn't very elegant and I wasn't 100% happy with it. Your solution works perfectly though, however I think it is important that I understand exactly how it works and what is happening otherwise I've learned very little. I can't quite see what is calling the function in the code provided. In my previous attempt I was using onclick or onsubmit to call the function. I can see that the code begins with: $(function() { What does this do? $('#myform').submit(function(event) { I guess that this is catching the form submit/click? The rest makes sense. Apologies for not using the code tags. I was looking for them yesterday but I was tired andmissed them. Thanks!
  3. Ok I got it working but had to use both the onsubmit and onclick event handlers. I've got to get some sleep now but I will report my findings tomorrow. Thanks for your help! David.
  4. I have verified the output of 'result' - it works correctly for matched and mis-matched captcha inputs. check.php simply returns a 1 or a 0. Would this approach not send the code into an infinite loop? Take a look ay form code: <form id="myform" enctype="multipart/form-data" action="<? echo $_SERVER['PHP_SELF']; ?>" method="POST" onsubmit="return dosubmit(this)" > It looks to me as if dosubmit() will be called again, it should match the captcha and then call the form again, and so on? Or am I mis-understanding something. Another approach I thought might work was to have the user submit via onclick but have the jquery call the form by submit and thus have two different methods used to submit the form but I can't get the form action to work this way.
  5. Thanks, I tried that. Whem I input my captcha it always returns as false. If I remove the call to submit the from though it correctly reports the captha as matched. eg: if(result==1){ alert("Wrong code input"); } else{ alert("Correct"); } The above works correctly but below always evluates as true (wrong code input) if(result==1){ alert("Wrong code input"); } else{ $('#myform').submit(); } Does the above call begin a new instance of the form, if so the captcha code will have changed since the previous check. Thanks.
  6. Yes that's right, if I set the return to false outside of the ajax request it prevents the form from submitting. So my code is now: function dosubmit(form) { var captcha_code=form.captcha_code.value; $.ajax({ type:'POST', url:'/includes/check.php', dataType:'json', data: 'captcha_code=' + captcha_code, success:function(result){ if(result==1){ alert(result); } else{ {---SUBMIT THE FORM---} } } }); return false; } How would I then submit the form based on the value of the the success. Thanks!
  7. Ok I have things almost working but have hit another dead end: <form id="myform" action="index.php" onsubmit="return dosubmit(this)" > <p><input type="text" name="captcha_code"></p> <p><input type="Submit" value="Submit" name="submit"/></p> </form> function dosubmit(form) { var captcha_code=form.captcha_code.value; $.ajax({ type:'POST', url:'/includes/check.php', dataType:'json', data: 'captcha_code=' + captcha_code, success:function(result){ if(result==1){ alert("Wrong code input"); return false; } else{ return true; } } }); } So when the form is submitted check.php is executed and the result of the check is returned to 'result', which I then evaluate and the return value should then determine whether the form submission continues or not. The input is passed successfully to the PHP page and result is successfully passed back to the ajax but the return value doesn't work - no matter what I try. I read something about async but I'm not sure what this is or if it will help. It's taken me 12 hours to get to this stage and now with the finishing line seemingly in view it looks like I can't achieve what I set out to do? Any help would be apprecaited. Thanks!
  8. Hi, I'm new to ajax and I'm having some issues, I've been hacking away for about 5 hours now and I've hit a deadend so hopefully someone here can help? What I want to do is perform html form validation (which requires a php script to be called) when a form is submitted, if it evaluates to 'true' print an alert and stop the form from being submitted, if false the form submission can continue. Here is what I am doing: <script src="prototype.js"></script> <script> function dosubmit() { $.ajax({ type: 'POST', url: 'check.php', success: function(data){ alert("Hello"); } }); } </script> <form method="POST"> <p><input type="text" name="name"></p> <p><input type="button" value="Submit" onsubmit="dosubmit()"/></p> </form> When I submit my form nothing happens, I get no response. Should I at least not get an alert? Thank you in advance, David.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.