AJAX/JQUERY post and include - php

Find this confusing...
If a user fills in a contact form (contactus.php) and submits the form using AJAX/JQuery to (process.php) and on the (process.php) there is a include function but the PHP file isn't being included..
Why could that be??
LOL if it makes sense. All help would really be appreciated.
include("file_name_goes_here.php");
OR__________________________________________________
How can I make (index.php) read a text file's contents as php coding and then excute it?
$data = file_get_contents("file.txt");

Can you load your txt file as a string and use eval? Note: I'm not suggesting this is a good idea!

Related

str_replace to replace html content using php

i'm creating a html editor using JavaScript and php, where the user selects html element from browser, edits this element inline and submits the changes to the server.
Now to apply the changes, i've used str_replace to compare the changes sent by the user with existing content in the html file at server end and replace it.
The selected element's content($_POST['content1']) and new content($_POST['contentreplace1']) are sent using $_POST
But this functionality is not working properly.
The existing code is not getting replaced with the new one.
<?php
$orig="".trim($_POST['content1']);
$new="".trim($_POST['contentreplace1']);
$file = 'index.html';
$file_contents = file_get_contents($file);
$file_contents_new = str_replace($orig,$new,$file_contents);
file_put_contents($file,$file_contents_new);
?>
What I'm doing wrong here?
Any suggestions or recommendations are welcomed.
Please share your thoughts and experiences.
Thanks for all the help in advance.

New element on a php array file

I'm a total noob on php, but a friend of mine asked for help and I thought I might do it..
I have this code/file here and want to find a way to add an element in this array via html file. I know it sounds noob, it does for me too, but please help, I've seen arrays, vectors and lists only on c++, tried to take a look at the documentation of php5 (since he want it in php 5) but I couldn't make it!
here it is...
<?php
$bledi = array('user12345', 'user2016', 'user5749852', 'user985658', 'HowToAddANewElement');
echo $result;
?>
You need a form with a text input in HTML and a send button.
When the form is submitted to the action page there you could put
your php.
You can make a global array ($bledi) and you will have an if condition there that says something like
if($_REQUEST['input_text'])
$bledi[] = $_REQUEST['input_text'];

Retrieving text from HTML5 to write to a file with PHP?

I was wondering if there was a way to retrieve info from a certain element in HTML and then write it to a file using PHP ?
For example:
<div id="info_needed">text needed</div>
<button id="submit info"> Click to write to PHP file</button>
How would I retrieve the "text needed" and write it to a file using php? (I understand I will have to use the Write() command, but I am completely lost on how to get the info.
Any help would be awesome.
Thanks guys!
Use jQuery to pull the text out. $('#id').text()
Use jQuery.ajax() to post to a PHP file that does the processing. i.e. capture the posted text.
You can use jQuery.post(). Make sure you set data parameter. {value: sometext} Your PHP script can then use file_put_contents() in append mode to append the text to the file.
P.S.: You could have a success function that indicates the action was successful.

Http post/get dynamic action url

Hello is it possible if someone could tell me the easiest way to create a dynamic action url on a html form.
We have 2 text box's and we would like to submit the information to a url like the following http://example.com/box1/box2/ but using the values contained within the forms text box's.
I guess this would need to be done via java script or something but i have no idea as to how to go about it.
Any help on this would be appreciated
thanks
It's very simple. All you need to do is to get the values from your script and then use header redirect. e.g.
if(isset($_POST['SUBMIT'] {
$box1 = $_POST['box1'];
$box2 = $_POST['box2'];
header("Location: http://example.com/$box1/$box2/");
}
or you can use PHP curl library if you do not want to do a redirect
if using javascript, guess u could do something like this, php or server RewriteRule (.htaccess) might be what u r looking for.
<script>
//replace the textbox1 and 2 with the id of your text boxes in your form
var box1=document.getElementById('textbox1').value;
var box2=document.getElementById('textbox2').value;
window.location ="http://example.com/"+box1+"/"+box2+"/";
</script>
Might want to put the script into a function and call it with an 'onclick=' event or if u want to call the javascript before the form submits. try using 'onsubmit=' with return=false; at the end of the function.
hope it helps

Have html in a string - need to show it as a separate html page using code

I have a script which takes in html from the user as in full page html either from the user or grabs it via curl or from an email. The thing is that I have the html in a string but on the same page I need to show the htmnl in a separate iframe. I don't want to reput any database, curl or imap code in the page referenced by teh iframe at all - is there a way for me to show html passed into a url somehow? like as in a get variable .. the html can be huge here... sorry if it sounds weird.
You can put the grabbed html into a temp file and put the link to that temp file into the src="" of the iframe.
Create them using tempnam(), then create a small script that gets the (preferably obfuscated) filename and simply prints it out if it was really a temp file created by you.
Be careful! if it doesn't check the filename well, you are giving full read access to your server... Put the link to this script in the src of the iframe. You can also create temp files in the public folder of your www server, but I wouldn't want temp/garbage there.
(if i am not misunderstanding your question)
You could put the string in a textarea inside a form and submit the form ..
the receiving page would read the posted data and render it on the page..
I'm not quite sure what you want to do, put you could always post the string as a POST variable, no limitations on how long they can be.
You can encode pieces of HTML with urlencode which is automatically decoded when you retrieve it with $_GET or you can use e.g. base64_encode and base64_decode. The problem is that there are limits to $_GET and $_POST. Both can be set in your configuration settings, but sending large amounts of data via the URL is really not-done because that's not how it should be used.
But if I read your question correctly, you can fetch the HTML at the top of the page, and then load it into an iframe?
if ($_GET['url']) {
$html = file($_GET['url']);
}
if ($_POST['html']) {
$html = $_POST['html'];
}
And then include it:
<html>
..
<iframe ..><php echo $html; ?></iframe>
..
</html>

Categories