1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to populate Form field

Discussion in 'PHP' started by chrisj, Oct 5, 2014.

  1. #1
    I have an Upload Form where an image is chosen to be uploaded and the code generates a new file name for it, and then moves the file to the uploads/ folder. Upon Submit the link info - to that image displays - (on the next page) - see code below- How can that link info (instead of being displayed) automatically populate a Form field, before the Form gets submitted? Any help will be appreciated.

      
    if ($form_submitted == 'yes') {
        $allowedExts = array("gif", "jpeg", "jpg", "png");
        $temp = explode(".", $_FILES["file"]["name"]);
        $extension = strtolower( end($temp) );
        if (  $_FILES["file"]["size"] < 2000000
        && in_array($extension, $allowedExts) )
        {
        if ($_FILES["file"]["error"]!= 0)
        {
        echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
        } else {
        $length = 20;
        $randomString = substr(str_shuffle(md5(time())),0,$length);
        $newfilename = $randomString . "." . $extension;
        move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $newfilename );
        $file_location = '<a href="http://www.---.com/upload/' . $newfilename . '">http://www.---.com/upload/' . $newfilename . '</a>';
        echo $file_location;
        }
        } else {
                echo "Invalid upload file";
              }
          $description = $description . " \n " . $newfilename;
            }
    
    PHP:


            
    <form enctype="multipart/form-data" action="uploader.php" method="POST">
              <!--<form name="form_upload" action="uploader.php" method="post">-->
    
                <div id="upload-video">
                  <ul>
                    <li style="width:240px; text-align:right;"><strong>[var.lang_title]:</strong></li>
                    <li style="width:400px; text-align:left;"><input name="title" type="text" class="upload-video-form-input" value="[var.title]" size="38" />
                    </li>
    
                    <li style="width:240px; text-align:right;"><strong>[var.lang_description]:</strong></li>
                    <li style="width:400px; text-align:left;"><textarea rows="4" name="description" cols="29" class="upload-video-form-input">[var.description]</textarea>
                    </li>
    
                    <li style="width:240px; text-align:right;"><strong>[var.lang_tags]:</strong></li>
                    <li style="width:400px; text-align:left;"><input name="tags" type="text" class="upload-video-form-input" value="[var.tags]" size="38" />
                    </li>
    
                    <li style="width:240px; text-align:right;">&nbsp;</li>
                    <li style="width:300px; text-align:left;" class="upload-video-tags">
                    [var.lang_enter_tags].<br />
                          [var.lang_enter_tags_description].</li>
    
    
                        <li style="width:240px; text-align:right;">
                         <!--<label for="file">Filename:</label>-->
                        <input type="file" name="file" id="file">
    
    
                    <li style="width:240px; text-align:right;"><strong>[var.lang_select_channel]:</strong></li>
                    <li style="width:400px; text-align:left;">
                      <select class="upload-video-form-input" style="width:160px;" size="1" name="channel" onchange="javascript:ahahscript.ahah('[var.base_url]/uploader.php?sub_cat='+ document.form_upload.channel.value, 'sub_change', '', 'GET', '', this);">
                      &nbsp;[var.fields_all;htmlconv=no]</select>&nbsp;([var.lang_select_one])
                    </li>
    
                    <li style="width:240px; text-align:right">&nbsp;</li>
                    <li style="width:380px" class="font5_14"><strong>[var.lang_sub_categories]</strong></li>
    
                    <li style="width:240px; text-align:right"><strong>[var.lang_sub_cat]:&nbsp;</strong></li>
                    <li style="width:400px; text-align:left;" id="sub_change"><select class="upload-video-form-input" style="width:160px;" size="1" name="sub_cat"></select>&nbsp;([var.lang_optional])</li>
    
                    <li style="width:240px; text-align:center">&nbsp;</li>
                    <li class="font5_14" style="width:380px;"><strong>[var.lang_optional_info]</strong></li>
    
                      <li style="width:240px; text-align:right"><strong>[var.lang_location_recorded]:</strong></li>
                      <li style="width:400px; text-align:left;"><input name="location_recorded" type="text" class="upload-video-form-input" value="[var.location_recorded]" size="25" />
                      </li>
    
                      <li style="width:240px; text-align:right"><strong>[var.lang_allow_comm]:</strong></li>
                      <li style="width:400px; text-align:left;">
                      <select class="upload-video-form-input" size="1" name="allow_comments">
                        <option value="yes" selected="selected">[var.lang_yes]</option>
                        <option value="no">[var.lang_no]</option>
                      </select>
                    </li>
    
                      <li style="width:240px; text-align:right"><strong>[var.lang_allow_embed]:</strong></li>
                      <li style="width:400px; text-align:left;">
                      <select class="upload-video-form-input" size="1" name="allow_embedding">
                        <option value="yes" selected="selected">[var.lang_yes]</option>
                        <option value="no">[var.lang_no]</option>
                      </select>
                    </li>
    
                      <li style="width:240px; text-align:right"><strong>[var.lang_private_pub]:</strong></li>
                      <li style="width:400px; text-align:left;">
                         <select class="upload-video-form-input" size="1" name="public_private">
                           <option value="public" selected="selected">[var.lang_public]</option>
                           <option value="private">[var.lang_private]</option>
                         </select>
                       </li>
    
                       <li style="width:240px; text-align:right">&nbsp;</li>
                       <li style="width:400px; text-align:left;">
                         <input class="button-form" type="submit" value="Next &gt;&gt;" name="B3" />
                       </li>
                     </ul>
                </div>
                <input class="upload-video-form-input" type="hidden" name="form_submitted" value="yes" />
              </form>
              <div class="clear-fix"></div>
            </div>
          <div class="container-wide-footer"></div>
    HTML:
     
    Last edited: Oct 5, 2014
    chrisj, Oct 5, 2014 IP