OttawaProgram
OttawaProgram

Reputation: 1

Cannot pass textarea input to PHP variable

To begin, I'm working with 3 languages. HTML, Javascript and PHP. I'm unable to pass user inputted textarea text to a PHP variable which would be used as a message in an email that would be sent out. What I believe to be the problem is that my textarea is actually in a modal window and for some reason I think that is what is screwing things up.

Here is my HTML Code:

<div class="rejectModal" title="rejectModal" id="rejectModal" style="display: none; padding:15px ">          
    <form name="rejectForm" action="">

    <textarea id="rejectArea" name="rejectArea" rows="6" cols="43">{$rejectAreaNote}</textarea> 


    <input type="button" value="Reject" class="btn success" id="submitReject" name="Reject" />

    <input class="btn" type="reset" value="Cancel" id="btnCancelSaveModal"  />
    </form>
</div>

JS Code:

$(function() {  
$(".submitReject").click(function() {  
    // validate and process form here  
    $('.error').hide();  
    var rejectAreaNote = $("textarea#rejectArea").val();  
    var noteLength = rejectAreaNote.length;
    if (rejectAreaNote == "" || noteLength < 5) {  
        $("label#rejectArea_error").show();  
        $("textarea#rejectArea").focus();  
        return false;  
    }  
    var dataString = rejectAreaNote;  

    alert (dataString);
    //return false;  

$.ajax({  
    type: "POST",  
    url: "gs_ViewDocument.php",  
    data: {
        "Reject" : "Reject",
        "rejectAreaNote" : "rejectAreaNote"
    },
    success: function() {  
        $('#reject_form').html("<div id='message'></div>");  
        $('#message').html("Reject Submitted!");
    }  
});  
    return false;  
 });  

});

What creates the Modal (JS):

    $('.rejectModal').css("background", "lightblue");
          $('#btnRejectDocument').bind(isTouchScreen ? "touchstart" : "click", function(){
       if (!gsSelection.unselectElem()) return false; 
           $('.rejectModal').dialog({
           modal:true, 
           resizable:false,
        width: 400,
    }).removeClass("ui-widget-content");
    $(".ui-dialog-titlebar").hide();
    return;
 });
$('#btnRejectDocumentModal').bind(isTouchScreen ? "touchstart" : "click", function(){
   $(this).parents('div.rejectModal').dialog('close');
});
$('#btnCancelSaveModal').bind(isTouchScreen ? "touchstart" : "click", function(){
   $(this).parents('div.rejectModal').dialog('close');
});

PHP Code:

if(isset($_POST['Reject'])&&$_POST['Reject']=='Reject')     
 {
      $isReject = true;
      RejectAction($DocumentID, $ClientName, $ClientEmail);
      $smartyvalues["isReject"] = $isReject;
      $smartyvalues["RejectMsg"] = "successfully rejected!";
 }

Also pretty new tot his Any help is greatly appreciated.

Upvotes: 0

Views: 1035

Answers (2)

a sad dude
a sad dude

Reputation: 2825

if(isset($_POST['Reject']) ...

You are not sending this to the server. Instead, you're sending "dataString", which is just the text from textarea. What you should do instead is send an object with needed fields:

    $.ajax({  
        type: "POST",  
        url: "gs_ViewDocument.php",  
        data: {
            "Reject" : "Reject",
            "rejectAreaNote" : "rejectAreaNote"
        },
        success: function() {  
            $('#reject_form').html("<div id='message'></div>");  
            $('#message').html("Reject Submitted!");
        }  
    });  

I'm still not sure what your code is supposed to do and how it glues together, but this here is definitely wrong.

Upvotes: 1

mblitz
mblitz

Reputation: 189

Textarea does not have a value attribute. If you want to add a value to your textarea, add it inside the tag: <textarea>value</textarea> So try changing it to this:

<textarea id="rejectArea" name="rejectArea" rows="6" cols="43"/>{$rejectAreaNote}</textarea>

Upvotes: 5

Related Questions