auto fill current page url to html form input - javascript

I have html form using to send feedback by php email.
In one input I want to save url of current page. Where user hit feedback button.
I want to track from which web page user is sending feedback.
Here is my code.
I found php code but its not working
Please help.
<input class="inputst" name="s_link" type="text" value="<?php $dataUrl = "http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]; ?>" name="productlink"><br>
<input type="submit" class="inputbtn" name="submit" style="margin-top:30px; float:right; margin-right: 15px;" value="Submit">

Instead of:
<input class="inputst" name="s_link" type="text" value="<?php $dataUrl = "http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]; ?>" name="productlink">
Try:
<input class="inputst" name="s_link" type="text" value="<?php echo 'http://'.$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]; ?>" name="productlink">
Hope this helps!

try
<?php echo "http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]; ?>
you are assigning a variable instead of echoing it..

Related

I want to use onclick function to get data from HTML Form inside php loop to use it in Ajax

I'm developing discussion board and I want to make a reply system on each comment using jquery.
I created certain div inside a loop with different values in each iteration.
Now I'm working on submitting the reply form and I have a problem. It works only on the first comment. When I reply to the first comment only It works but when replying to any other comment It doesn't work and give me my error message the textbox is empty Then I realized that it reads data from the first form only through the loop.
Here is the code.
<div class="comment_form">
<textarea class="span10" id="replyC" name="replyC" placeholder="Reply comment" rows="6">
</textarea><br>
<input id="commentId" name="commentId" type="hidden" value="<?php echo $CommentID;?>">
<input id="userId" name="userId" type="hidden" value="<?php echo $uId;?>">
<input id="articleId" name="articleId" type="hidden" value="<?php echo $ArticleID; ?>">
<input class="btn btn-lg btn-default replyForm" id="<?php echo $CommentID; ?>" name="replyForm" type="submit" value="Reply">
</div>
The button with class name "replyForm" I get it by
$(".replyForm").click(function()
and here is the javascript and Ajax code.
$(".replyForm").click(function(){
//$(this).parents().next('.replyForm').click(function(){
var user_reply = $("#replyC").val();
var userId = $("#userId").val();
var comment_id = $("#commentId").val();
var articleId = $("#articleId").val();
$.ajax({
url:'articleReply.php',
data:{replyC:user_reply,userId:userId,commentId:comment_id,articleId:articleId},
type:'POST',
success:function(data){
$("#resultReply").html(data);
$('#replyC').val('');
}
});
});
The problem Now .. It doesn't work on all comments retrieved from the loop but works only on the first comment while trying reply on other comments I get my empty message appears under the first comment.
So it get data from the first comment only not from the rest.
Any help ??
Here it works:
Here is the problem:

How can I reloaded URL link, that it stay the same after I click on submit button

I have simple form:
<div class="form-style-2">
<form action="" name="formular" id="formular" method="GET">
<label for="actual_position"><span>From: <span class="required"></span></span><input name="actual_position" type="text" maxlength="512" id="actual_position" class="searchField"
<?php if(!empty($actual_position)){ ?>
value="<?php echo $_GET['actual_position']?>"
<?php
}else {
?> value = ""; <?php
} ?>/></label>
<label for="final_position"><span>To: <span class="required"></span></span><input name="final_position" type="text" maxlength="512" id="final_position" class="searchField" <?php if(!empty($final_position)){ ?>
value="<?php echo $_GET['final_position']?>"
<?php
}else {
?> value = ""; <?php
} ?>/></label>
<input type="submit" value="Find path" />
And another multiselect in form who gets values form url link and compere with database and get som results. Here is a code:
<table width= "570px">
<tr><td width="200px" style="align:center"><b>Waypoints:</b> <br>
<tr><td width="370px"><select style="float:center; margin-left:5px" multiple id="waypoints">
if(!empty($urls)){
foreach($urls as $url){
if($result = $conn->query("SELECT * FROM $table where $ID = '$url' "));
$atraction = $result->fetch_array(); ?>
<option value="<?php echo $atraction['lat']. "," . $atraction['lon']; ?>"
> <?php echo "<b>".$atrction['City']. ", " . $atraction['Name'];?> </option>
<?php
}
}
?>
</select></td></tr>
<br>
</table>
</form>
And getting ID-s from url code:
if(!empty($_GET[$ID])){
$urls = $_GET[$ID];
foreach($urls as $url){
// echo $url;
}
}
... and after submit, it Post to URL some variables like this:
http://127.0.0.1/responsiveweb/travel.php?actual_position=Paris&final_position=Praha&ID[]=23&ID[]=15&ID[]=55
... very important for me are ID-s values ... but when I change for example actual position and then submit I lost my ID-s and I get something like this: http://127.0.0.1/responsiveweb/travel.php?actual_position=Berlin&final_position=Praha
Can you help me how to get after clicking on submit button full url link? Thanks
I had some trouble understanding your question OP, but I think I understood somehow what you ment, so I decided to try giving you a answer.
I have re-written your code, and tried to make somehow better code-structure. I have also used form method POST in my example, so you can see how you can change the get data on the redirection url.
See my code example here: http://pastebin.com/wQ7QCBmt
I also decided to use the form method POST instead of GET, so you can easily do back-end tasks, and extend your link if neccessary. You could also add more data to the link even when using GET. You could add an hidden input inside your form, example:
<input type="hidden" name="more_data" value="a_value" />

AJAX post variables to current page via href onclick - Jquery Mobile/PHP

I am creating an application that utilizes JQuery Mobile and PHP, nothing crazy here. I am trying to update a $_POST[''] variable on the page I am currently viewing.
The user clicks on an "Issue_Title" to add "Issue_Txt" to that particular list. So I need a way to know which issue_title the user clicks on so I can add it to the right place. To solve that when I retrieve the issue_title from mySQL table I format like so (testTitle is just a placeholder for debugging...I want $row['issue_title'] there so I can distinguish which title was clicked):
echo "<li data-role='fieldcontain'>"."".$row['issue_title']."</li>";
So onclick it will run the below JS function:
function NewIssueTxt(issue_title)
{
var combined = {'issue_title' : issue_title};
combined = $('#HiddenIssueTxtForm').serialize() + '&' + $.param(combined);
$.ajax({type:'POST', url: 'NewRoundDetails.php', data: combined, success: function(response){ }});
return false;
};
I can see via Javascript Console that this is POSTing as expected when I click the listview link. This should give me a $_POST['issue_title'] that I can use to submit along with the issue_txt which is all captured in the below form...which is a popup form that also appears when the user clicks the Issue_Title href.
<div data-role="popup" id="popupNewIssueTxt" data-history='false' data-theme="a" class="ui-corner-all">
<form id="NewIssueTxtForm" action="/NewRoundDetails.php" onsubmit="return submit_popupNewIssueTxt();" method="post">
<div style="padding:10px 20px;">
<h3>Issue Text:</h3>
<label for="issue_txt" class="ui-hidden-accessible">Issue Text:</label>
<input type="text" name="issue_txt" id="issue_txt" value="" />
<label for="issue_title" class="ui-hidden-accessible">Issue Title</label>
<input type="hidden" name="issue_title" id="issue_title" value="<?php echo $_POST['issue_title']; ?>"/>
<label for="date" class="ui-hidden-accessible">Date:</label>
<input type="hidden" name="date" id="date" value="<?php echo $_POST['date']; ?>"/>
<label for="dept_name" class="ui-hidden-accessible">Department Name:</label>
<input type="hidden" name="dept_name" id="dept_name" value="<?php echo $_POST['dept_name']; ?>"/>
<label for="participants" class="ui-hidden-accessible">Participants:</label>
<input type="hidden" name="participants" id="participants" value="<?php echo $_POST['participants']; ?>"/>
<label for="issue_category" class="ui-hidden-accessible">Issue Category:</label>
<input type="hidden" name="issue_category" id="issue_category" value="Work Environment"/>
<button id="NewIssueTxtButton" form="NewIssueTxtForm" type="submit" data-theme="b">Add</button>
</div>
</form>
As mentioned I confirmed the JS function is working...except I still have no value for $_POST['issue_title']. What am I doing wrong? Is the JS function not submitted fast enough...so I click the Issue_title but my form is opened before the POST happens? If that's the case how else can I get the href clicked into a usable variable?
To reiterate: I'm populating a listview with data from a mySQL DB. I need a way of knowing which link or listview is clicked so I can POST it along with other form data.

Posting value using Auto Submit isn't working

I have a post value came from the another page and post to index2.php. I want to post again that value to autosubmit.php using auto submit script. But why isn't working?
Here's my code
index2.php
<?php
$mysqli = new mysqli("localhost", "root", "", "app");
if (isset($_POST['submit'])) {
$drop=$_POST['drop'];
$tier_two=$_POST['tier_two'];
echo'
<form method="post" action="autosubmitform.php" id="dateForm" name="dateForm">
<input name="drop" type="" value="'.$drop.'" style="background-color:blue;"><input name="tier_two" type="" value="'.$tier_two.'">
<input type="submit" name="editsubmit">
</form>';
echo'<script type="text/javascript">
document.getElementById("dateForm").submit(); // SUBMIT FORM
</script>';
}
?>
autosubmitform.php
<?php
$mysqli = new mysqli("localhost", "root", "", "app");
if (isset($_POST['editsubmit'])) {
$drop=$_POST['drop'];
$tier_two=$_POST['tier_two'];
echo $drop; echo $tier_two;
}
echo'
<input name="drop" type="" value="'.$drop.'" style="background-color:red;"><input name="tier_two" type="" value="'.$tier_two.'">
<input type="submit" name="editsubmit">';
?>
changes in your code
/*
if you submit your form through javascript your button value is not submited
so you have to click that by javascript to submit it value
*/
<script type="text/javascript">
document.getElementsByName("editsubmit")[0].click(); // SUBMIT FORM
</script>
Also move your echo code inside php because if it does'nt go inside if than your variable $drop and $tier_two remain undefine in your echo statement present outside if
if (isset($_POST['editsubmit'])) {
$drop=$_POST['drop'];
$tier_two=$_POST['tier_two'];
echo $drop;
echo $tier_two;
echo'
<input name="drop" type="text" value="'.$drop.'" style="background-color:red;"><input name="tier_two" type="text" value="'.$tier_two.'">
<input type="submit" name="editsubmit">';
}
Alternate solution for above PHP code
$drop = '';
$tier_two = '';
if (isset($_POST['editsubmit'])) {
$drop=$_POST['drop'];
$tier_two=$_POST['tier_two'];
echo $drop;
echo $tier_two;
}
echo'
<input name="drop" type="text" value="'.$drop.'" style="background-color:red;"><input name="tier_two" type="text" value="'.$tier_two.'">
<input type="submit" name="editsubmit">';
user this script
window.onload = function(){
document.forms['dateForm'].submit()
}
as follows
echo"<script type="text/javascript">
window.onload = function(){
document.forms['dateForm'].submit()
}
</script>";
I hate not being able to comment. The only thing though is that some people can get caught half way through this.
If someone has javascript turned off, then they'll get stuck on this page with the raw data. Is there another way you could write this?
You could also just pass the values in the url (GET instead of POST) and encode the values if they need to be encrypted.

pressing submit button with javascript

actually I have:
<form action="<?php echo $this->getUrl('checkout/cart/estimatePost') ?>" method="post" id="shipping-zip-form" name="shipping-zip-form">
<label for="postcode"<?php if ($this->isZipCodeRequired()) echo ' class="required"' ?>><?php echo $this->__('Zip/Postal Code') ?></label>
<div class="input-box">
<input class="input-text validate-postcode<?php if ($this->isZipCodeRequired()):?> required-entry<?php endif;?>" type="text" id="postcode" name="estimate_postcode" value="<?php echo "04000"; ?>" />
</div>
<div class="buttons-set">
<button type="button" id="send" title="<?php echo $this->__('Get a Quote') ?>" onclick="coShippingMethodForm.submit()" class="button"><span><span><?php echo $this->__('Get a Quote') ?></span></span></button>
</div>
</form>
and I unsuccessful tried:
<script type="text/javascript">
document.getElementById('send').submit();
document.forms['shipping-zip-form'].submit();
</script>
What I want to do it's quite simple, let javascript automatically press the button so submit the form. I will not need the submit button anymore, I need to automate the press button process. Thx
I"m guessing that your function isn't firing. Set it to execute on page load if that's when you'd like it to happen. Also, only <form> elements can be submitted so trying to target your <button id="send"> won't work.
window.onload {
document.getElementById('shipping-zip-form').submit();
}
document.getElementById('shipping-zip-form').submit();
You can use jQuery and try this :
$(document).ready(function(){
$('#send').click(function(){
$('#shipping-zip-form').submit();
});
});

Categories

Resources