Jump to content

grab form value before submission


searls03

Recommended Posts

ok, so how can I grab $value before the form submits and I want to put it into the image field:

 

<?php 
include_once "secure/connect_to_mysql.php";

function genRandomString($length = 20) {
     $characters = '0123456789';
     $string ='';    


    for ($p = 0; $p < $length; $p++) {
         $string .= $characters[mt_rand(0, strlen($characters))];
     }

    return $string;

}
if ($_POST['submit']) {
$name = $_POST['name'];
$id = $_POST['id'];
$image = $_POST['image'];
$event = $_POST['event'];
$template  = 'Templates/index.php';
$picture = '$name.png';
$id =  genRandomString(); //this could be the uploaded picture

//we need just the filename - no extension
$picture_name = pathinfo($picture, PATHINFO_FILENAME);
$sql = "INSERT INTO pictures (name, id, image,  event) 
	VALUES('$name', '$id','$image','$event')";
$rs = mysql_query($sql) or die ("Problem with the query: $sql<br>" . mysql_error());
	echo mysql_error();
	$target_path = "images/";

foreach ($_FILES["uploadedfile"]["name"] as $key => $value) {
$uploadfile = $target_path . basename($_FILES[uploadedfile][name][$key]);
//echo $uploadfile;
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'][$key], $uploadfile)) { echo $value . ' uploaded<br>'; }
}
copy($template, "$name.php");

}

?>
<form action="new.php" method="post" enctype="multipart/form-data"><input name="name" type="text" /><input name="id" type="hidden" value=<?php echo $id; ?> /><br />
<input name="event" type="text" /><input name="image" type="text" value="images/<?php echo $value; ?>" /><input type="hidden" name="MAX_FILE_SIZE" value="900000000000000000000000000000000000000000000000000000000000000000000000000" />
Choose a file to upload:

     <div id="dynamicInput">
          Entry 1<br><input type="file" name="uploadedfile[]">
     </div>
     <input type="button" value="Add another text input" onClick="addInput('dynamicInput');">
<br /><input name="submit" type="submit" value="submit" /></form>

 

if I do it after the form submits then it shows up, is there a way to make it appear before it submits....like a second field echoing what the first field has typed it and it updates "live"?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.