scferg Posted February 9, 2008 Share Posted February 9, 2008 I was wondering, if it was possible to have predefined html form values. So, the form would only submit if the correct value was entered. Like, you need to enter "14" but you entered "13" ... the form would not submit. I just thought this would be a simple thing to do with javascript. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 9, 2008 Share Posted February 9, 2008 Something like this: function submitForm(){ var val = document.getElementById('myField').value; if(val == 14){ document.myForm.submit(); }else{ alert('Invalid Input'); } } HTML: <form name="myForm" action="page.php"> <input id="myField" name="fieldName" /> <input type="button value="Submit" onclick="submitForm();"> </form> Quote Link to comment Share on other sites More sharing options...
scferg Posted February 9, 2008 Author Share Posted February 9, 2008 Awesome! Thanks! Quote Link to comment Share on other sites More sharing options...
scferg Posted February 9, 2008 Author Share Posted February 9, 2008 Is there someway that if the code isn't correct, it will display a message like "Code invalid, please retype the code again" ? Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted February 9, 2008 Share Posted February 9, 2008 Yes, look in the "Else" part of the condition; of the script, that The Little Guy provided you. Where it has this: alert('Invalid Input'); Quote Link to comment Share on other sites More sharing options...
scferg Posted February 9, 2008 Author Share Posted February 9, 2008 Ok, thanks! Quote Link to comment Share on other sites More sharing options...
scferg Posted February 9, 2008 Author Share Posted February 9, 2008 Hmmmm... it seems to submit the form anyway. Try it at http://sims2news.com/?page=contact and try entering something other than the image shows. It still submits the form :-\ Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 9, 2008 Share Posted February 9, 2008 that is because you have the type as a type="submit" change it to: type="button" Quote Link to comment Share on other sites More sharing options...
scferg Posted February 9, 2008 Author Share Posted February 9, 2008 Great! It works Quote Link to comment Share on other sites More sharing options...
scferg Posted February 12, 2008 Author Share Posted February 12, 2008 Ok, I was using that as a type of CAPTCHA thing. I just needed something simple, but it was dumb of me to do it this way -- the bots have already gotten passed it. I've search all over the internet for a *real* CAPTCHA system, but all of them seem confusing. Like, some require databases and such. Do any of you know of a good CAPTCHA script, or know how to make one? I really appreciate it Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 12, 2008 Share Posted February 12, 2008 Good: http://phpsnips.com/snippet.php?id=6 Or Better: http://phpsnips.com/snippet.php?id=43 Quote Link to comment Share on other sites More sharing options...
scferg Posted February 12, 2008 Author Share Posted February 12, 2008 I tried the Advanced CAPTCHA script, but the image.php script seems messed up. Go to http://sims2news.com/image.php to see it. I don't know how to fix it... Quote Link to comment Share on other sites More sharing options...
scferg Posted February 12, 2008 Author Share Posted February 12, 2008 Nevermind...I just had to download the Disney.ttf font. But, now, I can't seem to get a valid code. http://sims2news.com/form.php Everything I've tried always returns with "The number you entered doesn't match the image." Quote Link to comment Share on other sites More sharing options...
scferg Posted February 12, 2008 Author Share Posted February 12, 2008 Ok...nevermind again The Disney font was too hard to understand, and half the time the characters were cut off. I just changed it to a different font. Thanks the help ! Quote Link to comment Share on other sites More sharing options...
scferg Posted February 13, 2008 Author Share Posted February 13, 2008 Hmmm....how would I implement this with my current forms if they already have an action? All of my forum have a action of http://mysite.com/v-cgi/forms.cgi Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted February 13, 2008 Share Posted February 13, 2008 You know this is the JavaScript forum; right? ??? You need to post server side scripting questions in the appropriate forums on this website. Quote Link to comment Share on other sites More sharing options...
scferg Posted February 13, 2008 Author Share Posted February 13, 2008 Then you can move it there. This kind of branched of my original Javascript thread. Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted February 13, 2008 Share Posted February 13, 2008 Sorry, I cannot move this thread; I am not a moderator. You can post a question, similar to this one, in the server side scripting forums; which can be found here: http://www.phpfreaks.com/forums/index.php?action=collapse;c=25;sa=expand#25 http://www.phpfreaks.com/forums/index.php?action=collapse;c=27;sa=expand#27 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.