#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Location
    india
    Posts
    34
    Rep Power
    10

    Refresh a php script when a button is clicked


    hi to all,
    i create a form with captcha, but the captcha values taken from database and image taken from a folder and match it, i call captcha sript using require() function. the problem is "how to refresh the require() script by clicking a button in <form>", but not refresh the form values.
    please help me
    thanks in advanced.
  2. #2
  3. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,472
    Rep Power
    2106
    You can't do this with standard PHP/HTML. You'll need to look into AJAX for that sort of functionality.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Location
    india
    Posts
    34
    Rep Power
    10
    Originally Posted by Catacaustic
    You can't do this with standard PHP/HTML. You'll need to look into AJAX for that sort of functionality.
    thanks Catacaustic , please help me with example code

    my code is like
    <form><input type="text" value="">
    <?php require('captcha.php'); ?><a href="#">refresh</a>
    <input type="submit" value="submit"></form>
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,082
    Rep Power
    381
    he is not going to write the code for you.. You can however do search and learn Ajax and if you encounter any problems, let us know (by posting in correct forum) and someone will help you

    Comments on this post

    • phpfresh agrees
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Location
    india
    Posts
    34
    Rep Power
    10
    i don't known ajax please help
    Originally Posted by paulh1983
    he is not going to write the code for you.. You can however do search and learn Ajax and if you encounter any problems, let us know (by posting in correct forum) and someone will help you
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Location
    india
    Posts
    34
    Rep Power
    10
    is this correct??????????
    <script type="text/javascript">
    function refreshcontent()
    {
    document.getElementById('captcha').innerHTML="<?php require('captcha.php') ?>";
    }
    </script>


    then call it using
    <a href="#" onclick=refreshcontent()">refresh</a>
  12. #7
  13. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2002
    Location
    Queensland, Australia
    Posts
    827
    Rep Power
    146
    Originally Posted by phpfresh
    is this correct?
    Depends on what is inside captcha.php. I can only see this working if it echos IMG HTML code. In which case you don't need to use AJAX. Instead, use Javascript to modify the image src. So if your current img src is "image/captcha.png", you use JS to change it to "image/captcha.png?random=77587778978920" and that will trigger your browser to retrieve the image again. note that what follows the question mark can be anything, so long as it's unique the browser will re-request it.

    If I'm on the mark, this is a JS question and you should ask it in the JS forum.
    Ooh, they have the Internet on computers now!
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Location
    india
    Posts
    34
    Rep Power
    10
    <?php

    $p="http://www.mydomain.com/captcha/IMAGES/";
    $image=$p. rand(1,250) . '.gif';

    echo "<img src='$image' id='captcha' alt='Captcha' />";
    mysql_connect("database connection") or die(mysql_error());
    mysql_select_db("selecting database") or die(mysql_error());

    $content = mysql_fetch_array( $text );
    {

    $imagename=$content[1];

    } ?>
    it is call in main form page by

    <form><input type="text" value="">
    <div id="captchapart"><?php require('captcha.php'); ?>
    <input type="text" value="<?php echo '$imagename'; ?>" /> </div>
    <input type="submit" value="submit"></form>

    my question is how to refresh the div #captchapart,
    i hope it should clear for you
    thankx
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Location
    india
    Posts
    34
    Rep Power
    10
    ok, i used the following idea in my form page

    <script type="text/javascript">
    function refreshcontent()
    {
    document.getElementById('captchapart').innerHTML="<?php require('captcha.php') ?> <input type='text' value='<?php echo $imagename; ?>' />";
    }
    </script>

    this will refresh the captcha only one, why???????
    there is any idea - please
  18. #10
  19. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2002
    Location
    Queensland, Australia
    Posts
    827
    Rep Power
    146
    Originally Posted by phpfresh
    this will refresh the captcha only one, why???????
    there is any idea - please
    After you open the page in your browser, view the page source and you'll see why it changes just once.

    Having seen how you've designed this, Catacaustic is correct--you need to use AJAX to perform a call to captcha.php.
    Ooh, they have the Internet on computers now!
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Location
    india
    Posts
    34
    Rep Power
    10
    but i don't known ajax please give some code example or please change my given code with suitable ajax format
  22. #12
  23. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,472
    Rep Power
    2106
    Ajax is nothing special. It's just JavaScript to do a call back to your server without refreshing the page.

    The easist way to do this is to look at one of the many JS libraries out there. I'd personally recommend jQuery for this as it seems ot be the most user-friendly, and has the biggest user-base for help if you get stuck. You should have a look at that, do some learning and try and figure it out. You won't learn anything new from us doing all the work for you.
  24. #13
  25. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2002
    Location
    Queensland, Australia
    Posts
    827
    Rep Power
    146
    Originally Posted by phpfresh
    but i don't known ajax please give some code example
    that's why you need to ask in the Javascript forum, not the PHP forum.
    Ooh, they have the Internet on computers now!
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2010
    Location
    india
    Posts
    34
    Rep Power
    10
    thanks everybody who help me i search in javascript forum DrWorm thank you so much if i got answer, i will inform you.

IMN logo majestic logo threadwatch logo seochat tools logo