Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    137
    Thanks
    1
    Thanked 0 Times in 0 Posts

    passing variables to new window in php

    1.

    i have a self submitting form using POST
    <form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="POST" id="test2" name="registrationform">

    i am not using any javascript assuming javascript is turned off in a users browser.

    i have a feature where in a user can click on an image to find out if a username is available or not. using javascript i am

    able to capture the value entered, pass the value entered by the user and open a new window and display a message with a php

    file if the username is available or not however since i am not using javascript i used the following code to call the same

    php file which checks for the user name,

    <a href="checkusername.php?usernameis="<?php echo($username); ?> target="_blank"> <img src="image.jpg"> </a>

    however i am not able to pass the value of the username entered in the textfield by the user.

    code in checkusername.php is

    $username = $_GET["usernameis"]; and the remaining code to connect to database and display a message.

    how can i pass the value entered in the textfield to checkusername.php when the image is clicked. also is there a way to

    define the width and height of the new window that opens.

    textfield is defined as follows = <input name="username" type="text" value="<?php echo($username) ; ?>" />


    2.
    i need to validate a password which can consist of both letters and numbers and should be between 5 to 10 characters only.

    how can i rewrite the following preg_match to specify the condition of 5 to 10 characters only as presently it is not working

    as i seem to be missing something in the syntax.

    if($password == "" || !preg_match('/^[a-zA-Z0-9]{\(5)$|^\(10)}+$/', $password) )

    please advice.

    thanks.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    <a href="checkusername.php?usernameis="<?php echo($username); ?> target="_blank"> <img src="image.jpg"> </a>

    however i am not able to pass the value of the username entered in the textfield by the user.

    code in checkusername.php is

    $username = $_GET["usernameis"]; and the remaining code to connect to database and display a message.

    how can i pass the value entered in the textfield to checkusername.php when the image is clicked. also is there a way to

    define the width and height of the new window that opens.
    Since you are using method="POST" in your form, the submitted value would be available in $_POST["usernameis"] rather that lts $_GET.
    You may use something like
    PHP Code:
    if(isset($_GET["usernameis"]))
     
    $username $_GET["usernameis"]; 
    elseif(isset(
    $_POST["usernameis"]))
     
    $username $_POST["usernameis"]; 
    if($password == "" || !preg_match('/^[a-zA-Z0-9]{\(5)$|^\(10)}+$/', $password) )
    Try
    PHP Code:
     if($password=="" || !preg_match("/^[a-zA-Z0-9]{5,10}$/",$password)) 
    Last edited by abduraooft; 03-10-2008 at 02:47 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •