searls03 Posted May 25, 2011 Share Posted May 25, 2011 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 https://forums.phpfreaks.com/topic/237457-grab-form-value-before-submission/ Share on other sites More sharing options...
Pikachu2000 Posted May 25, 2011 Share Posted May 25, 2011 You can't use php to get a form value before the form is submitted. Link to comment https://forums.phpfreaks.com/topic/237457-grab-form-value-before-submission/#findComment-1220199 Share on other sites More sharing options...
searls03 Posted May 25, 2011 Author Share Posted May 25, 2011 What can I use then Link to comment https://forums.phpfreaks.com/topic/237457-grab-form-value-before-submission/#findComment-1220200 Share on other sites More sharing options...
fugix Posted May 25, 2011 Share Posted May 25, 2011 sounds like you would want to use ajax Link to comment https://forums.phpfreaks.com/topic/237457-grab-form-value-before-submission/#findComment-1220202 Share on other sites More sharing options...
searls03 Posted May 25, 2011 Author Share Posted May 25, 2011 Do you have any idea what it would be called? Link to comment https://forums.phpfreaks.com/topic/237457-grab-form-value-before-submission/#findComment-1220203 Share on other sites More sharing options...
fugix Posted May 25, 2011 Share Posted May 25, 2011 Do you have any idea what it would be called? what do you mean? Link to comment https://forums.phpfreaks.com/topic/237457-grab-form-value-before-submission/#findComment-1220212 Share on other sites More sharing options...
searls03 Posted May 25, 2011 Author Share Posted May 25, 2011 what is the ajax called? I never used ajax before? or how do I set it up? Link to comment https://forums.phpfreaks.com/topic/237457-grab-form-value-before-submission/#findComment-1220214 Share on other sites More sharing options...
fugix Posted May 25, 2011 Share Posted May 25, 2011 this will help Link to comment https://forums.phpfreaks.com/topic/237457-grab-form-value-before-submission/#findComment-1220229 Share on other sites More sharing options...
searls03 Posted May 25, 2011 Author Share Posted May 25, 2011 what would be a good google search? I cant seem to find anything at all Link to comment https://forums.phpfreaks.com/topic/237457-grab-form-value-before-submission/#findComment-1220233 Share on other sites More sharing options...
fugix Posted May 25, 2011 Share Posted May 25, 2011 did you click on the link that i provided? explains ajax from the people that made it Link to comment https://forums.phpfreaks.com/topic/237457-grab-form-value-before-submission/#findComment-1220237 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.