Jump to content

Recommended Posts

I have a basic contact us form that gets data from another page if there is and leaves the textarea empty if there is none.

 

HTML:

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST" autocomplete="on">
            <div class="ui-contact-form ">
                <span class="icon-user ui-contact-icons"></span><label>Name: </label><input class="input-name"  type="text" name="name"  autofocus/>
            </div>
            <div class="ui-contact-form">
                <span class="icon-list ui-contact-icons"></span><span>Service of Enquiry: </span>
                <div id="radio" class="btngrp-service" name="btngrp-service1" >
                    <input type="radio" id="radio1" name="btngrp-service" value=1><label for="radio1" class="btngrp-service">Moving</label>
                    <input type="radio" id="radio2" name="btngrp-service" value=2 checked="checked"><label for="radio2" class="btngrp-service">Delivery</label>
                    <input type="radio" id="radio3" name="btngrp-service" value=3><label for="radio3" class="btngrp-service">Accounting</label>
                    <input type="radio" id="radio4" name="btngrp-service" value=4><label for="radio4" class="btngrp-service">IT</label>
                    <input type="radio" id="radio5" name="btngrp-service" value=5><label for="radio5" class="btngrp-service">Others</label>
                  </div>
            </div>
                <div class="ui-contact-form">
                    <span class="icon-envelop ui-contact-icons"></span><label>E-Mail: </label><input type="email" name="email" />
                </div>
                <div class="ui-contact-form">
                    <span class="icon-phone ui-contact-icons"></span><label>Contact No.: </label><input type="tel" name="contactno" />
                </div>
                <div class="ui-contact-form">
                    <span class="icon-info ui-contact-icons"></span><label>Feedback / Enquiries </label><textarea rows="5" cols="10" name="enquiry" placeholder="Enter your questions here!" ><?php echo htmlspecialchars($enqContent); ?></textarea> 
                </div>
                <input type="submit"/>
            </form>
if (isset($_GET['delSpeed']) && isset($_GET['delWeight'])) {
    $delSpeed = $_GET['delSpeed'];
    $delWeight = $_GET['delWeight'];
    $enqContent = 'I would like to enquire about a delivery order weighing ';
    $enqContent.= $delWeight .'KG and would require '.$serviceText. ' shipping.';
} else {
    $enqContent = '';
}

And I validate the other fields making sure the user has entered something and not left it empty

$nameErr  = $emailErr = $contactErr = $enquiryErr = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$valid = true;
var_dump($enqContent); <-- already cut off here

if (empty($_POST["name"])) {
    $nameErr = "<span>Please enter a valid name</span>";
    $valid = false;
}
else {
    $name = $_POST["name"];
    $_SESSION['name']=$name;
}

if (empty($_POST["email"]))  { 
    $nameErr = "<span>Please enter a valid email</span>";
    $valid = false;
    $emailErr = "Missing";
}
else {
    $email = $_POST["email"];
    $_SESSION['email'] = $email;

}
if (empty($_POST["contactno"])) { 
    $nameErr = "<span>Please enter a valid contact number.</span>";
    $valid = false;
    $error = "error";
}
else {
    $contactNum = $_POST['contactno'];
    $_SESSION['contactno'] = $contactNum;
}

if(empty($_POST['enquiry'])) {
    $nameErr = "<span>Please enter valid content to help us serve you better.</span>";
}
else {
    $enquiry = $_POST['enquiry'];
    //$_SESSION['enquiry'] = $enquiry;
    var_dump($enquiry);
}
if($valid) { 
    //trim input
    print_r($_POST);
    $serviceType = $_POST['btngrp-service'];
    $_SESSION['btngrp-service'] = $serviceType;
    //header('Location: http://localhost/ppsv2/submit.php');
}

As you can see after the IF, I check for the input that came from the other page, the string gets cut off and I have no idea why. When I press submit to check what string I get from $enqContent, this is what I get. I have tried bumping up max_input_vars and post_max_size and nothing seems to work.

I would like to enquire about a delivery order weighing 12KG and would%.

I would like to know what is causing this and what is the solution to it. Thanks!

Link to comment
https://forums.phpfreaks.com/topic/290247-string-gets-cut-off/
Share on other sites

there's nothing in the posted code that would cause the problem.

 

however, given your class="...." naming in all the html markup, i suspect you have some client-side code, that's likely causing this. what's all the relative code on the page(s) that would be needed to reproduce the problem?

Link to comment
https://forums.phpfreaks.com/topic/290247-string-gets-cut-off/#findComment-1486742
Share on other sites

 

As you can see after the IF, I check for the input that came from the other page, the string gets cut off and I have no idea why. When I press submit to check what string I get from $enqContent, this is what I get. I have tried bumping up max_input_vars and post_max_size and nothing seems to work.

I would like to enquire about a delivery order weighing 12KG and would%.

Is that the value you get after the form has been submitted? Shouldnt you be using  $_POST['enquiry']  not  $enqContent  when checking the value submitted from the form?

Link to comment
https://forums.phpfreaks.com/topic/290247-string-gets-cut-off/#findComment-1486743
Share on other sites

there's nothing in the posted code that would cause the problem.

 

however, given your class="...." naming in all the html markup, i suspect you have some client-side code, that's likely causing this. what's all the relative code on the page(s) that would be needed to reproduce the problem?

 

Basically I get 2 values from another page and puts them into the if loop. If there are values $enqContent gets populated with the values and creates a template sentence to put inside the textarea, if there isn't it just leaves the textarea blank. The problem seems really erratic. I could type 1 2 3 4 5 6 7 8 9 0 and I would get 

1 2 3 4 5%2

It seems like the last spacing always gets the %2 like it's trying to do a html style of spacing which is %20 but I cannot be sure. I have checked through my styles and they have nothing to do with it being like this.

 

Is that the value you get after the form has been submitted? Shouldnt you be using  $_POST['enquiry']  not  $enqContent  when checking the value submitted from the form?

 

Fixed but the error still persists. Thanks for pointing it out!

Link to comment
https://forums.phpfreaks.com/topic/290247-string-gets-cut-off/#findComment-1486746
Share on other sites

Do you have any JavaScript in your 'form' page? 

 

What I would do would be to create a simple, mostly empty, HTML page with your needed form (without any code) that posts to your PHP file. Then, 'echo()' the string that was cut.

 

If it works, the problem is with the 'client side script, meaning probably some JavaScript that does something weird before posting the data.

If this doesn't work, the problem is not the client, you'll then know that you need to search on the server or 'in between' (a proxy, a browser pluging, something else).

 

Did anybody else tried your form or only you? Did you try on different browsers and computers?

Link to comment
https://forums.phpfreaks.com/topic/290247-string-gets-cut-off/#findComment-1486800
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.