SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    grab texxt, insert values into form

    I am not sure if this is the right place....
    what I am looking for is a code that when I click on a link, the value given will go into a text box from a form.

    I tried using a code that had 2 forms that allowed a transfer of info- but that didnt really work for me too well.

    I saw a page on a game (travian) that listed an amount to the right of the text box and clicking on that amount meant that the info would then be moved into the text box

    Im looking at this as users are allowed to edit their own work, and it would be easier than to try and copy their info and paste it in (if they dont do it, their info is deleted)

    I know some of my text will be longer than just a small word (paragraphs), but I am interested if its possible to do such a large transfer of info (I have several text boxes within my form that I would like this to work on.)

    any suggestions?

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You will need to explain this further, or at least provide what you have at hte moment.


  3. #3
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont have anything, thats why Im looking for something.

    what Im looking for::

    I have information stored in my database that gets outputted with the following variables (php codes):: $profession, $joke, $love, $book, $insult, $any

    These variables are shown on the page (if they are in the database). I then have a form on the left part of the page. When the form is filled out- the values update the database and therefore the variables.

    The problem comes in, when the user goes to update the database, I would liket o keep the textareas clear of writing, but have the variables be links of stored information that when clicked can be placed into the textarea instead of highlighting and copying then pasting.

    THe only examples Ive been able to find are
    http://javascript.internet.com/forms...tact-info.html

    that is the closest I have come so far, but I cant seem to implement it correctly.


    here is the code that I have and am trying to get it placed into::

    PHP Code:
    <?php
    session_start
    ();

    // is the one accessing this page logged in or not?
    if (!isset($_SESSION['db_is_logged_in'])
       || 
    $_SESSION['db_is_logged_in'] !== true) {

       
    // not logged in, move to login page
       
    header('Location: activate.php');
       exit;
    }


    include(
    'connect.php');
    ?>

    <?php
           $images_dir 
    'uploads';

        
    $uid   $_SESSION['id'];
        
    $se $_SERVER['PHP_SELF'];  

     


        
        
    // check if the user id and password combination exist in database
        
    $result mysql_query"SELECT * FROM wot_user WHERE id='$uid'" );
            list(
    $id$userid$password$fullname$email$notes$image) = mysql_fetch_array$result );

        
    $nr mysql_num_rows$result );
            
    mysql_free_result$result );    
                    
    $notes stripslashes(nl2br($notes));  
                    
    $nota eregi_replace('<br />'''$notes);
                    
    $fullname stripslashes($fullname);
         
            if( empty( 
    $nr ) )
            {
                
    $result_final "\n\t 
                              
              
                          <div id='text' style='position:absolute; left:2%; top:2%; width:50%; z-index:1'> 
                          No User found with this name, please try again.</div>
                         
                         "
    ;
            }
            else
            {


                
    $result_final "\n\t";







        

      if (isset(
    $_POST['joke'])):
      
    // The author's details have been updated.
      
      
    $joke mysql_real_escape_string(stripslashes(nl2br(htmlspecialchars($_POST['joke']))));
      
    $age mysql_real_escape_string(stripslashes(nl2br(htmlspecialchars($_POST['age']))));  
      
    $gender mysql_real_escape_string(stripslashes(nl2br(htmlspecialchars($_POST['gender']))));
      
    $love mysql_real_escape_string(stripslashes(nl2br(htmlspecialchars($_POST['love']))));
      
    $book mysql_real_escape_string(stripslashes(nl2br(htmlspecialchars($_POST['book']))));
      
    $insult mysql_real_escape_string(stripslashes(nl2br(htmlspecialchars($_POST['insult']))));   
      
    $any =  mysql_real_escape_string(stripslashes(nl2br(htmlspecialchars($_POST['any']))));
      
    $profession =  mysql_real_escape_string(stripslashes(nl2br(htmlspecialchars($_POST['profession']))));
      
    $pid $_POST['pid'];
      
       
    $sql "UPDATE wotpics SET
              joke = '
    $joke',
              userids ='
    $id',
              gender = '
    $gender',
              profession = '
    $profession', 
              book = '
    $book',
              insult = '
    $insult',
              any = '
    $any',
              age = '
    $age', 
              love = '
    $love',          
              commentdate=NOW() 
              WHERE photoid = '
    $pid'";
              
              
      if (@
    mysql_query($sql)) {
                                
    $Referer $_SERVER['HTTP_REFERER'];
    echo 
    "<meta http-equiv= 'refresh' content='0;url=$Referer'>";
     


      } else {
        echo 
    '<p>Error updating author details: ' .
            
    mysql_error() . '</p>';
      }
         

    else: 
    // Allow the user to edit the author

            
      
    $picd $_GET['id'];
      
    $author = @mysql_query(
          
    "SELECT  * FROM wotpics WHERE photoid='$picd'");    
              list(
    $id$name$gender$age$profession$joke$love$book$insult$any$commentdate$timesviewed$userids$photoid$caption$photo_name) = mysql_fetch_array$author );
              
    $ida $id 1;
             
    $ids $id 1;          
        
    $mnr mysql_num_rows$author );
            
    mysql_free_result$author );
      if (!
    $author) {
        exit(
    '<p>Error fetching author details: ' .
            
    mysql_error() . '</p>');
      }



      
         


                  
    $result_final "\n\t
         




          <div id='text' style='position:fixed; left:2%; top:10%; width:100px; z-index:5'>
     
    <a href='default.php'>Home</a><br />
    <a href='javascript:history.back()'>Back</a><br /> 
    <a href='http://www.domain.org'>domain</a><br /><br />

    <b>Contestants</b><br />
    <a href='all.php?cont=0'>All</a><br />
    <a href='all.php?cont=m'>Males</a><br />
    <a href='all.php?cont=f'>Females</a><br />
    <br />

    <b>Options</b><br />
    <a href='userlist.php'>User List</a><br />
    <a href='loggedin.php'>User Options</a><br /> 
    <a href='npics.php'>Edit work</a><br /> 
    <a href='edituser.php?uid=
    $uid'>Edit profile</a><br /><br />
                       
    "

    if(
    $uid != "1"){
    $edit = @mysql_query(
          
    "SELECT  * FROM wot_user WHERE id='$uid'");    
              list(
    $id$name) = mysql_fetch_array$edit );
              
        
    $mnr mysql_num_rows$edit );
            
    mysql_free_result$edit );
      if (!
    $edit) {
        exit(
    '<p>Error fetching author details: ' .
            
    mysql_error() . '</p>');
      }     
      
    $edita = @mysql_query(
          
    "SELECT  * FROM wotpics WHERE name='$name'");    
              list(
    $id$name) = mysql_fetch_array$edita );
              
        
    $mnr mysql_num_rows$edita );
            
    mysql_free_result$edita );
      if (!
    $edita) {
        exit(
    '<p>Error fetching author details: ' .
            
    mysql_error() . '</p>');
      }                     
              
     
    $result_final .= "\n\t
    <b>Edit Pic</b><br />
    <a href='editwork.php?id=
    $uid'>Your Pic</a><br /><br /> ";

    }else{           

        
    $result_final .= "\n\t
    <b>Edit Pics</b><br />"
    ;
    if(
    $id == 1){
        
    $result_final .= "\n\t
        <a href='editwork.php?id=
    $ida'>Next Pic</a><br /><br />";
    }else{  
     
    $result_final .= "\n\t
    <a href='editwork.php?id=
    $ids'>Prev Pic</a><br /> 
    <a href='editwork.php?id=
    $ida'>Next Pic</a><br /><br />";
           }


      
    $result_final .= "\n\t

    <b>Admin</b><br /> 
    <a href='signup.php'>Signup</a><br />
    <a href ='loggedin.php'>Login</a><br />
    <a href='logout.php'>Logout</a>
    </div>                            

    <div id='text' style='position:absolute; left:130px; top:10%; width:45%; z-index:4'>
    <img src='"
    .$images_dir"/".$photo_name."' width='80%' height='80%' />
    <br /> 

                
    <br /><br />            
    <form action='
    $se' method='post'>

    Edit Your Page. Please post all information. <br />
    If need be, just copy from the right.<br /><br />
    <label>Name: 
    $name</label><br />
    <label>Age:<br /> 

      <select name='age' size='1'>"
    ;
    for (
    $count 10$count <= 70; ++$count) {
      
    $result_final .= "\n\t 
      <option value='
    $count'>$count</option>"

      
    $result_final .= "\n\t             
    </select>
    </label><br /> <br /> 
    Gender:<br /><label> <input type='radio' name='gender' value='Female'> Female<br /></label>
             <label> <input type='radio' name='gender' value='Male'  CHECKED > Male<br /> </label>


    <br />  
    <label>Profession:<br /> <input type='text' name='profession' value=''  rows='10' cols='50'/></label><br /><br />
    <label>Favorite Joke:<br /> <textarea name='joke' value=''  rows='10' cols='50'/></textarea></label><br /><br />
    <label>Favorite Char:<br /> <textarea name='love' value=''  rows='10' cols='50'/></textarea></label><br /> <br />   
    <label>Favorite Book Char:<br /> <textarea name='book' value=''  rows='10' cols='50'/></textarea></label><br /><br />

    <label>Favorite Insult:<br /> <textarea name='insult' value=''  rows='10' cols='50'/></textarea></label><br /><br />
    <label>Anything else to know:<br /> <textarea name='any' value=''  rows='10' cols='50'/></textarea></label><br />



    <input type='hidden' name='id' value='
    $uid' />
    <input type='hidden' name='pid' value='
    $picd' />


    <input type='submit' value='SUBMIT' /></p>
    </form>
    </div> "
    ;
       
    $picd $_GET['id'];
      
    $author = @mysql_query(
          
    "SELECT  * FROM wotpics WHERE photoid='$picd'");    
              list(
    $id$name$sex$age$profession$joke$love$book$insult$any$commentdate$timesviewed$userids$photoid$caption$photo_name) = mysql_fetch_array$author );
              
        
    $mnr mysql_num_rows$author );
            
    mysql_free_result$author );
    if( 
    $sex == 'F' )
        {                            
            
    $sex 'Female';}
        else{
            
    $sex 'Male';}  
            
                  
    $result_final .= "\n\t 
    <div id='text' style='position:absolute; left:60%; top:6%; width:38%; height:90%; z-index:3'>

      <br />
                            <b>Name:</b> 
    $name<br />  <br />
                        <b>Age:</b> 
    $age<br />    <br />
                        <b>Gender:</b> 
    $sex<br />  <br />
                        <b>Profession:</b> 
    $profession<br />  <br />
                        <b>Favorite Joke:</b><br />
    $joke<br />   <br />
                        <b>Favorite Char:</b><br />
    $love <br />  <br />
                        <b>Favorite Book Char:</b><br />
    $book <br />  <br />    
                        <b>Favorite Insult:</b><br />
    $insult<br />   <br />
                        <b>Anything else to know:</b><br />
    $any<br /> <br />
                                            <b>Last Edited:</b> 
    $commentdate<br /><br />
                        <br />
                        

       
                        </div> 
                    
                              
         
     
                             
                              "
    ;  


               


                         
      
      
                  
    $result_final .= "\n\t 
         
    </div>

           

                           
                    
        
       


    "
    ;
    endif;             

                   }                                                 

         
               
    ?>
     
              
                   <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
        'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
    <html xmlns='http://www.w3.org/1999/xhtml'>
    <head>
    <title>ADD comments</title>
    <meta http-equiv='content-type'
        content='text/html; charset=iso-8859-1' />
    <?php
    include('css.inc');
    ?>
    </head>
    <body>    
    <?php
    echo $result_final;

    ?>
                                 </body></html>

    thats my code for my page, and you can see where it all gets outputted as straight text. As it stands it will not be inputted into the forms unless you copy and paste by hand (I dont want to place the variables as values as it could mess up the new data)

    Im just looking for the script to take the information from the output and place it into the blank textareas (if they do not want to change anyhting in it)

    Hopefully thats a bit clearer

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it would be better to just populate the textarea's/textboxes with the database value.


  5. #5
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    philmont
    Posts
    315
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess, I was just hoping to have some sort of checkbox out for them to click on and it would be filled in, this way- it could be empty if they wanted to delete everything.

    just found this: http://javascript.internet.com/forms/copy-fields.html

    so far, if I type something in and click the box- it will work, but if I add a value to the area, and then check the box, the other info disappears..Ive also tried to populate some of the text with my variables- but nothing is being shown within the textareas.


Bookmarks

Posting Permissions

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