Chrisj Posted March 18, 2013 Share Posted March 18, 2013 I have this Form that works successfully (I know it's not state-of-the-art).I simply want to add code to make Contact Name field mandatory. I'm not sure if I should post all the code. Can you help me? thanks <script type="text/javascript"> function checkemail(){ var str=document.myform.email_address.value; var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; if (filter.test(str)) testresults=true; else { alert("Please input a valid email address!"); return false; } if(document.myform.agree.checked!=1) { alert("Please check the box to agree to the Terms."); return false; } if(document.myform.ans.value.toLowerCase()!="white") { alert("Please answer security question correctly: Black or White?"); return false; } return true; } </script> Quote Link to comment https://forums.phpfreaks.com/topic/275818-making-contact_name-a-required-field/ Share on other sites More sharing options...
Jessica Posted March 18, 2013 Share Posted March 18, 2013 Check if that field has a string entered. Don't forget to include PHP validation on the backend, you can't rely on JS validation only. Quote Link to comment https://forums.phpfreaks.com/topic/275818-making-contact_name-a-required-field/#findComment-1419349 Share on other sites More sharing options...
Chrisj Posted March 18, 2013 Author Share Posted March 18, 2013 The script only shows this: <tr> <td>Contact Name:</td> <td><input type='text' size='40' name='contact_name'> </td> </tr> Can you help me add code to make Contact Name field mandatory? thanks Quote Link to comment https://forums.phpfreaks.com/topic/275818-making-contact_name-a-required-field/#findComment-1419358 Share on other sites More sharing options...
Jessica Posted March 18, 2013 Share Posted March 18, 2013 You need to add the code to your javascript. If you don't know how to write javascript, you need to either learn or hire someone to do it. If you make an effort, we can help you debug it. But you haven't written any code for this problem. Quote Link to comment https://forums.phpfreaks.com/topic/275818-making-contact_name-a-required-field/#findComment-1419359 Share on other sites More sharing options...
Chrisj Posted March 18, 2013 Author Share Posted March 18, 2013 Thanks for your reply. I'm learning all the time. I believe I should add this code, but I don't know where it should go, and what else I need. var username = document.myform.contact_name.value; if (/^[a-z]+([ \'\-][a-z]+)*$/gi.test(username)) { Quote Link to comment https://forums.phpfreaks.com/topic/275818-making-contact_name-a-required-field/#findComment-1419367 Share on other sites More sharing options...
Jessica Posted March 18, 2013 Share Posted March 18, 2013 That's a lot more complex than your original requirement. Making a field required is not the same as validating the value within in. A contact name also sounds to me a different thing than a username. *shrug* If you can't explain what you want it's not surprising you can't get it done. Quote Link to comment https://forums.phpfreaks.com/topic/275818-making-contact_name-a-required-field/#findComment-1419370 Share on other sites More sharing options...
Chrisj Posted March 18, 2013 Author Share Posted March 18, 2013 Putting me down isn't helpful. Any other help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/275818-making-contact_name-a-required-field/#findComment-1419396 Share on other sites More sharing options...
Jessica Posted March 18, 2013 Share Posted March 18, 2013 There wasn't a put down in any of my statements. Good luck getting "help". Quote Link to comment https://forums.phpfreaks.com/topic/275818-making-contact_name-a-required-field/#findComment-1419397 Share on other sites More sharing options...
Chrisj Posted March 18, 2013 Author Share Posted March 18, 2013 Now sarcasm. Please don't reply again. You obviously just enjoy acting superior instead of helpful Quote Link to comment https://forums.phpfreaks.com/topic/275818-making-contact_name-a-required-field/#findComment-1419398 Share on other sites More sharing options...
fife Posted March 18, 2013 Share Posted March 18, 2013 That will probably be the end of your replies. Id listen to Jessica as being a Guru, she knows her stuff. Best to learn and then post code you havent found else where or at least understand slightly yourself. Just stick to php form validation to start with then make it more fancy once it works however http://lmgtfy.com/?q=jquery+form+validation Quote Link to comment https://forums.phpfreaks.com/topic/275818-making-contact_name-a-required-field/#findComment-1419430 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.