Jump to content

Post name 'notes' is skewed during actual post


n1concepts

Recommended Posts

Hi,

 

Can someone explain to me the reason why $_POST['notes'] keeps getting altered to '¬es=null' as in the example below from the PHP cURL code?

 

Results: contact_title=mr&first_name=john&last_name=doe¬es=null&submit=submit

 

Notes that $_POST['notes'] is displayed in the string as '¬es' and the '&' sign is even missing when appending to string.

Now, the strange thing about it is if you change the name for that field to something other than 'notes' it works without an issue as shown below:

 

contact_title=mr&first_name=john&last_name=doe&comments=null&submit=submit

Notice: I changed the field name to 'comments' and that field name appended properly to the string as '&comments'

 

My issue is I have to use the field name 'notes' for the textarea box b/c the 3rd party source that needs to receive the data requires that name.

Plus, I have to use cURL to post the data so I can force the redirect to our confirmation page instead of theirs - therefore, standar post method won't work.

 

I think I have the cURL part to grab and sumbit the form data correct and will test that soon as I can get past the 'notes' field issue - just need to update the URL for redirect but I can't figure out why the 'notes' textarea name getting distorted on post - I'm stuck! :)

 

Here's the code which when loaded in php file, should echo the $_POST string when submit button clicked in form:

 

<?php


//create array of data to be posted
if (isset($_POST['submit'])) {


   // setting default values if empty
        if ($_POST['notes'] =='') {
        $_POST['notes'] = 'null';
    }


//  THE ONE IN QUESTION IS:  $post_data['notes']= $_POST['notes'];
    $post_data['contact_title']= $_POST['contact_title'];
    $post_data['first_name']= $_POST['first_name'];
    $post_data['last_name']= $_POST['last_name'];
$post_data['notes']= $_POST['notes'];
    $post_data['submit']= $_POST['submit'];


//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
    $post_items[] = $key . '=' . $value;
}

//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
echo $post_string."<br /><br /><hr />";
// $post_string .= "&notes=".$_POST['notes'];
//echo $post_string;
exit();					// I'm stopping the code here until I can figure out why $post_data['notes'] not displaying correctly

//create cURL connection
// $curl_connection = curl_init('http://xxx.domain.com');

//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 0);

//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

//perform our request
$result = curl_exec($curl_connection);

//show information regarding the request
//print_r(curl_getinfo($curl_connection));
//echo curl_errno($curl_connection) . '-' . curl_error($curl_connection);

//close the connection
curl_close($curl_connection);

unset($_POST['submit']);    // reset field for new post entry to avoid reprocessing old data

// Redirect to confirmation page
header("Location: index.php");        // redirect to Home page once values submitted to remote site for processing
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>

</head>

<body bgcolor="#F2F2E6" topmargin="0">

<div align="center">
  <table border="0" cellpadding="0" cellspacing="0" width="801"  align="center">
  <tr></tr>
  <tr>
    <td valign="top" bgcolor="#FFFFFF" colspan="10">
      <p align="right"></td>
    <td height=""></td>
  </tr>
  <tr>
    <td valign="top" bgcolor="#FFFFFF" rowspan="2" colspan="2"> </td>
    <td valign="top" bgcolor="#FFFFFF" colspan="6" height="2"></td>
    <td valign="top" bgcolor="#FFFFFF" rowspan="2" colspan="3"> </td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF" colspan="2" valign="top" align="left"> </td>
    <td colspan="3" align="left" valign="top" bgcolor="#FFFFFF"><form name="form1" method="post" action="<?php $_SERVER[php_SELF]; ?>">


      <div class="htitle">Contact Information</div>
      <div class="hleftspacer15">
        <table width="550" border="0">
          <tr>
            <td width="135" class="smalltext1">Job Title</td>
            <td width="405"><input name="contact_title" type="text" id="contact_title" tabindex="70"></td>
          </tr>
          <tr>
            <td class="smalltext1">First Name <span class="redAsterisk">*</span></td>
            <td><input name="first_name" type="text" id="first_name" tabindex="75">
		</td>
          </tr>
          <tr>
            <td>Last Name <span class="redAsterisk">*</span></td>
            <td><input name="last_name" type="text" id="last_name" tabindex="80">
		</td>
          </tr>
          <tr>
            <td width="135" align="left" valign="middle" class="smalltext1">Comments</td>
            <td width="405">
              <textarea name="notes" id="notes" cols="35" rows="4" tabindex="65"></textarea>
              </td>
          </tr>
        </table>
      </div>

      <div class="sbtn">
        <input name="submit" type="submit" value="submit" tabindex="900" id="submit" />

    </form></td>
    <td valign="top" bgcolor="#FFFFFF" height="119"> </td>
  </tr>
  <tr>
    <td></td>
    <td bgcolor="#FFFFFF" height="33" colspan="10"><p align="center"></td>
  </tr>

  </table>
</div>

</body>

</html>

Link to comment
Share on other sites

Copy and load the entire script and you'll see the form which contains the four fields (3 text and the 1 textarea field which is name 'notes').

The form is basic and although there is cURL code that's not impacting what should be happening - I just defined a basic 'foreach' loop and parsing through the array - adding the four fields to $post_data[] to prepare to be sent w/cURL.

 

Again, the problem is when you submit the form, the string that is produced show $_post['notes'] alters in name and the '&' sign which is required to append the field to string also changed so I know something is seeing those characters incorrectly and changing them.

 

Reason: if you change $post_data['notes'] to something other than 'note' and resubmit, it works just fine.

For example: change $post_data['notes'] to $post_data['comments'] and notice the difference in string - the '&' sign then appears and 'comments' is correctly displayed in the string.

 

That's what I can't figure out: I have to get 'notes' to display correctly as that's what's expected on the receiving side which I have no control to change...

Link to comment
Share on other sites

Oh, I was trying to help you by suggesting some simple de-bugging.  But, I did as you suggested, and loaded the form.  Filled it out and submitted it.  I found that it passed this string:

contact_title=Big Cahuna&first_name=Jerry&last_name=Bones&notes=Show me the money&submit=submit

 

I would also suggest that it is working on your end. Perhaps your "source" is mis-leading you.

Link to comment
Share on other sites

I'd guess your problem isn't that your $_POST['notes']/$post_data['notes'] is wrong, but rather that your just not displaying it right when you output it.

 

¬ is the entity name for the character your seeing (see http://www.w3.org/TR/html4/sgml/entities.html#h-24.2.1)

 

When you output your imploded string, your generating the output  something like 'last_name=kicken&notes=bleh', your browser is likely interpreting that &not sequence as the entity name.

 

You need to run your string through htmlentities() first so the & gets output as & (the entity for &) and the browser displays it correctly.

 

Tip, use your browser's View-Source function, you'll see what you expect, rather than the funky character.

 

Link to comment
Share on other sites

Wow! I see that it did work for you...

Now, I'm really tripping.... thx!

 

One last question: you you know of any method where you can post data to a 3rd party form and control the redirect after that data submission?

Other than what I've defined using cURL?

 

I need to make an API call to submit the data in some method but then keep the user from being redirected on their page b/c it's just raw unstructured xml code; when users see that data it appears as if there is an error. therefore, i want to redirect them to our own confirmation page. You can see what I did from the code I provided but it (for some reason) not working w/vendor - but it works fine on my test site.

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.