POST & GET methods did'nt work

agmr559

New Member
Messages
6
Reaction score
0
Points
1
Hi friends

I'm newby in this business, and I'm trying get variables from a HTML form.
I tried GET and POST methods, but variables are not recognized in second PHP page, using $_GET and $_POST functions to work variables.
Into localhost work fine, but in x10 don't work
please some help

regards
A. Marambio
 

Salvatos

Member
Prime Account
Messages
562
Reaction score
1
Points
18
Hi, if you want us to be able to help you, you'll have to show us your code (make sure to remove sensitive information like passwords, if any) and point out to the part that doesn't work. Expected behaviour and actual behaviour also help understand the issue.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
A. Copy of the form sending the information
B. Copy of the script
C. How do you know they are not working?
 

garrettroyce

Community Support
Community Support
Messages
5,611
Reaction score
249
Points
63
This can happen if you specify an incorrect form accept-charset. IE, using "UTF8" instead of "UTF-8". I think form encoding could cause the same problem, but I've never verified it.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Note that full source code isn't necessary. More helpful is a minimal code sample, just enough code to be complete and to demonstrate the issue. To describe the problem clearly, state what you expect to happen and what actually happens (including any error messages).
 

agmr559

New Member
Messages
6
Reaction score
0
Points
1
Hi, thanks for yours replays

This is the sending html page:

<BODY>
<FORM METHOD="post" ACTION="send_simpleform.php">
<P><strong>Su Nombre:</strong><br>
<INPUT type="text" NAME="sender_name" SIZE=30></p>
<P><strong>Su E-Mail Address:</strong><br>
<INPUT type="text" NAME="sender_email" SIZE=30></p>
<P><strong>Mensaje:</strong><br>
<TEXTAREA NAME="message" COLS=30 ROWS=5 WRAP=virtual></TEXTAREA></p>
<P><INPUT TYPE="submit" NAME="submit" VALUE="Send This Form"></p>
</FORM>
</BODY>
</HTML>

This is the receiving php page:

<?php
$msg = "ESTOS SON LOS DATOS RECIBIDOS:\n";
$msg .= "Nombre: $_post['sender_name'])\n";
$msg .= "E-Mail: $_post['sender_email']\n";
$msg .= "Mensaje: $_post['message']\n\n";
$to = "maulikan@agmr.x10.bz";
$subject = "Send test";
$mailheaders = "From: Alberto Marambio <> \n";
$mailheaders .= "Reply-To: $sender_email\n\n";
mail($to, $subject, $msg, $mailheaders);
?>

The e-mail is sent, but don't display the data variables.
Also I tried using get method, using " instead ' and specify variable name alone, for example:
$msg .= "Nombre: $sender_name\n";
none of them is working
I'm not specifying charset

regards.
 

callumacrae

not alex mac
Community Support
Messages
5,257
Reaction score
97
Points
48
Please use the
Code:
 tag to display code. Thanks.

Use $_POST, not $_post

Also, your HTML is incorrect. You should be using lower case tags, and you need a doctype and opening HTML tag.

~Callum
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Please use the
Code:
 tag to display code.[/QUOTE]
Or [html] or [php], as appropriate.

Note that, when properly indented, you can see structural problems with your code. 
[html]<BODY>
  <FORM METHOD="post" ACTION="send_simpleform.php">
    <P><strong>Su Nombre:</strong><br>
        <INPUT type="text" NAME="sender_name" SIZE=30></p>
        <P><strong>Su E-Mail Address:</strong><br>
            <INPUT type="text" NAME="sender_email" SIZE=30></p>
            <P><strong>Mensaje:</strong><br>
                <TEXTAREA NAME="message" COLS=30 ROWS=5 WRAP=virtual></TEXTAREA></p>
            <P><INPUT TYPE="submit" NAME="submit" VALUE="Send This Form"></p>
            </FORM>
            </BODY>
          </HTML>
[/html]
The unclosed <input>s and use of the non-[URL="http://webstyleguide.com/wsg3/5-site-structure/2-semantic-markup.html"]semantic[/URL] <br/> should be fixed. <strong> is also misused; it's supposed to denote [URL="http://www.w3.org/TR/html401/struct/text.html#h-9.2.1"]strong emphasis[/URL], not simply a replacement for <b>. You should be using <label> to markup input labels. If you want them to be bold, use styling.

[html]<html>
  <head>
    <style type="text/css">
      label { 
        font-weight: bold; 
        display: block;
      }
      input[type='submit'] {
        display: block;
      }
      input[type='text'],
      input:not([type='submit']),
      textarea#message
      {
          width: 30em;
      }
      textarea#message {
        height: 6em;
      }
    </style>
  </head>
  <body>
    <form method="POST" action="send_simpleform.php">
      <label for="sender_name">Su Nombre:</label>
      <input id="sender_name" name="sender_name" />
      <label for="sender_email">Su E-Mail Address:</label>
      <input id="sender_email" name="sender_email" />
      <label for="message">Mensaje:</label>
      <textarea id="message" name="message" wrap="virtual"></textarea>
      <input type="submit" name="submit" value="send this form" />
    </form>
  </body>
</html>[/html]

[php]<?php
$msg = "ESTOS SON LOS DATOS RECIBIDOS:\n";
$msg .= "Nombre: $_post['sender_name'])\n";
[/php]
Unlike function and class names, variable names are [url=http://php.net/manual/en/language.variables.basics.php]case sensitive[/url]. [FONT="Courier New"]$_post[/FONT] is a different variable from [FONT="Courier New"]$_POST[/FONT].

With [URL="http://us2.php.net/manual/en/language.types.string.php#language.types.string.syntax.double"]heredocs[/URL], you can readily create multiline strings (though it should be noted that quoted strings can also span multiple lines).

[php]<?php
if ("\n" == "\x0D\x0A") {
    $eol = '';
} else {
    $eol = "\r";
}
$to = "maulikan@agmr.x10.bz";
$subject = "Send test";
$mailheaders =<<<EOS
From: Alberto Marambio <> $eol
Reply-To: $sender_email$eol
$eol
EOS;
$msg =<<<EOS
ESTOS SON LOS DATOS RECIBIDOS:$eol
Nombre: $_POST[sender_name]$eol
E-Mail: $_POST[sender_email]$eol
Mensaje: $_POST[message]$eol
$eol
EOS;
if (mail($to, $subject, $msg, $mailheaders)):
    // very basic error handling. More should be done.
    ?>
    <p class="error">Message sent.</p>
<?php else: ?>
    <p class="error">I couldn't send your message. Please try again later.</p>
<?php endif; ?>[/php]
 
Last edited:

callumacrae

not alex mac
Community Support
Messages
5,257
Reaction score
97
Points
48
PHP:
<?php
if ("\n" == "\x0D\x0A") {
    $eol = '';
} else {
    $eol = "\r";
}

Isn't that just
PHP:
$eol = PHP_EOL;
?

~Callum
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Isn't that just
PHP:
$eol = PHP_EOL;
?
PHP_EOL == "\n". The code ensures lines are terminated with CRLF. If "\n" == CRLF, then newlines already contain a "\r". Otherwise, the CR is added. I'm still looking for a more elegant & robust way of using multiline strings with SMTP; a simple regex, perhaps. Or maybe I should just let sendmail handle it.
 
Last edited:

agmr559

New Member
Messages
6
Reaction score
0
Points
1
Hi friends

problem fixed!
the changes were:
1) change all html tags to lowercase in sending page
2) change $_post to $_POST in receiving page

Next I'll follow yours others tips

Thank's a lot for yours support
 

callumacrae

not alex mac
Community Support
Messages
5,257
Reaction score
97
Points
48
PHP_EOL == "\n". The code ensures lines are terminated with CRLF. If "\n" == CRLF, then newlines already contain a "\r". Otherwise, the CR is added. I'm still looking for a more elegant & robust way of using multiline strings with SMTP; a simple regex, perhaps. Or maybe I should just let sendmail handle it.

I thought the point in PHP_EOL was that it worked on any system?

~Callum
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
PHP_EOL works for what it's supposed to do, but "work" is one of those generic verbs that doesn't actually say much by itself. PHP_EOL is the newline for the PHP interpreter's platform. It's useful to output a newline to suit the interpreter's platform, rather than the platform the script was written on.

Under certain circumstances, compilers translate "\n" to "\x0D\x0A". The PHP interpreter will inherit this, as it uses escape characters rather than literals in its scanner. This is the situation where 'PHP_EOL == "\n"' I referred to. This actually doesn't always hold, even on platforms that use CRLF for newlines.

My previous code is wrong in that it targets the interpreter platform, where it should target the authoring platform. Changing "\n" to a literal newline will fix this. We could also add code to support platforms that use line feeds as newlines, though there aren't enough in use to make it very worthwhile.

PHP:
<?php
switch ("
") {
case "\x0D\x0A":
    $sol = $eol = '';
    break;
case "\x0A":
    $sol='';
    $eol = "\r";
    break;
case "\x0D":
    $sol="\x0A";
    $eol = '';
    break;
}
...
Messy, messy.

Alternatively, it could use implode rather than multiline strings.
PHP:
<?php
define('CRLF', "\x0D\x0A");

$to = "maulikan@agmr.x10.bz";
$subject = "Send test";
$mailheaders = implode(CRLF, array(
  "From: Alberto Marambio <>",
  "Reply-To: $sender_email",
  ""
));

$msg = implode(CRLF, array(
  "ESTOS SON LOS DATOS RECIBIDOS:",
  "Nombre: $_POST[sender_name]",
  "E-Mail: $_POST[sender_email]",
  "Mensaje: $_POST[message]",
  ""
));
...

Or there's that preg_replace option.
PHP:
define('CRLF', "\x0D\x0A");

function h2n_nl($str) {
    return preg_replace("/(?<!\x0D)\x0A/", CRLF, $str);
}

$to = "maulikan@agmr.x10.bz";
$subject = "Send test";
$mailheaders =<<<EOS
From: Alberto Marambio <>
Reply-To: $sender_email
EOS;
$msg =<<<EOS
ESTOS SON LOS DATOS RECIBIDOS:
Nombre: $_POST[sender_name]
E-Mail: $_POST[sender_email]
Mensaje: $_POST[message]
EOS;

$msg = h2n_nl($msg);
$mailheaders = h2n_nl($mailheaders);
...

If the mailer is configured properly, I believe it will translate line feeds into CRLFs, so the above is only necessary if the mailer is misconfigured.
 
Last edited:
Top