Jump to content

Chrisj

Members
  • Posts

    537
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by Chrisj

  1. I'm using an upload script (I did not write it) that works successfully.

     

    I'm trying to add the function where you 'must check box to agree to terms' prior to uploading a file.

     

    I've added lines 67 thru 75, and lines 88 thru 92, but it is missing something, because, whether the box is checked or not, a file can still be uploaded.

     

    Any guidance will be appreciated.

    <?php
    session_start();
    require_once 'phps3integration_lib.php';
    $message = "";
    if (@$_POST['submit'] != "") {
    $allowed_ext = array("gif", "jpeg", "jpg", "png", "pdf", "doc", "docs", "zip", "mov", "MOV", "flv", "mp4", "3gp", "3GP");
    $extension = end(explode(".", $_FILES["file"]["name"]));
    if (($_FILES["file"]["size"] < 10485760000) && in_array($extension, $allowed_ext)) {
    if ($_FILES["file"]["error"] > 0) {
    //$message.="There is some error in upload, see: " . $_FILES["file"]["error"] . "<br>";//Enable this to see actual error
    $message.="There is some error in upload. Please try after some time.";
    } else {
    $uploaddir = '../Upload/';
    $uploadfile = $uploaddir . basename($_FILES['file']['name']);
    $uploaded_file = false;
    if(move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile))
    {
    $uploaded_file = $_FILES['file']['name'];
    }
    if ($uploaded_file != FALSE) {
    $user_name = @$_POST['user_name'] != "" ? @$_POST['user_name'] : "Anonymous";
    $form_data = array(
    'file' => $uploaded_file,
    'user_name' => $user_name,
    'type' => 'file'
    );
    mysql_query("INSERT INTO `phps3files` (`id`, `file`, `user_name`, `type`) VALUES (NULL, '" . $uploaded_file . "', '" . $user_name . "', 'file')") or die(mysql_error());
    $message.= "File Successfully Uploaded";
    } else {
    $message.="There is some error in upload. Please try after some time.";
    }
    }
    } else {
    $message.= "Invalid file, Please upload a gif/jpeg/jpg/png/pdf/doc/docs/zip/mov/flv/mp4/3gp file of maximum size 25 MB.";
    }
    }
    ?>
    
    <?php
    require_once 'header.php';
    ?>
    <head>
    
    <script>
    var ids = ['input', 'message', 'button'];
    var obj = {};
    
    ids.forEach(function (v) {
        obj[v] = document.getElementById(v);
    });
    
    obj.input.style.display = 'none';
    obj.button.style.display = 'block';
    
    obj.input.addEventListener('change', function () {
        obj.message.innerText = this.value;
        obj.message.style.display = 'block';
    });
    
    obj.button.addEventListener('click', function (e) {
        e.preventDefault();
    
        obj.input.click();
    });
    </script>
    
    <script type="text/javascript">
    function validate()
    {
    if(false == document.getElementById("agree").checked)
    {
    alert("If you agree with the terms, check the Agree check box");
    }
    }
    </script>
    
    </head>
    <html>
    <fieldset>
    <form action="" method="post" enctype="multipart/form-data">
    
    <div class="control-group">
    <label for="file" class="control-label"><font size="6" color="#454545"><b>Choose a file to upload:</b></font></label><br /><br />
    <input id="input" name="file" type="file" /></input>
    <button id="button"><font size="3" color="#454545">Click To<br /> Select File</font></button>
    <div id="message"><font size="3" color="#454545">No File Chosen</font></div>
    </div>
    <div>
    <input type="checkbox" name="agree" id="agree" value="agree" /> <label for='agree'>
    <a href="../Terms1.php" target="_blank"><span style="color: #454545; font-size: 10px">By uploading a file here, you agree to these <u>Upload Terms/Agreement</u></a></span>
    </label>
    </div>
    <div class="control-group">
    <div class='controls'>
    <label class="myLabel1">
    <input type="submit" name="submit" value="Submit" class="btn" style="opacity: 0">
    </label><
    </div>
    </form>
    </fieldset>
    
    <script>
    var ids = ['input', 'message', 'button'];
    var obj = {};
    
    ids.forEach(function (v) {
        obj[v] = document.getElementById(v);
    });
    
    obj.input.style.display = 'none';
    obj.button.style.display = 'inline-block';
    
    obj.input.addEventListener('change', function () {
        var filename = this.value.replace(/^.*[\\\/]/, '');
    		obj.message.innerHTML  = filename;
        obj.message.style.display = 'inline-block';
    });
    
    obj.button.addEventListener('click', function (e) {
        e.preventDefault();
    
        obj.input.click();
    });
    
    </script>
    <?php
    if ($message != "" || @$_SESSION['message'] != "") {
        ?>
        <div class="alert alert-success">
        <?php echo $message; ?>
        <?php
        echo @$_SESSION['message'];
        @$_SESSION['message'] = '';
        ?>
        </div>
        <?php
    }
    ?>
    <div>
    </div>
    
    <?php require_once 'footer.php'; ?>
    
    
    
  2. Thanks for your replies.

     

    Regarding "show us the code", I have showed the php in the intial posting, and here is the Form:

    <form action='../ContactForm.php' method='post' name='myform' onSubmit="return checkemail()">
    <div class="row">
    <div class="col-sm-4">
    <input class="form-control" type="text" name='contact_name' placeholder="Name">
    </div>
    <div class="col-sm-4">
    <input class="form-control" type="text" name='email_address' placeholder="Email">
    </div>
    </div>
    <br>
    <div class="row">
    <div class="col-sm-12">
    <textarea name='Description' placeholder="Type your message here..." class="form-control" rows="9"></textarea>
    </div>
    </div>
    <div class="row">
    <div class="col-sm-4">
    <p style="color:grey; font-size:15px;"><b>Security Question:<br> Is Fire Hot Or Cold?:</p>
    <input type="text" name="ans"/><br>
    <div>
    <div class="row">
    <div class="col-sm-4">
    <input class="btn btn-action" type='submit' value="Send message">
    </div>
    </div>
    </div>
    </form>
    

    Regarding "Can you assign a header call to a variable?", I'm not clear on that. Is my url(s) the variable?

    Any clarification, and/or code tweak suggestion will be greatly appreciated.

  3. Thanks so much for your reply.

    Yes, I have this input field:

    <input type="text" name="ans"/>
    

    which works successfully from my windows desktop. After entering 'hot' and select 'Send Message' I am successfully directed to the page(I've changed the url for this posting) listed here"

    // if no errors are set, continue
    if(empty($error))
    {
    header('Location: ww.somesite.com/ThankYou.html');
    exit;
    }
    

    And also, from my desktop if I enter anything other than 'hot', and select 'Send Message', I'm successfully directed to the page listed here:

    $error[] = header('Location: ww.somesite.com/WrongAnswer.html');
    exit;
    

    But from my iPhone when I enter 'hot' (or anything else) and select either 'Send Message", Done(on the phone) and then 'Send Message', or 'Go'(on the phone), no matter what, I'm directed to this page:

    ww.somesite.com/WrongAnswer.html
    

    So, if it's true that "Entering text on a mobile is no different than a fixed desktop", than obviously and not surprisingly, my code needs some type of correction/modification.

     

    Any ideas/suggestions will be appreciated.

    Much thanks again

  4. I realize this is old code (that I didn't write) but works well for a temporary 'under construction' page.
    After filling in the simple Form fields the simple Security question is presented : Is fire Hot or Cold?
    When I enter text into the answer field it works successfully, except, of course on a mobile device. In order for it to work on a mobile device, I believe I need to present a choice, rather than entering text - correct?
    So, I'm looking for a possible simple tweak on this code, so that it will work for a mobile device, please. I don't really want to re-write all of it, and I know it's not super-secure, but it will do for now.
     
    Here's the last part of the Form:
     
    <div>
    <p>Security Question:<br> Is Fire Hot Or Cold?:
    <input type="text" name="ans"/></p><br>
    <p><input class="btn btn-action" type='submit' value="Send message"></p>
    </div>
    </form>
    
    And
     
    
    <?php
    // create an empty error array to hold any error messages\
    $error = array();
    $mailto     = 'someone@somewhere.com';
    $mailsubj   = "ContactForm Submission";
    $mailhead   = "From:SomehereForm\n";
    $mailbody   = "--- Contact form results ---\n";
    foreach($_REQUEST as $key => $value)
    {
    if($key != 'PHPSESSID')
    {
    $mailbody .= $key.": ".$value."\n";
    }
    }
    if(isset($_POST['ans']) && $_POST['ans']!='hot')
    {
    // add error to error array
    $error[] = header('Location: ww.somesite.com/WrongAnswer.html');
    exit;
    }
    // if no errors are set, continue
    if(empty($error))
    {
    header('Location: ww.somesite.com/ThankYou.html');
    exit;
    }
    ?>
    

    Is it possible to add something like:

    <option value="ans">hot</option>
    <option value="">cold</option>
    

    and then change this somehow:

    $error['anything other than hot'] = header('Location: ww.somesite.com/WrongAnswer.html');
    exit;
    

    Any tweak help will be appreciated.

  5. I have this Contact Form, that I'm trying to add a captcha element to it. The captcha script html part is this:

    <td>
    Enter Image Text<input name="captcha" type="text"><img src="captcha.php" />
    </td>
    

    And it looks like (see attached image)

     

    How can I style this, and also put some space between the text, the field box, and the numbers box, horizontally?

     

    I look forward to some suggestions. Much thanks.

    post-20454-0-38721500-1477527601_thumb.png

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