I am trying to make a PHP script write into a plain text file. I have done this before and it worked just fine. But it's not working this time for some reason.
Here is the HTML I am using:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="/css/feedback.css" >
<title>Questions, Comments, Suggestions</title>
</head>
<body>
<p class="title">Questions, comments, and suggestions here!</p>
<form method="post" name="userFeedback" action="/submit.php">
<textarea id="comments" placeholder="Leave a comment or review here..."></textarea>
<textarea id="name" placeholder="Your name here"></textarea>
<textarea id="contact" placeholder="Put any means of contact you want to here (optional)"></textarea>
<br>
<input class="enter" type="submit" value="Enter">
</form>
</body>
</html>
All I want to do with this is to print out whatever is entered onto a plain .txt file with PHP 5.3. Here is the code:
$data = ($_POST["comments"] ." || ". $_POST["name"] ." || ". $_POST["contact"]);
$data = strip_tags($data);
$file = "feedback.txt";
$f = fopen($file, "a+");
fwrite($f, $data . "\n" . "\n");
fclose($f);
header ( 'Location: index.html' );
Please remember that I am using 5.3. I'm sure there's a simple error in here somewhere. Can someone help me with this? Thank you in advance!
We got it! Turns out that the PHP $_POST method looks for the "name" attribute and not the "id".
Related
I'm trying to pass a 'mason' variable into a Perl autohandler script that runs before the HTML.
Is this possible.
<!--- MASON -->
<html>
<body>
<%init>
my $sub_headline = 'this is text';
</%init>
###HEADER###
</body>
</html>
<!--- AUTOHANDLER --->
my $m_header = '<div class="m-portlet__head">
<div class="m-portlet__head-caption">
<div class="m-portlet__head-title">
<h3 class="m-portlet__head-text">###TITLE###</h3>
</div>
<p>$sub_headline</p>
</div><!-- /.caption -->
</div><!-- /.head -->';
$html =~ s/###HEADER###/${m_header}/i;
Ended up making a component for the header and adding a condition for the passed in arg. Then pirnt the correct HTML.
I am trying to submit a form by PERL. I have managed to submit the form, but I am getting an HTML page showing "Invalid Session Flow" after the form submission. If I submit from a browser, the new page contains another form.
I couldn't find the reason why that message could come. Is it possible to troubleshoot if I don't have any access on the server side? Or it has to be checked from server side?
My Code:
my $url = "https://MY_URL";
my $Browser = new LWP::UserAgent();
$Browser->ssl_opts(verify_hostname => 0,SSL_verify_mode => 0x00);
my $page = $Browser->get($url);
my $content = HTML::TreeBuilder->new_from_content($page->decoded_content) or die $!;
my $match = $content->find_by_attribute('name' => 'token');
my $token = $match->attr('value');
chomp($token);
my %fileds = ("DATA" => "STD111","token" => $token);
my $Page = $Browser->request(POST $url,\%fileds);
if ($Page->is_success){
print $Page->status_line."\n";
print $Page->content."\n";
}else{
print $Page->status_line."\n";
print $Page->message;
}
Below is the page sources viewed from FireFox
Initial Page:
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">
<title>Website Title</title>
</head>
<body>
<form method="post" action="/">
<input type="hidden" name="token" value="5f75b4fb68ed">
<input name="stdname">
<input type="submit" value="Submit">
</form>
</body>
</html>
The output I am getting:
200 OK
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">
<title>Website Title</title>
</head>
<body>
<form method="get" action="/">
ERROR: Invalid session flow<br>
<input type="submit" value="Relogin">
</form>
</body>
</html>
The Actual Landing page when submitted via any browser:
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=iso-8859-1">
<title>Website Title</title>
</head>
<body>
<form method="post" action="/">
<input type="hidden" name="token" value="5f75b4fb68ed">
<input type="password" name="stdpass">
<input type="submit" value="Submit">
</form>
</body>
</html>
It's likely that the browser is sending other headers that your LWP program is omitting. When faced by a situation like this, I find the best approach is to use browser plugin I like Live HTTP Headers for Firefox) that traces the actual HTTP transaction and then change my program to get as close to that as possible.
I have spent a significant time looking for an answer, and tried every solution without success :/
Basically I want to use wamp server to create contact form that will be sent to my mail address.
I have wamp running but for the life of me I can't figure out why I wouldn't receive the mails, I either get the 404 page when submitting the form, or lately "Warning: mail(): SMTP server response: 553 sorry, that domain isn't in my list of allowed rcpthosts".
I am now looking for a solution that will at least send the form to my address, whether it's secured or not I just want to see an actual mail successfully sent.
Thanks !
edit: here is the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Contact Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="page-wrap">
<div id="contact-area">
<form method="post" action="contactengine.php">
<label for="Name">Name:</label>
<input type="text" name="Name" id="Name" />
<label for="Email">Email:</label>
<input type="text" name="Email" id="Email" />
<label for="Message">Message:</label><br />
<textarea name="Message" rows="20" cols="20" id="Message"> </textarea>
<input type="submit" name="submit" value="Submit" class="submit-button" />
</form>
<div style="clear: both;"></div>
</div>
</div>
</body>
</html>
--then the contact engine--
<?php
$EmailFrom = "myadress#mail.com";
$EmailTo = "myadress#mail.com";
$Subject = "Nice & Simple Contact Form by CSS-Tricks";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
--then the thanks message--
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
<head>
<title>A Nice & Simple Contact Form</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="page-wrap">
<img src="images/title.gif" alt="A Nice & Simple Contact Form" />
<p>By CSS-Tricks</p>
<br /><br />
<h1>Your message has been sent!</h1><br />
<p>Back to Contact Form</p>
</div>
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-68528-29";
urchinTracker();
</script>
</body>
</html>
Windows does not come with a Mail Server so just calling mail() will work as far as php is concerned but the mail goes nowhere.
You either need to install a mail server or use something like the PHPMailer library to allow you to send SMTP mails via something like Yahoo or Google.
I dunno if its a silly mistake but a post/get variable is not being set, while it is supposed to be. Here are the HTML and php code snippets:
<html>
<head>
<title>
Chain Story
</title>
</head>
<body>
<form method="GET" action="check-valid.php">
<textarea name="a" rows="5" cols="50"></textarea>
<input type="submit" value="Add" />
</form>
</body>
</html>
check-valid.php:
<?php
require 'includes/connect.inc.php';
$conn_ref = connect_db('chainstory') or die(mysqli_error());
if(isset($_GET)){
echo 'Get variable set';
if(isset ($_GET['a'])){
$as = $_GET['a'];
$query = "insert into story1 values (1, " . $as . ")";
mysql_query($query, $conn_ref);
}
else{
echo $_GET;
}}
?>
I get the following output:
Get variable set
Notice: Array to string conversion in /home/kevin/Code/php/myWebsite/check-valid.php on line 15
Array
I am coding this in netbeans. Can anyone point me out what mistake im making? :(
Did you try rename the textarea? Longer name , and give id to textarea same the name.
What browser does you use for testing?
I met some problems with input names in IE for example if an input name matches a javascript function name or protected names. Have you a javascript function or variable in your code what's name is a ? Because if the name of the input conflicts with a js var or name IE does not send the input field to the server. (Chrome Firefox and other browsers does)
I have some ugly html that is emailed to my program that looks like:
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
</head>
<body>
Saved search results.<br>
<br>
Name: 'Some splunk search' <br>
Query Terms: 'tag=foo NOT BAR=\"Boom\"' <br>
Link to results: <a href="https://foo/search/blahblahblah">
https://foo/search/blahblahblah</a>
<br>
<br>
<table border="1">
...snipped the rest for brevity.
I am able to pull the table elements out using HTML::TreeBuilder but can't figure out how to
pull the "Name:" an "Query Terms" from above out without resorting to other means.
A $root->dump of the above looks like:
<html> #0
<head> #0.0
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> #0.0.0
<body> #0.1
<p> #0.1.0 (IMPLICIT)
" Saved search results. "
<br /> #0.1.0.1
<br /> #0.1.0.2
" Name: 'Some splunk search' "
<br /> #0.1.0.4
" Query Terms: 'tag=foo NOT BAR=\"Boom\""
So is there a way to get the naked text between the #0.1.0.2 and #0.1.0.4
Thanks!
Todd
If there is a pattern to the text, it might be easier to use a combination of HTML parsing and regular expressions.
my $body_text = $body->as_text(skip_dels => 1);
my ($name) = ($body_text =~ m#Name: '([^']+)'#s);
my ($query_terms) = ($body_text =~ m#Query Terms: '([^']+)'#s);