I currently have a variables.php file like this:
<?php
$rep_name = "John Doe";
$rep_phone = "555-555-5555";
$rep_email = "johndoe#email.com";
$rep_subject = "Agent Contact: JDoe";
$rep_price = "39.95";
?>
I want to create an HTML page with a form that would generate this - would look something like this:
<form name="generatevariables" action="generate_variables_file.php" method="post">
Rep Name:<input name="rep_name" placeholder="John Doe"><br />
Rep Phone:<input name="rep_phone" placeholder="555-555-5555"><br />
Rep Email:<input name="rep_email" placeholder="johndoe#email.com"><br />
Rep Subject:<input name="rep_subject" placeholder="Agent Contact: JDoe"><br />
Rep Price:<input name="rep_price" placeholder="39.95">
</form>
and they would enter their information and click a button that says Generate. That would create the variables.php file and download it to their computer for them to upload via FTP:
<?php
$rep_name = "John Doe";
$rep_phone = "555-555-5555";
$rep_email = "johndoe#email.com";
$rep_subject = "Agent Contact: JDoe";
$rep_price = "39.95";
?>
which could then be uploaded and the variables be called throughout the site, just as I am currently calling the variables at the very top.
Does this make sense? I need for the rep to be able to generate their own variables.php file, the rest of the website depends on the variables.php file for all content that is specific to them.
Thanks.
You can set an appropriate header to force download, then just echo out the code in plain text:
<?php
//generate_variables_file.php
header('Content-disposition: attachment; filename=variables.php');
header('Content-type: text/plain');
echo '<?php';
echo '$rep_name = "' . $_POST['rep_name'] . '";';
echo '$rep_phone = "' . $_POST['rep_phone'] . '";';
echo '$rep_email = "' . $_POST['rep_email'] .'";';
echo '$rep_subject = "' . $_POST['rep_subject'] .'";';
echo '$rep_price = "' . $_POST['rep_price'] .'";'
echo '?>';
Related
The file has a 2 texboxes submit button when it is tapped the data is put into the newly created file.Each new created file
I have file j.php that creates a texfile question.$myDate.txt creates a new txt file with a unique name and $question1 represents the question and it is put in the textfile data as the first element the sign "," splits $question1 and $question2. The variable $question2 represents the answer. And is put the second element in the text file.
The second file questions.php opens instntly after the button is submitted the file is supposed the read adn split the data of the text file and read it and dispay it once the texfile is split into two elements since the text files contains two elements. The first one shows up as a question and the texbox in should be written an answer and the form would be submitted.
But the problem on file 2 it it dosen't read the textfile data. when the text box pops up.
<?php
if(isset($_POST['submit'])) {
$number =$number +1;
$myDate = round(10*microtime(TRUE));
$result ="question".$myDate.".txt";
$question1 = $_POST['name'];
$question2 = $_POST['age'];
$file = fopen( $result, "w+" ) or die( "file not open" );
$s = $question1 . "," . $question2 . "\n";
fputs($file, $s)or die("Data not written");
// Here - redirect to questions.php to display the contents.
header('Location: questions.php');
die;
}
else{
echo
'<center>
<form action = "j.php" method = "post">
<br>Question you want ask the person <input type = "text" name="name"> <br>
<br>Answer<input type = "text" name = "age"><br>
<input type = "submit" name = "submit" value = "Make Question">
</form>
</center>';}
?>
<?php
$myDate = glob("*.txt");
$myFile = "question".$myDate."txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
$arr =explode(",",$theData);
$x=$arr[0];
$y = $arr[1];
$text = $_POST["name"];
$text = true;
if($_POST['submit']) {
$text = $_POST["name"];
if ( $text ==$y) {
echo "<font color = 'red'>Your answer is incorrect</font>";
} else {
echo "answer not correct";
}
}
?>
<center>
<form method = "post">
<?php echo $x ?> <input type = "text" name="name"> <br>
<input type = "submit" name = "submit" value = "Submit answer">
</form>
</center>
\\expected output the texfile being read and next to the text box the question popped upp\\
I am working on a form, and want to save a copy of every form submitted. The problem is the form's action is a counting file, that makes each file saved count up once. For example, the third form submitted is named "3.php", and the tenth form submitted is named "10.php". When I try to write the POST variable top the new file, it is gone. Anyway I could write their responses to a new document with my counting files code?
Form code on main file:
<form action="count.php" method="post">
<input type="text" name="formItem1">
<input type="text" name="formItem2" required>
<input type="text" name="formItem4" required>
<input type="text" name="formItem5" required>
<input type="text" name="formItem6" required>
<input type="submit" name="Click" value="Submit">
</form>
Count.php code:
<body>
<?php
define('countlog.txt', __DIR__ . "./");
if (file_exists('countlog.txt')) {
# If File exists - read its content
$start = (int) file_get_contents('countlog.txt');
} else {
# If No File Found - Create new File
$start = 1;
#file_put_contents('countlog.txt', "$start");
}
# When Form Submitted
if (isset($_POST) and isset($_POST['Click']) and $_POST['Click'] == "Submit") {
$file_name = "{$start}.php";
$template = file_get_contents('template.php');
#file_put_contents("./submissions/" . $file_name, "$template");
# Update Counter too
$start = $start + 1;
#file_put_contents('countlog.txt', "$start", 1);
echo "Generated Filename - $file_name";
}
?>
</body>
Template.php code:
echo "<h1>Answer1: " . $formItem1 . "</h1>";
echo "<h1>Answer2: " . $formItem2 . "</h1>";
echo "<h1>Answer3: " . $formItem3 . "</h1>";
echo "<h1>Answer4: " . $formItem4 . "</h1>";
echo "<h1>Answer5: " . $formItem5 . "</h1>";
echo "<h1>Answer: " . $formItem6 . "</h1>";
Use sessions. Create a session on each page with session_start(); Store the post value using the session global array. eg. $_SESSION['yourValue'] = POST['yourValue'];. Now on the rest of the pages you should be able to access the value. e.g
$yourValue = $_SESSION['yourValue'];
IF you use $template = file_get_contents('template.php'); it will make the content of template.php a string, and the variables will not be evaluated.
You could use eval() http://php.net/manual/en/function.eval.php to evaluate a string as PHP code. I would not recommend this method, but if you want to use it you will need to return, rather than echo the template otherwise the template will be echoed to the browser rather than the string you want to save to file.
template.php
return "<h1>Answer1: " . $formItem1 . "</h1>".
"<h1>Answer2: " . $formItem2 . "</h1>".
"<h1>Answer3: " . $formItem3 . "</h1>".
"<h1>Answer4: " . $formItem4 . "</h1>".
"<h1>Answer5: " . $formItem5 . "</h1>".
"<h1>Answer: " . $formItem6 . "</h1>";
count.php
$template = file_get_contents('template.php');
$template = eval($template);
It would be much easier/better to include the template, and the code will execute, thus populating the $template variable.
template.php
<?php
$template = "<h1>Answer1: " . $formItem1 . "</h1>".
"<h1>Answer2: " . $formItem2 . "</h1>".
"<h1>Answer3: " . $formItem3 . "</h1>".
"<h1>Answer4: " . $formItem4 . "</h1>".
"<h1>Answer5: " . $formItem5 . "</h1>".
"<h1>Answer: " . $formItem6 . "</h1>";
?>
count.php
include('template.php');
Both methods assume you have used extract($_POST); to import variables from an array into the current symbol table.
i have a little script and i want to give possibility to the user to edit the "config.php" file , with the script in the (setting.php) page .
For Example , they are some of codes in "config.php"
$title = 'myblog';
$email = 'info#google.com';
$desc = 'Something';
i want to have a "HTML" page , to get the value of the things that i said.
(the user enter the value and the value should be used in other parts of script)
if you want something like the user can change the title, if there are more than one user means if one changes config.php the title will be changed for the rest.
so, it's better to use a databases.
if it's only one user, you can use a file to store the information in.
please, explain more what you want to do, one user or more than one ?
You should better do this:
In the settings.php file:
<form action="settings2.php" method="POST">
Title:<input type="test" name="title"><br>
Email:<input type="test" name="email"><br>
Desc:<input type="test" name="desc"><br>
<input type="submit">
And settings2.php:
<?php
$title = $_POST['title'];
$email = $_POST['email'];
$desc = $_POST['desc'];
$content= '<?php
$title = "'.$title.'";
$email = "'.$email.'";
$desc = "'.$desc.'";
?>';
$file = "config.php";
$fh = fopen($file, 'w') or die("can't open file");
fwrite($fh, $content);
fclose($fh);
?>
These 2 pages will put in config.php the values submited by the form, for example:
<?php
$title = "PHP";
$email = "email#email.com";
$desc = "something";
?>
I really don't know Drupal but have managed to create a simple HTML page that I would like to use the first and last name inputted to run snoopy.class.php to run a script on a web site to retrieve some data. The button should run a function that will submit the URL but I am not getting any results.
Because I don't know how to debug in Drupal I added some echo statements to see how far the code ran it seems to be stopping when it tries to create a new snoopy object. I downloaded the class and put it in what I would think would be an accessible folder, namely public_html/tools it:
-rw-r--r-- 1 agentpitstop apache 37815 Sep 3 21:03 Snoopy.class.php
Below is the code I am using
<form method="post">
<p>Last Name: <input type="text" name="lastname" /><br />
First Name: <input type="text" name="firstname" /></p>
<p><input type="submit" value="Send it!"></p>
</form>
<?php
if($_POST)
{
echo "1st display <br />\n";
$url = "https://pdb-services-beta.nipr.com/pdb-xml-reports/hitlist_xml.cgi?";
$url = $url . "customer_number=beta83agent&pin_number=nipr123&report_type=1";
$lastname = $_POST['lastname'];
$firstname = $_POST['firstname'];
$parms = array("name_last"=>$lastname,"name_first"=>$firstname);
echo "2nd display <br />\n";
$result = curl_download($url,$parms);
$xml=simplexml_load_file("$result.xml");
$nipr_id = $xml->NPN;
echo "url " . $url . "<br />\n";
echo "Agent " . $_POST['firstname'] . " " . $_POST['lastname'] . " Id is:". $nipr_id . "<br />\n";
echo "3rd Result from call " . $result . "<br />\n";
}
?>
<?php
include "Snoopy.class.php";
function curl_download($url,$parms)
{
echo "in call to curldownload ";
$snoopy = new Snoopy();
echo "after setting object";
$snoopy->curl_path = "/usr/bin/curl"; # Or whatever your path to curl is - 'which curl' in terminal will give it to you. Needed because snoopy uses standalone curl to deal with https sites, not php_curl builtin.
echo "after setting path";
$snoopy->httpsmethod = "POST";
echo "after setting post";
$snoopy->submit($url, $parms);
echo "after setting submit";
print $snoopy->results;
echo "results: " . results;
return $snoopy->results;
}
?>
Any help would be appreciated.
If you need custom development on a Drupal site create a custom module and use Drupal's form API.
If you need to perform HTTP request from PHP, use a PHP library/extension, such a php-curl, Guzzle or Drupal's drupal_http_request(). And yes, they all support HTTPS.
I am using a drupal_http_request to an xml string from another web site I am currently trying to figure out how to grab this as an xml it does not seem to be working but when I run the exact same url in a browser it gives me back the information in xml format any ideas on how to do this Thought if I put something in like $headers = array("Content-Type: text/xml") when I execute $http_contents = drupal_http_request($url, $headers = array("Content-Type: text/xml")); it would give me the data in an xml format but it is not any ideas thanks in advance Below is my code
<form method="post">
<p>Last Name: <input type="text" name="lastname" /><br />
First Name: <input type="text" name="firstname" /></p>
<p><input type="submit" value="Send it!"></p>
</form>
<?php
if($_POST)
{
$url = "https://pdb-services-beta.nipr.com/pdb-xml-reports/hitlist_xml.cgi?customer_number=testlogin&pin_number=testpin&report_type=1";
$url = $url . "&name_last=" . $_POST['lastname'] ."&name_first=". $_POST['firstname'];
$result = grabData($url);
$xml=simplexml_load_file("$result.xml");
$nipr_id = $xml->NPN;
echo "Agent " . $_POST['firstname'] . " " . $_POST['lastname'] . " Id is:". $nipr_id . "<br />\n";
}
?>
<?php
function grabData($url)
{
$http_contents = drupal_http_request($url);
if (!isset($http_contents->data)) {
throw new RuntimeException("Cannot get contents from the URL");
}
if($replace_special_characters)
$http_contents_data = str_replace('&','&', $http_contents->data);
else
$http_contents_data = $http_contents->data;
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $http_contents_data, $result);
xml_parser_free($xml_parser);
echo "Display http_contents_data " . $http_contents_data . "<br />\n";
echo "Display result " . $result . "<br />\n";
return $result;
}
?>
here is what I am receiving
LISTsamplelastname, samplefirstname samplemiddlenamesampleidsampleidstateDOB
and when I run the url through the browser I get this
<?xml version='1.0' encoding='UTF-8'?>
<HITLIST>
<TRANSACTION_TYPE>
<TYPE>
LIST
</TYPE>
</TRANSACTION_TYPE>
<INDIVIDUAL>
<NAME>
samplelastname, samplefirstname samplemiddlename
</NAME>
<ID_ENTITY>
sampleid
</ID_ENTITY>
<NPN>
sampleid
</NPN>
<STATE_RESIDENT>
state
</STATE_RESIDENT>
<DATE_BIRTH>
dob
</DATE_BIRTH>
</INDIVIDUAL>
<INDIVIDUAL>
</INDIVIDUAL>
With the help of Supdley and My fellow worker John Salevetti I found the solution. Merely wrap the xml contents in htmlspecialchars the xml now displays
The answer to this was wrapping the xml content in question in a htmlspecialchars command this will override the suppression of non-html characters on the page. Would like to send a shoutout to Spudley who looked at this code and reminded me of the nonhtml character suppression Thanks Spudley for helping me not to go too far down that rabbit hole!
this was the original line ....
echo "Display http_contents_data " . $http_contents_data . "<br />\n";
and this is the modified line......
echo "Display http_contents_data " . htmlspecialchars($http_contents_data) . "<br />\n";