Jump to content

john2020

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Everything posted by john2020

  1. I have a form on a PHP page which has 11 groups of radio buttons. Is there way to use PHP instead of client-side JavaScript to submit the form values only when one radio button has been selected from each of the 11 groups? Also, is it possible to get the form elements in a PHP page with JavaScript? Why does this JavaScript: myForm.elements.length stop working in a PHP page? I thought it wouldn't affect client-side JS since PHP is server-side code. Thank you!
  2. I am not sure if I am posting this to the correct forum. I have some Javascript that works fine in an html page. Basically it submits the form when one radio button has been selected from each of 11 groups. function Validate_Form_Submit() { R_Checked=0; for(i=0;i<myForm.elements.length;i++) { if(myForm.elements[i].checked) { R_Checked++; } } if(R_Checked==11) document.forms["myForm"].submit(); } Then I put this within the radio button input tag: onClick="Validate_Form_Submit() If I change the name of the page from .html to .php this code stops working i.e. stops submitting the form even though the source code looks the same for the two files. Isn't it a bit strange?
  3. I did manage to get the whitelist working to prevent SQL Injection attacks: if ($_POST["Submit"]) { $stringToFilter = $_POST["email"]; echo preg_replace( "/[^a-zA-Z0-9\.\-\_\@]/", "", $stringToFilter ); }
  4. Thank you, guys! It's good to know that they complement each other. Two things. First, the email filter considers even _@d.c to be a valid email address. Second, there must be some newbie error but I can't get this to work: if ($_POST["Submit"]) { define('USERNAME_REGEX', '/^[a-z][\w\.\*\-\_]{2,14}$/i'); $username = $_POST["username"]; if ( !preg_match(constant("USERNAME_REGEX"), $username)) { $error .= "Please enter a username. Use 3 to 15 characters and start with a letter. You may use letters, numbers, hyphen, asterisk, underscores and dot (.) <br />"; } }
  5. Folks, I am just trying to learn PHP. For form input validation which is better - Regexp or PHP Filters? Or do they have completely different uses? Where does preg fit in? Thank you! J.S.
  6. Thank you for your help. You got the typo form my original.
  7. Thank you! Just to clarify, shouldn't the double quotes be closed after svValue? In my original question I made a typo and didn't close the quotes. So would this be correct (just closed the quotes)? if( empty($_SESSION["One"]) || ($_SESSION["Two"] != "svValue" ) ) { do this; }
  8. Folks, I am trying to learn PHP and I have spent the morning trying to sort out something seemingly simple but it is not working for me. I want to write a statement which says: if session variable "one" is empty or if session variable "two" is not equal to "svValue" then do this: if ((empty ($_SESSION["One"])) || if ($_SESSION["Two"] != "svValue ) { do this; } Could you point out the mistake(s) in my syntax? Thanks! John
×
×
  • 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.