Jump to content

Stefany93

Members
  • Posts

    261
  • Joined

  • Last visited

Everything posted by Stefany93

  1. Hello fellows, Sorry to bother you again, but I have ran into troubles again. It's about the same JS validation script, but this time, when the user clicks the "submit" button, twice, instead of the error messages repeating like the case before, the form gets submitted to the server EVEN if there are still errors generated by the script, and I don't need to tell you how lame that is. Here is the code itself, please give me some tips on how to proceed. I tried and I tried to fix this on my own, but without results: // Input validation in the contact form // The clicked variable checks whether the "submit" button has been clicked. clicked = true; // The onload property of the window object will collect the // IDs of the form fieds we intend to get the get the values from // as soon as the webpage has finished loading. window.onload = function(){ document.forms[0].onsubmit = function(){ name_field = document.getElementById("name_field"); email_field = document.getElementById("email_field"); text_area = document.getElementById("text_area"); // If the "submit" button has been clicked, we set the "clicked" variable to false // so that our JS errors won't be repeated. if(clicked === true){ clicked = false; // Here we take the IDs from the fieldset elements of the form // we are conducting the check on. Later on, we shall append // text nodes to these fieldset elements as children // and in that way we shall display the errors // our user might have allowed. var fieldset_name = document.getElementById("fieldset_name"); var fieldset_email = document.getElementById("fieldset_email"); var fieldset_message = document.getElementById("fieldset_message"); // Our regular expression, we are going to need it later when we validate the // email address of the user. var re = /^[a-z]+[a-z0-9.]+@{1}[a-z0-9\-]+[.]{1}[a-z]{1,5}[a-z.]{1,5}?[a-z]$/i; // Due to the lack of a better idea, the variable there_is_error // is just defined and it will be given the value of true // every time there is an error with the user input. var there_is_error; // Here we declare the error messages our user is going to get // if he has populated the wrong data in the mandatory fields of // our contact form. var name_error = document.createTextNode(" Please populate your name! "); var email_error2 = document.createTextNode(" Please enter your email! "); var email_error = document.createTextNode(" Please enter a valid email! "); var message_error = document.createTextNode(" Please populate your message! "); // If the name field is less than 2 characters, diplay an error. if(name_field.value.length <= 2){ fieldset_name.appendChild(name_error); there_is_error = true; } // If the email is less than 5 characters, display an error if(email_field.value.length <= 5){ fieldset_email.appendChild(email_error2); there_is_error = true; } // If the email is not a proper one, i.e. missing an "@" symbol // and other typical email address character, or if it containt // characters unrepresentative for an email address // display an error. We check all that with the regular expression // we had declared earlier with the "re" variable. if(!re.test(email_field.value)){ fieldset_email.appendChild(email_error); there_is_error = true; } // If the message body is not populated at all, // display an error if(text_area.value.length < 1){ fieldset_message.appendChild(message_error); there_is_error = true; } // If the "there_is_error" variable evaluates true, // that means that there the user has entered incorrect information // at some point, and what we do next is that we return false, // which prevents the form to be submited to the server // where it will be handled by some server side programming language. if(there_is_error === true){ return false; } } } }
  2. ^^ Thanks a bunch jazzman, I will send them my CV straight away!
  3. So stupid of me - indeed does offer jobs from other countries, since you mentioned it, I looked around and found it - I just had to put the country's domain on the end of the URL. Thank you so much! And yes, there are Bulgarian job websites, but they are only for Bulgarian programming companies...
  4. Dear fellows, I am very sorry I am posting this annoying question, but her lies my issue - I usually go to indeed.com to search for programming jobs, and it is an awesome website, but it is only for jobs located in USA, but I tried and I tried searching for websites that offer programming jobs within Europe and I managed to find just a few of them, and they only had a few listings. So could you please recommend me a website that lists programming openings in Europe? Thank you very much!
  5. @Jessica, your solution to the problem was pure genius, thank you very much! @Psycho, thank you very much for telling me that all of the errors need to be displayed, not the program to stop at the first one encountered. About your second advice, I was actually thinking of implementing some elements next to the input box just with IDs without values, but I have had programmers telling me that this is plain wrong and a bad programming practice because the server loads the empty <span></span> elements without actually having to use them if the user inputs their data correctly and thus making them useless, that is why, I have been told, the best way to add a text into the document with JS is just to create elements and text nodes on the fly. Here is the complete code. If someone has any comments on it, I will be most happy to read them, thank you. clicked = false; window.onload = function(){ document.forms[0].onsubmit = function(){ name_field = document.getElementById("name_field"); email_field = document.getElementById("email_field"); text_area = document.getElementById("text_area"); if(clicked === false){ clicked = true; var fieldset_name = document.getElementById("fieldset_name"); var fieldset_email = document.getElementById("fieldset_email"); var fieldset_message = document.getElementById("fieldset_message"); var re = /^[a-z]+[a-z0-9.]+@{1}[a-z0-9\-]+[.]{1}[a-z]{1,5}[a-z.]{1,5}?[a-z]$/i; var there_is_error; var name_error = document.createTextNode(" Please populate your name! "); var email_error2 = document.createTextNode(" Please enter your email! "); var email_error = document.createTextNode(" Please enter a valid email! "); var message_error = document.createTextNode(" Please populate your message "); if(name_field.value.length <= 2){ fieldset_name.appendChild(name_error); there_is_error = true; } if(email_field.value.length <= 5){ fieldset_email.appendChild(email_error2); there_is_error = true; } if(!re.test(email_field.value)){ fieldset_email.appendChild(email_error); there_is_error = true; } if(text_area.value.length < 1){ fieldset_message.appendChild(message_error); there_is_error = true; } if(there_is_error === true){ return false; } } } }
  6. Hello fellows, I am building a client - side contact form validation with JS. The problem is that that I want when the user inputs the wrong input, basically, a text next to the input box to appear with the appropriate error message when the user clicks "submit". So far so good, but the main issue occurs when the user clicks "submit" multiple times and the error message repeats itself which is kind of lame. Tried to solve it for a couple of hours yesterday, until I failed miserably... So could you please tell me a way to make it the error message to appear only once, regardless how many times "submit" has been pressed? Here is the code written so far: function validate_form(name_field, email_field, text_area){ var fieldset_name = document.getElementById("fieldset_name"); var fieldset_email = document.getElementById("fieldset_email"); var fieldset_message = document.getElementById("fieldset_message"); var re = /^[a-z]+[a-z0-9.]+@{1}[a-z0-9\-]+[.]{1}[a-z]{1,5}[a-z.]{1,5}?[a-z]$/i; var name_error = document.createTextNode("Please populate your name!"); var email_error = document.createTextNode("Please enter a valid email!"); var message_error = document.createTextNode("Please populate your message"); if(name_field.value.length <= 2){ fieldset_name.appendChild(name_error); return false; } }
  7. Thank you very much for the replies, fellow programmers! I understand now that the only reason "var" isn't removed is because the CodeIgniter development team doesn't want to in order to help folks who are still running on PHP4 for some reason. Anyways, thank you.
  8. Hello fellows, I have noticed that CodeIgniter has the "var" keyword in front of all of its predefined class properties like this: class CI_Session { var $sess_encrypt_cookie = FALSE; // more code here } I know that the "var" keyword was used back in PHP 4 to define a variable, but no one still uses PHP 4 anyways, so could you please tell me why the hell CodeIgniter still puts "var" in front of properties?
  9. Declare the $selection variable outside of the functions and then pass it to them as a parameter? Like so: $selection = 'your value'; function one($selection){ // your code here } function two($selection){ // your code here } Alternatively, you could use the "global" keyword, but it is bad idea unless it is absolutely necessary...
  10. Well, you are making a query and you have some mistake in it. Either you missed or put an extra comma, forgot to enclose a MySQL function with braces, no idea really. What I usually do when I receive such error, is that I copy my SQL query and go to PHPMyAdmin and paste the query in the "SQL" tab. There you will see a more detailed explanation of the problem. Or alternatively, you could just post the code you use to make a new topic...
  11. Huh? Could you please elaborate?
  12. Welcome and good luck with your project...
  13. I actually have a friend who is part of the PHP development mailling list and he was one of the programmers who voted for the deprecation of the mysql_* library. I think that is really good - all mysql_* should be removed because they pose a security risk. And I don't get why people use mysqli - PDO is way more updated and secure. I wish there was way people would start learning making SQL queries using at least mysqli or even better PDO. Most of the beginners start with mysql_* functions and that is just plain wrong...
  14. Oh, did you mean that the author SHOULD mix PHP and JS together? I seem to have understood it wrong, I thought you said that he is currently mixing them...
  15. I fail to see how he is mixing PHP and JS together...
  16. Congratulations Christian! You are indeed an awesome programmer! I really want to become as awesome as you someday!
  17. Hello and welcome! This forum has so little users so every newcomer programmer is more than welcome!
  18. Pretty much all programmers I know use Google Chrome. I think it is a pretty neat browser, really fast and very programming friendly.
  19. Nope, they deprecate stuff that don't work anymore or are harmful if used...
  20. I agree, with prepared statements, SQL injections are almost 100% eliminated. $username = 'Longstreet'; $query = $db->prepare("INSERT INTO names(username) VALUES(:username)"); $query->bindParam(':username', '$username', PDO::PARAM_STR); $query->execute(); When I first started using PDO, I kept forgetting to execute the query and I can't tell you how many hours I had spend searching why the heck wasn't my code working
  21. Thanks a bunch!
  22. Hi fellows, I am building up a blog application and I am stuck. I am trying to make the appropriate comments display below a single blog post in a single query. The problem is that if the number of comments is more than 1, the blog post is being repeated as well which is not what I want. I want only 1 blog post to be displayed on a single page and all the comments that associate with the post be displayed as well. Here is the code of the query [size=5]$blog_post = (isset($_GET['blog_post'])) ? filter_input(INPUT_GET, 'blog_post', FILTER_SANITIZE_NUMBER_INT) : 0; $query = $db->prepare("SELECT posts.post_id, posts.title, posts.contents, DATE_FORMAT(posts.date_posted, '%d %M %Y') AS date_posted, comments.comments_name, comments.comment, DATE_FORMAT(comments.date_commented, '%d %M %Y') AS date_commented FROM posts LEFT JOIN comments ON comments.post_id = posts.post_id WHERE posts.post_id = :blog_post OR posts.post_id = (SELECT MAX(posts.post_id) FROM posts)"); $query->bindParam(':blog_post', $blog_post, PDO::PARAM_INT); $query->execute();[/size] And here is part of the HTML page where I am trying to make things work [size=5]<article class="post"> <div class="post-data"> <?php while(list($post_id, $title, $contents, $date_posted, $comments_name, $comment, $date_commented) = $query->fetch(PDO::FETCH_NUM)){ ?> <h2><?php echo $title;?></h2> <p> <?php echo $date_posted;?></p> </div> <p> <?php echo nl2br($contents);?> </p> <hr></hr> <!-- Blog comments --> </article> <article class="post"> <div class="title"> <h3> <?php echo '<strong>',$comments_name,'</strong>'; ?> </h3> </div> <p> <?php echo $date_commented; ?> </p> <p> <?php echo $comment; ?> </p> <?php }?> </article>[/size] Thank you very much! EDIT - Sorry but somehow the font size of the code posted here is very small for some reason... Best Regards Stefany
  23. Sorry it took me so long to reply, thanks to everyone for the links and suggestions! @gizmola, thank you so much for the detailed explanation, I value it a lot!
  24. Hello fellows, I want to study frameworks but the problem is that the big ones like Zend and Yii are very difficult to be understood by someone who has never dealt with frameworks before. I tried going over to simpler ones, but their documentation is simply horrible - "This framework is documented by itself" Told you, simply terrible. So if you can be so kind to point me to a simple and well documented framework so that I have get the hung of these stuff, I will be very grateful. Thank you! Best Regards Stefany
  25. Thank you very much for the help!
×
×
  • 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.