I have a form which is used to write to a database. I managed to successfully complete everything except including php variables as part of the url in the flash message:
if($sale->save() && $updateowed)
{
return Redirect::to('/')->with('flash_notice','Sale record id '.$sale->id.' created. <a href=/printmemo/'.$sale->id.'>Print Cash Memo</a>');
}
The first $sale->id is displayed correctly. However, the $sale->id inside the href prevents the form form redirecting to '/' and shows a blank message. Checking the database reveals the $sale->save() is indeed successful. I kind of know it's the problem with how I use quotes, however I'm unable to solve the problem. Any help is much appreciated.
You are doing it wrong, you should only pass the data to the session and build the tag from your view, for example you may pass the $sale->id form the controller using something like this:
return Redirect::to('/')->with('sale_id', $sale->id);
Then in your view where you want to show the link using $sale->id build it like:
<?php if(Session::has('sale_id')): ?>
<a href=<?php echo "printmemo/" . $sale->id ?>>Print Cash Memo</a>
<?php endif; ?>
If you are using Blade then use blade syntax to echo the id.
Related
i want to put two parameters by jquery in href of a link and then use by codeigniter, my code is below:
$("#user_comment_show").append("<li>"+...+'<a id="remove_link" href="<?php echo base_url().'my_site/remove_user_comment/';?>'+data.user_email_address+"/"+data.user_text+'">'+.....+"</li>"
i see data.user_email_address and data.user_text in source page but by select a link codeigniter shows me an error :
The URI you submitted has disallowed characters.
what's wrong with code and how to send these two parameters to my public function in codeigniter by jquery in a link. i appreciate to help me solve my problem
data.user_email_address && data.user_text find by ajax in database
my a link in source page
change into like this
$("#user_comment_show").append("<li><a id='remove_link' href='<?php echo base_url()?>/my_site/remove_user_comment/'+data.user_email_address+'/'+data.user_text+'>Your Link Name</a></li>")
hopefully this will work fine.
normally it is working as expected, but while building my login page it is not working as I want to.
Well url is http://localhost/?page_id=96?msg=INVALID_PASSWORD_MSG
And I am trying to make it work this..but it is not working, I will be happy for every help :)
<?php if (isset($_GET['msg'])) { ?>
<div class="invallidpassword"><cite><?php echo $_GET['msg']; ?></cite></div>
<?php } ?>
I think you need to correct the question marks. Lets say you have a query page which retrieves page content from database. Then
It should be something like following.
http://localhost/query?page_id=96&msg=INVALID_PASSWORD_MSG
The first question mark added after the requested page, and the parameters are separated by &
I've got a php script which builds a html table via echoing data, But i want to add a link onto one of the values and pass that value to the next page.
<td><a href='redirect.php'><?php $_SESSION['WR'] = $row['WorkOrdRef'];echo $row['WorkOrdRef'];?></a></td>
is the line in question but this will only pass the last value added to the table.
Oh, it doesnt work like this. the php code gets executed no matter if you click the link.
I guess the easiest way to do this is to pass it as a get parameter.
html page:
<?=$cellContent?>
redirect.php:
$clickedcell = $_GET['clickedcell']
now the $clickedcell will have the data from the previous page about what cell did the user click.
If you want to use session for some reason, you still have to pass it with GET or POST and store it after the user clicks.
hopefully this is understandable and good luck with your project.
you can change the session by get method also it is possible building by javascript
in the same page add this
if(isset($_GET["clicked"])){
$_SESSION['WR'] = $row['WorkOrdRef'];
$redirect'<META HTTP-EQUIV="REFRESH" CONTENT="0;URL='.$adres.'/"> ';
return $redirect;
}
and then change your url
<td><?php echo $row['WorkOrdRef'];?></td>
I'm trying to create a link that takes the user to two different pages depending is the user logged or not. Problem is I'm still new to programming and this is quite big bite for beginner like me but its something I have to do. I created something like this so far but either way I suck at searching or there just isnt specific information for what I need
<?php if($userLogged){
echo '<a href="index.php" class="stylelink">';
}
else
{
echo '<a href="index1.php" class="stylelink">';
}
echo "Etusivu</a>";
?>
I'm also using Dreamweaver's login function that creates the MM_Username session and such, and Im not sure how to make the condition. userLogged is still an empty variable. Id appreciate any advice.
Thanks
-John
well, instead of using echo statements in the php tag you can write html and use php for outputting the value of the page like this
Etusivu
The $_SESSION['MM_Username'] works if you have included session_start(); at the beginning of the page and you can use the condition as above instead of $userLogged.
I am having a problem where I am successfully setting a URL variable in the form of mywebsite.com/contact/?product=VAR1 from one page to another, and it will be read on the 2nd page with my simple code.
First use is fine but any thing after that is not. There is a problem with the variable not being cleared/re-read/reset. The URL Bar even reads fine in the URL bar mywebsite.com/contact/?product=VAR2 so that first part works.
But the code doesn't want to get the VAR2 part once it has stored VAR1. It just keeps re-displaying VAR1 once it is loaded once.
<?php echo htmlentities($_GET['product']); ?>
If it makes a difference, I am succesfully displaying the ?product= information inside of a jQuery value changer with this:
$(".input-text").val('<?php echo htmlentities($_GET['product']); ?>');
I have tried my own solutions like putting in a unset($product); before the last ?> but no avail.
I have a limited knowledge of PHP/jQuery and would like to use this way of setting/grabbing variable since it is simple. I am using it in jQuery because it can re-write the exact form input-box value with this variable passed along, and successfully send it in my CMS's contact form.
------------------------ updated: added code ------------------------
(I am just displaying all the code logically as I can think of)
#1: Set up the variable into the URL. The first echo getURL displays the url, I add my ?product= and then it gets the item name. This is all fine.
<a href="<?php echo Mage::getURL('webforms/index/index/id/2') ?>?product=<?php echo $_product->getName(); ?>">
#2: My form is set up within my CMS. It has a special class so I can select it exactly within my jQuery. I do not have access to all of this, it is generated by the CMS. The purpose obviously is to get selected products to be rememmberd via this Variable, and serve purpose in the contact form.
<div class="field webforms-fields-enquiryfield">
<label for="field_20">
Product in Enquiry
</label>
<div class="input-box">
<input type="text" name="field[20]" id="field[20]" class="input-text" style="" value="">
</div>
</div>
#3: Now that my area to display, & variable are set up, we use jQuery to insert the variable into the actual value of the input-text form. I am doing this because within my CMS I am not able to simply add it in. I have to use jQuery to replace the text (which is empty box anyway).
$(".webforms-fields-enquiryfield .input-text").val('<?php echo htmlentities($_GET['product']); ?>');
Hope that made more sense.
I have figured the answer to this, the problem was that the CMS Magento likes to cache certain blocks - which is why I could view it first, then my CMS would store the variable but not erase it. No matter what kind of fixes I tried to disable caching, no go.
Instead I ended up using the following code, using a # variable, and some simple JavaScript that anyone can understand. I will be using this in future projects no doubt! Very easy variable passing ...
if(window.location.hash) {
var hash_value = window.location.hash.replace('#', '');
$("my-css-input-field-or-whatever-you-want").val(hash_value);
}
The hash_value can be used in a variety of ways now I suppose, and this works well around my Magento set up, it does not get cached/stored. Grabbing the URL location & hash instead.
(And the PHP used, simplified for anyone to replace/reuse within a CMS)
<a href="[GetBaseURLfromCMS]#[MyDynamicVariableHere] ">