I have this code:
<?php
include 'theme.php';
css();
if($_POST['wget-send'])
{
$formdir=$_POST['dir'];
$formlink=$_POST['link'];
$filelink = fopen('/root/wget/wget-download-link.txt',a);
$filedir = fopen('/root/wget/wget-dir.txt',w);
fwrite($filedir, $formdir);
/*
fwrite($filelink, $formlink."\n");
exec('touch /root/wget/wget-download-link.txt',$out);
exec('echo "'.$dir.'" > /root/wget/wget-dir.txt',$out);
*/
exec('echo "'.$formlink.'" > /root/wget/wget-download-link.txt');
exit();
}
echo "<form action=\"".$PHP_SELF."\" method=\"post\" id=\"WgetForm\">";
echo "Download directory:<br><input type=\"text\" name=\"dir\" size=\"15\" value=\"/mnt/usb/\"/><br>";
echo '<br>Download link:';
echo ("<textarea name=\"link\" rows=\"13\" cols=\"62\"></textarea><br><br>");
echo '<input type="submit" onclick="LinkAdded()" name="wget-send" value="Send" id="WgetID"/>';
echo "</form></div>";
echo <<<HTML
<script type="text/javascript">
function LinkAdded()
{
alert("Link has been sucessfully sent to wget, it'll be downloaded soon, check the wget log for the download progress");
location.replace("wget_log.php");
}
</script>
HTML;
foot();
echo '
</div>
</body>
</div>
</html>';
?>
the alert part works it gives me a pop up but after the pop up, it just gives me a blank page. How do I make the location.replace("wget_log.php"); work?
stackoverflow keeps telling me that I should add more details on my post but I think that's all the details I can give.
You need to prevent the default action of submitting the form by returning false from the click handler
echo '<input type="submit" onclick="LinkAdded(); return false;" name="wget-send" value="Send" id="WgetID"/>';
Related
I am trying to integrate Razorpay in my application. Here is a code that controls loading of payment model when "Pay Now" button is clicked. I want to make the modal load on page load instead of button click. I tried submitting form via javascript to see if that loads the modal but that's not working.
Here is the code:
<form action="verify.php" method="POST" id="gateway">
<script
src="https://checkout.razorpay.com/v1/checkout.js"
data-key="<?php echo $data['key']?>"
data-amount="<?php echo $data['amount']?>"
data-currency="INR"
data-name="<?php echo $data['name']?>"
data-image="<?php echo $data['image']?>"
data-description="<?php echo $data['description']?>"
data-prefill.name="<?php echo $data['prefill']['name']?>"
data-prefill.email="<?php echo $data['prefill']['email']?>"
data-prefill.contact="<?php echo $data['prefill']['contact']?>"
data-notes.shopping_order_id="3456"
data-order_id="<?php echo $data['order_id']?>"
<?php if ($displayCurrency !== 'INR') { ?> data-display_amount="<?php echo $data['display_amount']?>" <?php } ?>
<?php if ($displayCurrency !== 'INR') { ?> data-display_currency="<?php echo $data['display_currency']?>" <?php } ?>
>
document.getElementById("gateway").submit(); // Not working
</script>
<!-- Any extra fields to be submitted with the form but not sent to Razorpay -->
<input type="hidden" name="shopping_order_id" value="3456">
</form>
However, I also noticed that form actions to page verify.php so if the form is submitted it will go to that page where I just want to load the payment modal. Hence, what I tried can just not be the solution.
I found the solution. Posting as it may be of help for someone in the future:
In razorpay/checkout/automatic.php (or manual.php) place this right after the opening <form> element:
<script>
$(window).on('load', function() {
$('.razorpay-payment-button').click();
});
</script>
Attach an onload event to script and simulate click in the handler
<script>
function loadPaymentModal() {
const elem = document.getElementsByClassName('razorpay-payment-button')[0];
elem.click();
}
</script>
<form action="verify.php" method="POST" id="gateway">
<script onLoad="loadPaymentModal()" src="https://checkout.razorpay.com/v1/checkout.js"
data-key="<?php echo $data['key']?>"
data-amount="<?php echo $data['amount']?>"
data-currency="INR"
data-name="<?php echo $data['name']?>"
data-image="<?php echo $data['image']?>"
data-description="<?php echo $data['description']?>"
data-prefill.name="<?php echo $data['prefill']['name']?>"
data-prefill.email="<?php echo $data['prefill']['email']?>"
data-prefill.contact="<?php echo $data['prefill']['contact']?>"
data-notes.shopping_order_id="3456"
data-order_id="<?php echo $data['order_id']?>"
<?php if ($displayCurrency !=='INR' ) { ?> data - display_amount="<?php echo $data['display_amount']?>" <? php } ?>
<? php if ($displayCurrency !== 'INR') { ?> data - display_currency="<?php echo $data['display_currency']?>" <? php } ?>
>
</script>
<!-- Any extra fields to be submitted with the form but not sent to Razorpay -->
<input type="hidden" name="shopping_order_id" value="3456">
</form>
<script src="{{url('/')}}/frontendtheme/js/plugins/jquery-3.3.1.min.js"></script>
<script>
$(window).on('load', function() {
jQuery('#gateway').submit();
});
</script>
note: Use your min.js file folder on script source
I am a beginner on coding. I am working on a WordPress website using beaver builder theme. My challenge is to display a login form (when the user is not logged in) and the user name when he is logged in, to a specific area of the header that has a class "header-text".
Here is my php code located in a file named "file.php"
<?php
if(is_user_logged_in()) {
$user = wp_get_current_user();
$var1 = "<p>Welcome <?php echo $user->display_name; ?></p>
<p><a href='/login/login.php?logout=true'>Click here to log out</a></p>";
$var2 = "<form action='login.php' method='post'>
<input type='text" autocomplete='off' placeholder='Username' name='username'/>
<input type='text' autocomplete='off' placeholder='Password' name='password'/>
<button type='submit' value='Submit'>Submit</button>
</form>";
echo echo json_encode($var1);
} else {
echo echo json_encode($var2);
}
?>
Here is javascript
<script type="text/javascript">
jQuery(document).ready(function($){
function displayAccess() {
$.get("login/file.php");
return false;
}
if(<?php echo json_encode($var1); ?>) {
var variable1 = <?php echo json_encode($var1); ?>;
document.getElementByClassName("header-text").innerHTML = variable1;
}
if(<?php echo json_encode($var2); ?>){
var variable2 = <?php echo json_encode($var2); ?>;
document.getElementByClassName("header-text").innerHTML = variable2;
}
});
</script>
I need help to correct my script. Thanks!
in this case, javascript an jquery is not necessary, because the login status changes on reload, anyway.
all you need is a change in your php code:
<?php
/* put this to your template file (e.g. header.php) */
if(is_user_logged_in()) {
$user = wp_get_current_user();
/* change $var1 to echo it via html block inside php */
?>
<p>Welcome <?php $user->display_name; ?></p>
<p>Click here to log out</p>
<?php
/* cut $var2 because it is not accessible in the else clause */
} else {
/*
paste $var2 here and echo it
btw:
* For tags that are self-closing, the forward slash should have exactly one space preceding it (https://make.wordpress.org/core/handbook/best-practices/coding-standards/html/#self-closing-elements)
* use single or double quotes – make a decision!
*/
?>
<form action="login.php" method="post">
<input type="text" autocomplete="off" placeholder="Username" name="username" />
<input type="text" autocomplete="off" placeholder="Password" name="password" />
<button type="submit" value="Submit">Submit</button>
</form>
<?php
}
?>
Ok so I'm facing this problem here
I've got 2 files :
index.html
get.php
On index.html I've got a form :
<form method="POST" action="get.php">
<input name="x" placeholder="first value" type="text">
<input name="y" placeholder="second value" type="text">
<input value="send" type="submit">
</form>
<br>
<iframe id="frame" class="right" width="100%" height="300" src="get.php"></iframe>
and here is the get.php file
<?php
if(isset($_POST['x'])==false)
{
echo "<h3>First variable is required...</h3>";
exit;
}
if(isset($_POST['y'])==false)
{
echo "<h3>Second variable is required...</h3>";
exit;
}
echo "<a style='padding:15px;background:#eee;color:#fff;border-radius:5px;' href='index.html'>Go back to the main page</a><br><br><br>";
$x=0;
$y=0;
$x=$_POST["x"];
$y=$_POST["y"];
echo "Values entered were $x and $y respectively<br><br><br>";
echo "Sum of $x+$y= ".($x+$y)."<br><br>";
echo "Multiplication of $x*$y= ".($x*$y)."<br><br>";
echo "Division of $x/$y= ".($x/$y)."<br><br>";
echo "Power of of $x<sup>$y</sup>= ".pow($x,$y)."<br><br>";
echo "power of $y<sup>$x</sup>= ".pow($y,$x)."<br><br>";
echo "Table of $x<br><br>";
for($i=1;$i<=10;$i++){
echo "$x * $i = ".($x*$i)."<br>";
}
echo "<br><br>Table of $y<br><br>";
for($i=1;$i<=10;$i++){
echo "$y * $i = ".($y*$i)."<br>";
}
?>
Now what is needed is that I put 2 values in both fields and once I click the submitted button it should show result of the get.php in the <iframe> placed on index.html rather then loading a new page of get.php
You could set iframe content using following snippet. The data are send using ajax and you need to prevent form submit behaviour. Try e.g:
$(function() { // document ready handler
$('form[action="get.php"]').on('submit', function(e) {
e.preventDefault();
$.post(this.action, $(this).serialize(), function(data) {
var iframeDoc = $('#frame')[0].contentDocument;
iframeDoc.open();
iframeDoc.write(data);
iframeDoc.close();
})
})
});
i am trying to make a post and comment script.Just for learning purpose.What i have done so far is:
post a status by clicking a submit button
(it will insert the post to a database and retrieve it from the database to show )
there will be a comment section for each post,it will take users comment and upload it to database ( problem lies here).
my main problem is i can't manage to show the most recent comment posted when user click the post button. it will be inserted to database when user click the post button but can't show it to them when updated.How can i do that. i need suggestion or idea..not a coded solution .thanks :)
problem is in the red circled area user will put their comment and click post button.it will be uploaded to the database by an ajax call using firendComment.php page. But cant update the post by showing this comment uploaded?how can i do that.For convenience i am supplying my entire script here:
<?php
session_start();
require_once 'myDB.php';
if(isset($_POST['post']) && !empty($_POST['post'])){
$post=$_POST['post'];
$_SESSION['post']=$_POST['post'];
try{
$newComment=DB::getInstance();
$newComment->insert('post',array('posts'=>$post));
}catch(Exception $e){
echo $e->getMessage();
}
header('HTTP/1.1 303 see other');
header('Location:'.$_SERVER['PHP_SELF']);
}
?>
<html>
<head>
<style>
#formdiv{width:347px;height:120px;background:#dfe3ee;position:relative;border:1px dashed black;top:0px;left:300px;padding:5px; margin-bottom:3px;
}
#individual{background:#f7f9f7;display:block;height:30px;padding:6px;}
#cmntbox{
width:347px;background:#dfe3ee;position:relative;border:1px solid black;left:300px;padding:5px;margin-bottom:10px;
}
.repText{
width:100%;background:#f7f7f7;position:relative;border:1px solid black;padding:3px;resize:none;}
}
</style>
</head>
</body>
<div id='formdiv'>
<form action='' method='POST'>
<textarea name='post' placeholder="what's on your mind !" cols='40' rows='3'></textarea>
<input type='submit' name='submit' value='post comment' style='float:right;width:100px;height:30px;background:#3b5998;color:white;'>
</form>
</div>
<?php
$newComment=DB::getInstance();
$results=$newComment->getComment('SELECT','post',array('posts','id'))->result();
foreach($results as $result=>$val){
$postid='rep'.$val->id;
$hiddenid='hidden'.$val->id;
?>
<div id='cmntbox'><?php
echo $val->posts;
echo '</br><hr>';
$comments=$newComment->get('cmnt',array('postid','=',$val->id))->result();
foreach($comments as $comment){
?>
<div id='individual'><?php echo $comment->cmnts; ?></div>
<hr>
<?php
}
?>
<form action='friendComment.php' method='post'>
<textarea name='myrep' id='<?php echo $postid; ?>' class='repText'></textarea>
<input type='button' class='reply' value='reply' style='width:50px;height:30px;background:#3b5998;color:white;' >
<input type='hidden' id='<?php echo $hiddenid; ?>' class='hiddenfield' name='postid' value='<?php echo $val->id; ?>'>
</form>
</div>
<?php
}
?>
<script>
var reply=document.getElementsByClassName('reply');
var repText=document.getElementsByClassName('repText');
var hidden=document.getElementsByClassName('hiddenfield');
for(i=0;i<reply.length;i++){
(function(i){
reply[i].addEventListener('click',function(e){
var xmlHttp=new XMLHttpRequest();
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4 && xmlHttp.status==200){
console.log(xmlHttp.responseText);//do nothing
}
}
var parameters='myrep='+repText[i].value+'&postid='+hidden[i].value;
xmlHttp.open("POST", "friendComment.php", true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.send(parameters);
});
})(i);
}
</script>
</body>
</html>
friendComment.php page :
session_start();
require_once 'myDB.php';
if(isset($_POST['myrep']) && isset($_POST['postid'])){
if(!empty($_POST['myrep']) && !empty($_POST['postid'])){
// echo $_POST['postid'].' has a comment of '.$_POST['myrep'];
$getDB=DB::getInstance();
$getDB->insert('cmnt',array('postid'=>$_POST['postid'],'cmnts'=>$_POST['myrep']));
$results=$getDB->getComment('SELECT','cmnt',array('postid','cmnts'));
print_r($results);
}
}
I'm trying to submit a POST and a GET form with one submit button. I tried using the following php code:
echo "<html>\n<head>\n<title>Params</title>";
echo "<script type='text/javascript'>";
echo "function submitForms(){
document.getElementById('form1').submit();
document.getElementById('form2').submit();
}";
echo "</script>";
echo "</head>";
echo "<body>";
echo "<form action='' method='get' id='form1'>";
echo "<label>First Name </label>";
echo "<input type='text' name='first'><br/>";
echo "<label>Last Name </label>";
echo "<input type='text' name='last'><br/>";
echo "<label>Age </label>";
echo "<input type='text' name='age'><br/>";
echo "<label>Telephone </label>";
echo "<input type='text' name='phone'><br />";
echo "</form>";
echo "<form action='' method='post' id='form2'>";
echo "<label>Username </label>";
echo "<input type='text' name='username'>";
echo "<label>Password </label>";
echo "<input type='password' name='password'>";
echo "</form>";
echo "<input type='submit' value='Send' onclick='submitForms();'>";
echo "</body></html>";
What I get is only the POST params, while the GET request is not loading at all.
How can I fix this?
Thanks in advance.
You should take only one form all fields in that and after getting all input data after submit you can do whatever you want to do..
The way you are doing this is not possible reason being when form is submitted control goes to server to handle http request. hence only one form can be submit at a time. You can't submit two forms at once.. try changing order of form submit and other form will start submitting..
You should use AJAX (jQuery). Something like this should do the trick:
//Onclick for any button you wish to submit the forms
$('#form2 input[name="submit"]').click(function(e) {
e.preventDefault();
var formOne = $("#form1"),
formTwo = $("#form2");
//Post first form
$.post( formOne.attr('action') , formOne.serialize(), function() {
alert('Form one posted!');
});
//Post second form
$.post( formTwo.attr('action') , formTwo.serialize(), function() {
alert('Form two posted!');
});
});
Not tested yet, but this should work. More information for the $.post method can be found here.