How use Dynamic hyperlink on each wordpress post? - php

I built a static button from backend but i want that button get hyperlink from post editor
I have designed a static design and button on singlepost.php file now i want that when i create a new post then i want to put a redirect hyperlink behind that button from post editor section. how can i do that ?
how i set hyperlink behind that "Get Deal" button from post page ?
Get Deal button is static for all post but this button take link when i put from post editor section (so there will be separate dynamic link for each post)
My static design code for post is :
<div class="price_row_grid">
<div class="price_for_grid floatleft">
<?php theme_create_btn('no', 'price'); ?>
</div>
<div class="floatright vendor_for_grid">
<?php if ($price_meta == 'admin'): ?>
<?php $author_id = $post->post_author; ?>
<a class="admin" href="<?php echo get_author_posts_url($author_id) ?>" title="<?php the_author_meta('display_name', $author_id); ?>">
<?php echo get_avatar($author_id, '22'); ?>
</a>
<?php elseif ($price_meta == 'store'): ?>
<div class="brand_logo_small">
<?php WPSM_Postfilters::re_show_brand_tax('logo'); //show brand logo?>
</div>
<?php endif; ?>
</div>
</div>
<div class="price_row_grid">
<div class="price_for_grid floatleft">
<p class="button">Get Deal</p>
</div>
Now how i set hyperlink behind "Get Deal" from post editor because i just build button which is static for all pages but i want to set different hyperlink for each page.

you can take a help from this example
<html>
<head>
<script type="text/javascript">
function onsubmit_handler(){
var myForm = document.getElementById('myForm');
var data = document.getElementById('data').value;
if(data == "a")
myForm.setAttribute('action', 'a.php');
else if(data == "b")
myForm.setAttribute('action', 'b.php');
else
myForm.setAttribute('action', 'error.php');
}
</script>
</head>
<body>
<h3>Enter Text:</h3>
<form id="myForm" method="post" onsubmit="onsubmit_handler()">
<input type="text" id="data" name="data" value="">
<input type="submit" value="Post">
</form>
</body>
</html>

Related

How to make the button visible and hidden according to requirement

I want to display the button only when $safe_cus is 1.But the button gets displayed when the browser is resized.
<?php if($safe_cus == 1) {?>
<div class="col-sm-6 hidden-xs">
<div class="pull-right">
<a class="btn btn-primary" href="<?php echo $action_multiple; ?>"><?php echo $button_multiple_bill_payment; ?></a>
</div>
</div>;
<?php } ?>
one more thing you can do is write CSS based on your condition for ex
if($safe==1){.css{display:none;}}else{.css{display:blockl}}
Now put CSS as a class on your button
hope this helps you.
u can use javascript:
first set an id for your div;
for example "parentdiv"
then get your div to you javascript code:
document.getElementById("parentdiv");
and set an onload function for ur body tag:
body onload="show()"
then you can do ur display stuff with php:
<?php if($safe_cus == 1) {?>
<div class="col-sm-6 hidden-xs">
<div class="pull-right">
<a class="btn btn-primary" href="<?php echo $action_multiple; ?>"><?
php echo $button_multiple_bill_payment; ?></a>
</div>
</div>;
<script>
function show(){
var div = document.getElementById("parentdiv");
div.style.display="block";
}
</script>
<?php } ?>

How to get hyperlink in wordpress php?

I am building a website and i have this issue :
I am working on a template and i did some modification. So the front page have some boxes which shows deals and buttons.
As you can see there are buttons called "See Deals"
Each box is a post so when i create a post then each box created automatically . I want that when i put a link on post then it will automatically set behind that "See Deals" button. I mean i want that this "See deal" button take the url from a link which i put in this post.
I wrote this code for boxes :
<div class="price_row_grid">
<div class="price_for_grid floatleft">
<?php theme_create_btn('no', 'price'); ?>
</div>
<div class="floatright vendor_for_grid">
<?php if ($price_meta == 'admin'): ?>
<?php $author_id = $post->post_author; ?>
<a class="admin" href="<?php echo get_author_posts_url($author_id) ?>" title="<?php the_author_meta('display_name', $author_id); ?>">
<?php echo get_avatar($author_id, '22'); ?>
</a>
<?php elseif ($price_meta == 'store'): ?>
<div class="brand_logo_small">
<?php WPSM_Postfilters::re_show_brand_tax('logo'); //show brand logo?>
</div>
<?php endif; ?>
</div>
</div>
<div class="price_row_grid">
<div class="price_for_grid floatleft">
<p class="button">Get Deal</p>
</div>
Now suppose i created a post on wordpress :
Now you can see there i put a dummy link at the end of post "google" now i want that when i put any link there then the box of this post get this link and set behind "Get Deal" button.

jQuery AJAX Refresh after Insert not working

I have a single page website, I have the insert working correctly, but I cannot seem to update the #results div after submit. The values are being inserted into the database just fine and if I hard refresh they are appearing. But not with the jQuery AJAX refresh. I am new to Ajax, so any help would be really appreciated, and any comments on code structure or bad habits, please comment as I am trying to learn the proper way to program.
Here is my code:
$(document).ready(function(){
$("form#addTodo").submit(function(){
alert('hello world'); // ensure function is running
var post_title = $('input#post_title').val(); // take values from inputs
var post_content = $('input#post_content').val();
$.ajax({
type: "POST",
url: "add.php",
data: "post_title=" + post_title + "&post_content=" + post_content,
success: function() {
// alert('success'); // ensure success
$('#results').fadeOut('slow').load('include/results.php').fadeIn('slow');
}
});
$('input#post_title').val(''); // clear form fields
$('input#post_content').val('');
return false;
});
});
Here is the results.php file:
<?php
$sql = $db->query('SELECT id, post_title, post_content FROM posts ORDER BY post_title ASC');
$results = $sql->fetchALL(PDO::FETCH_OBJ);
$count_posts = count($results);
?>
<?php if ( have_posts() == true) : ?>
<div class="accordion" id="accordion_main">
<?php foreach($results as $entry): ?>
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion_main" href="#collapse-<?php echo $entry->id; ?>">
<?php echo $entry->post_title; ?>
</a>
</div>
<div id="collapse-<?php echo $entry->id; ?>" class="accordion-body collapse">
<div class="accordion-inner">
<p class="target"><?php echo $entry->post_content; ?></p>
<p>Edit Delete</p>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<h3>There are no posts to display at this time.</h3>
<?php endif; ?>
This works fine when it is included by the index.php, I just can't get it to refresh after posting the data to the DB.
<?php
require_once 'includes/db.php';
require_once 'includes/functions.php';
?>
<?php get_header(); ?>
<div id="results">
<?php include_once 'includes/results.php'; ?>
</div>
<hr />
<p>Add New Post</p>
<form id="addTodo" action="">
<div>
<label for="post_title">Post Title</label>
<input id="post_title" name="post_title">
</div>
<div>
<label for="post_content">Post Content</label>
<input id="post_content" name="post_content">
</div>
<div>
<button id="submit" type="submit">
Save
</button>
</div>
</form>
<?php get_footer(); ?>
I should mention that I haven't put in form validation yet. Any help is greatly appreciated, thanks.
Why not just return the data from success? and use that to make your html input
success:function(returnedData) {
if (returnedData.status = 'successful') {
//use javascript to append the data for example like
//returnedData.message to make html and insert into your current html
}
}
Note: returnedData has to be pushed out by your php in an json format.
you can find a similar answer to your request if you read this thread that I had recently answered : Jquery Mobile Post to PHP (same page)
But you must make some adaptation for you context ;-) !!
I think that is the unique solution if you're using unique file script
To insert data returned from php file just use $("element id or class").html() function to insert the data or html to specific area of your document

How to pass variable objects to multiple javascript popup forms

This is my first serious foray into javascript/ajax.
Overview:
I have an index page listing multiple records, each on different rows. For each record I have a link which pops open a small javascript window which contains a symfony form. All goes well, with the exception that I can't figure out how to pass the popup javascript the object Id of each record. Here's what I have:
Starting with the Action:
public function executeTrackReferrals(sfWebRequest $request){
$userId = $this->getUser()->getId();
$this->pager = new sfDoctrinePager('referral', sfConfig::get('app_pager'));
$this->pager->setQuery(Doctrine_Core::getTable('Referral_submissions')->getUsersSubmissions($userId));
$this->pager->setPage($request->getParameter('page', 1));
$this->pager->init();}
Main index page:
<?php
include_partial('<a bunch of other includes >');
include_partial('referral/rtsIndex', array('pager' => $pager));
?>
_rtsIndex partial:
<table>
<?php foreach ($pager->getResults() as $r => $referral): ?>
<?php
$referralObject = Doctrine_Core::getTable('referral')->getReferralObjectById($referral->getId());
$submissionObject = Doctrine_Core::getTable('referral_submissions')->getObjectByReferralId($referralObject->getId());
?>
<TR VALIGN=TOP>
<td WIDTH=10% ALIGN="center" class="_7">
<P ALIGN=CENTER>
<script type='text/javascript'>
$('.popup_changestatus').click(function(){
// put the row id into the hidden field in the popup
var rowId = $(this).parent().find('span.row_id').html();
$('test').val(rowId);
fg_popup_form("fg_formContainer","fg_form_InnerContainer","fg_backgroundpopup");
return false;
});
</script>
<a href="#" class="popup_changestatus">
<?php echo utilities::getStatusCode($submissionObject->getCandidateStatus()); ?>
</a>
<span class="row_id" style="display: none">
<?php echo $referral->getId() ?>
</span>
</P>
</td>
</TR>
</table>
the Javascript popup form code mentioned above, includes this line:
<?php include_partial('referral/changeStatusCodeForm'); ?>
The above line renders the actual symfony form:
_changeStatusCodeForm partial:
<?php
$object = new referral_submissionsForm(<this is where I need to pass an ID for each popup form>);
echo $object;
?>
Can anyone steer me in the right direction?
If interested in the actual javascript code, it's a pretty nifty open source popup:
http://www.html-form-guide.com/contact-form/simple-modal-popup-contact-form.html
EDIT:
Here is the contents of contactform-code.php:
<script type='text/javascript' src='/project/misc/simple-popup-form-1/scripts/gen_validatorv31.js'></script>
<script type='text/javascript' src='/project/misc/simple-popup-form-1/scripts/fg_ajax.js'></script>
<script type='text/javascript' src='/project/misc/simple-popup-form-1/scripts/fg_moveable_popup.js'></script>
<script type='text/javascript' src='/project/misc/simple-popup-form-1/scripts/fg_form_submitter.js'></script>
<div id='fg_formContainer'>
<div id="fg_container_header">
<div id="fg_box_Title">Change Status</div>
<div id="fg_box_Close">Close(X)</div>
</div>
<div id="fg_form_InnerContainer">
<form id='contactus' action='javascript:fg_submit_form()' method='post' accept-charset='UTF-8'>
<input type='hidden' name='submitted' id='submitted' value='1'/>
<input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
<input type='text' class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />
<div class='short_explanation'>* required fields</div>
<div id='fg_server_errors' class='error'></div>
<div class='container'>
<?php
// $form = new referral_submissionsForm();
include_partial('referral/changeStatusCodeForm');
?>
</form>
</div>
</div>
First, you shouldn't directly use Doctrine_Core into your model. The best way here, is to make a leftJoin on your 2 tables when you pass the query to the pager. Then, in your template, you just fetch the relation (like $object->getRelation()).
Regarding to your problem, you should pass the ID when building the <div id='fg_formContainer'> since it's the content of your popup. The part come from this file: contactform-code.php.
Show us where do you build this div and you will have the place where you have to pass the id.
Edit:
Well, I finally get your problem. You have one popup define on your page that can be called on each click from each row. And you want to know how to pass the row id to the global popup.
This can be done in javascript. Instead of :
<a href='javascript:fg_popup_form("fg_formContainer","fg_form_InnerContainer","fg_backgroundpopup" );'>
<?php echo utilities::getStatusCode($submissionObject->getCandidateStatus()); ?>
</a>
You can better use :
<a href="#" class="popup_contact">
<?php echo utilities::getStatusCode($submissionObject->getCandidateStatus()); ?>
</a>
<!-- use this hidden span to put the row id, to be able to retrieve it using jQuery -->
<span class="row_id" style="display: none">
<?php echo $referral->getId() ?>
</span>
And then, define an action using jQuery (for example):
$('.popup_contact').click(function() {
// put the row id into the hidden field in the popup
var rowId = $(this).parent().find('span.row_id').html();
$('#submitted').val(rowId);
fg_popup_form("fg_formContainer", "fg_form_InnerContainer", "fg_backgroundpopup");
return false;
})

correct place for my form tag to pass correct value in action PROBLEM

i have this code:
<body>
<div class="header">
<?php if (isset($_SESSION['user_id']) && !isset($menu)) { ?>
<div class="menu_holder">
<ul>
<li>
<a href="<?php echo ADDRESS; ?>menu.php" class="green_link">
<img src="<?php echo IMAGES; ?>template/menu.gif" width="51" height="20" border="0" />
</a>
</li>
</ul>
</div>
<?php } ?>
<?php
if (!isset($plainHeader))
{
$plainHeader = " ";
?>
<img src="<?php echo IMAGES; ?>template/logo.gif" width="160" height="94" />
<?php
}
?>
</div>
<br/>
<?php $id_to = $user['profile_id_contact']; ?>
<div class="main_content">
<center>
<div class="innerContainer">
<span class="headings2">FREE CHAT CONTACTS</span>
<form id="message_area" style="display:none" method="post" action="<?php echo ADDRESS; ?>messageSent.php?id=<?php echo $id_to ?>">
<?php
if (count($users) > 0)
{
foreach ($users as $user)
{
//some php here
?>
<a href="#" class="charcoal_link" style="line-height: 20px;" onclick="showMessageArea(this); return false;" >
<?php echo $uniqueCode1?><span class="pink_text"><?php echo $uniqueCode2?></span><?php echo $uniqueCode3?>
</a>
<textarea name="message" rows="10" cols="20"></textarea>
<input name="Submit" type="submit" value="Send"></input>
<?php
}
}
?>
</form>
</div>
</center>
</div>
</body>
as my code is now the form tag is in the wrong place because my tag links does not show.
where must i put my form tag so that when i click on any of the uniquecode links i pass the correct $id_to in the action??? when i move the form tag after the my links show but regardless of which link i click on it passes the first link's $id_to with the action. i have also tried to pass $id_to as a hidden field which i had after the sumbit but still it passes the first link's id
please help? i have been struggeling with this for some time now...i cannot redirect the page via JS becuase this site is for a MOBILE aka mobi site
please help? im desperate
thank you
if i move the form tag and have it like this:
messageSent.php?id=">
and i view the page source $id_to contains correct id but as sson as i go to sentMessage.php the id in the url is incorrect
To pass a id to the next page in a link you need to add "?id='.$id.'" at the end of the url.
e.g.
<a href="<?php echo ADDRESS; ?>menu.php?id=5" class="charcoal_link" style="line-height: 20px;">
To make sure that each link is different you can right click and copy the url to double check.

Categories