I am trying to create an email that is sent to customers after they place an order. I am using Laravel 8 and installed it using the command: php artisan make:mail OrderPlaced - this created all the necessary files. I then used: php artisan vendor:publish and published all the mail blade.php files:
This is my routes file, it is sent up so I can quickly design what my email will look like without continually sending emails:
/* Test email route */
Route::get('/mailable', function () {
$order = \App\Models\Order::find(1);
return new \App\Mail\OrderPlaced($order);
});
This is my OrderPlaced.php Mail controller:
public function build()
{
return $this->markdown('emails.orders.placed')
->to($this->order->billing_email, $this->order->billing_name)
->subject($this->order->billing_name . "'s Order");
}
My issue is that I am trying to apply CSS to my placed.blade.php file. It current looks like this:
#component('mail::message')
<h1>Order Received</h1>
<p>Thank you for ordering with Mobile Mastery and we are so hyped that you decided to make us part of upgrading
your gaming experience. Your order is being prepared and shipped currently, but in the mean time do NOT delete
this email as you may need it, for example, to return an item. You order details are as follows:</p>
-- OTHER ORDER RELATED STUFF --
#endcomponent
You can see that the title has a <h1> tags and the info has <p> tags but in the actual email, only the <h1> tag is applied and the <p> is shown on screen:
Can anyone tell me how to style Laravel's #component('mail::message') effectively or point me to a good page for it? Thanks
Probably the data is escaped. You can see that the mail message blade has this
{{-- Body --}}
{{ $slot }}
Explanation from doc:
By default, Blade {{ }} statements are automatically sent through PHP's htmlspecialchars function to prevent XSS attacks. If you do not want your data to be escaped, you may use the following syntax:
Hello, {!! $name !!}
Read more
https://laravel.com/docs/8.x/blade#displaying-unescaped-data
Related
many times I see, for example in Symfony:
html file:
<hr>
<?php $this->generateUrl('blog_show', array('slug' => 'slug-value')); ?>
<br>
this is a bad smell, like not using depencency injection: this way HTML is coupled to the current framework. I have to edit it if I want to move it to another framework.
Wouldnt it be better to just pass the generated url string from the controller?
You can separate your view from your backend as you want, but your frontend file has to refer to an url at some point, even if it is just an api.
Changing your url from <?php $this->generateUrl('blog_show', array('slug' => 'slug-value')); ?> to <?php $showUrl; ?> just make it less maintainable and harder to migrate to another framework.
If you want to be Framework Independant you should use Symfony backend like an API.
The url could be generated in the controller to separate model from view. But it's only a first step. The best way is to separate model, view and routing. I think the best way is to use a view helper which generates the path. I changed some framework for project (abandonware to symfony). It is easier when the project used a template (like Smarty or Twig)
Take a look at Symfony Twig extensions to have some example which separates path generation and controller.
As example, Twig purpose the path method. This view helper is searching the url path from the route paramter. It doesn't have any relation with controller or model.
path : Returns the relative URL (without the scheme and host) for the given
route. If relative is enabled, it'll create a path relative to the
current path.
As you can see there you only have to be carefull to the route name.
/**YourController**/
/**
* #Route("/foo", name="new-game", methods="get")
*
* #return Response
*/
public function myFooAction()
{
//Your code
//The rendering without information about his own or other path
return $this->render('default/foo.html.twig', []);
}
And the corresponding path in Twig :
<hr>
Some text
<br>
I want to build a Blog, of sorts, with Meteor but, rather than just have a Blog such as platypus.meteor.com, I want to create a separate Meteor template for each Blog "post" and then send a link to select people such as "platypus.meteor.com/thispost"
In this way, the person would only see the post I intend them to see; to see others, they would have to guess at other values, such as "/thatpost", "/theotherpost" etc.
And in my case, if they stumbled across them, no big deal.
This is my plan:
Create one template at a time:
<template name="thispost">
. . .
</template>
...and then allow access to that to whomever I apprise of its availability (that is, they simply enter the link I send them into their browser).
I don't know what sort of routing I need to set up; I'm open to either IronRouter or FlowRouter. At any rate, I want an URL like "platypus.meteor.com/thispost" (after a "meteor deploy platypus" of this project) to show the user the contents of that Template and nothing else.
So my question is: what do I have to do, routing-wise, to accomplish this?
How about simply:
Router.route("/:templateName/:postId",{
template: this.params.templateName,
data: function(){ return Posts.findOne({ _id: this.params.postId })
});
Then you can generically share any post with any template and have the template name appear right in the route.
I'm doing some work on an existing site that is based on the Wordpress theme, but uses about 15 plugins (Including Buddypress). One in particular is the WP Sliding Login|Dashboard plugin, which has a link to the user's activity feed. I found the code that creates that link in the wp-sliding-login-dashboard.php file:
<?php
if ( is_user_logged_in() ) {
global $current_user;
$username = $current_user->user_login;
echo ' <li>Activity Feed</li>';
}
?>
I want to use this code to send the user to the same location, but using the a link at the top of the home page. Unfortunately, the home page links are all created using Wordpress menus, which as far as I can tell, only allow for the use of static links attached to existing pages.
Do I create a dummy page to link to that exits only to execute the above code? Is that even possible? Picture a five-year-old trying to read Shakespeare, and you have an idea of my ability as a coder, so feel free to engage me as such - i.e. if you say, "oh just create a scoping function instead of creating a global function", i would stare at you drooling and confused.
Images for clarity: The sliding login menu (WP-Sliding Login|Dashboard Plugin), showing the target URL in the status bar as www.ferrignofit.com/members/FerrignoFit/activity/ (the current logged in user is FerrignoFit):
http://i.imgur.com/NPvmCXU.jpg
The main page Wordpress-based menu, which i want to go to the above URL, but is currently going to www.ferrignofit.com/activity/, a different page:
http://i.imgur.com/dIiFpDC.jpg
So here's a jQuery solution for this specific issue. From seeing the images you have, what you want to do is target a specific anchor in your dynamic WordPress menu.
As you may be aware, you can create custom links for the WordPress menu function... it simply lets you set a label and a URL. You should create such item and just give it a hash for the URL for now.
Now set a class for that specific menu item so you can have a nice handle for jQuery to target it (otherwise you can use the dynamic class that WordPress creates for each specific menu-item).
One you have a class set or you know what you need to target then you can add this block of code before your menu.
<?php if (is_user_logged_in()){ ?>
<script>
$(document).ready(function(e) {
var targetNav = $('li.customClassName a');
var userName = '<?php $current_user = wp_get_current_user(); echo $current_user->display_name;?>';
var userUrl = 'http://www.mywebsitename.com/members/'+ userName +'/activity/';
targetNav.attr('href',userUrl);
});
</script>
<?php } else { ?>
<script>
$(document).ready(function(e) {
var targetNav = $('li.customClassName a');
targetNav.attr('href','http://www.stackoverflow.com');
});
</script>
<?php } ?>
Please not that I am using PHP to get the current username in WordPress, after I get the username and I store it in the userName variable I use it in the userUrl to set it with the path that I want.
On another note, I'm using is_user_logged_in() so you have the option of making the link something else if the user is in fact not logged in. So with this if statement one of the two blocks of code will be output by PHP.
As soon as my two variables are set, I simply target my menu item with jQuery and modify the href attribute to replace the hash with the path and dynamic username.
Though this is not very good practice to mix JS and PHP, I'd like to learn myself here what other solutions someone can suggest so I'm posting this as a solution for your very specific issue.
I tested this code with my own WordPress site and it works, just remember that this code NEEDS to be in a PHP file otherwise the PHP used in the <script> tags won't mean anything to the server if it's in a .js file.
I have purchased add-ons module contact_directory using concrete5, now I have need to customize on my requirement.
so I have need to changed file packages\contact_directory\blocks\contact_directory\view.php, I have created test.php file in same directory where my view.php file, so my form tag is url('contact_directory/test')?>">
so please tell me where it's wrong?
Concrete5 utilizes a loose MVC architecture for blocks. What this means is that unlike "plain old" php sites where you have a file that gets run when a certain URL is visited, your block's controller is always called instead. But you can have different functions in the controller that respond to different url's, and in the C5 world these are called actions.
So in your block's view.php file, change your form tag to this:
<form method="post" action="<?php echo $this->action('test'); ?>">
Then in the controller.php file, make a new public function that has the name "action_" followed by what you passed into the form tag. In your example, that would be:
public function action_test() {
//do stuff here
}
Now you're going to run into an issue because Concrete5 blocks always render the "view.php" template (there is no easy way to tell it to use a "test.php" file instead, for example). The easiest solution here is to combine two templates into your view.php file with an "if" statement. For example:
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); ?>
<?php if ($controller->getTask() == 'test'): ?>
<!-- Put all of the code from your test.php file here -->
<?php else: ?>
<!-- Put all the code from your view.php file here -->
<?php endif; ?>
One thing to note -- if your block gets placed in the Page Defaults or in a Global Area (or Stack), then it's possible that the form action won't submit to the right place. I'm not sure about this though -- this was a problem I ran into back in version 5.4.2, but it may have been fixed since then.
PS - If you want to look at some sample code that utilizes this form handling stuff in C5 blocks, download my free Email List Signup addon ( http://www.concrete5.org/marketplace/addons/email-list-signup ).
I am new to wordpress and i want to transfer data from one page to another in wordpress. I used php to post my form data to a wordpress page. My code is:
<form method='post' action='http://www.example.com/www/create_website/'>
.....
<input type ='submit' value = 'OK'/>
</form>
But every time i clicked the submit button i got error page not found. Why it is so because link is loading the page in browser but not working for form post. How can i solve the issue???
Having spent about a day figuring out how to do this, I thought it might be helpful to others in the stackoverflow community.
GOAL: To take the results from a form field and use it on another page.
In this example, my client wanted users to be able to fill in any amount in a text field to make a Paypal payment. I'm using S2Member plugin to create buttons and hook up the Paypal payments, but they did not offer this functionality --only buttons with hard wired amounts.
You can see this in action here:
http://virginiabloom.com/?page_id=250 . But it is LIVE. If you start a paypal payment, it WILL deduct money from your account. Which will make Virginia very happy.
HOW I SOLVED IT:
First, I created a form just for this field.
Enter Other Payment Amount $
Next, I found a very simple plugin on stackoverflow and adapted it to my needs:
<?php
/*
Plugin name: redirect on post
Desciption:
http://stackoverflow.com/questions/13686245/how-to-create-a-custom-url-based-on-dropdown-in-wordpress-form-submission
I-changed-dropdown-to-field-input
*/
function redirect_on_submit() {
// check if the post is set
if (isset($_POST['amount']) && ! empty ($_POST['amount']))
{
header( "Location: yourUrl.com/?
page_id=542&amount=" . $_POST['amount'] );
}
}
add_action('init', redirect_on_submit);
NOTE: Change the page URL and ID information in the header to point to the Wordpress page you want to send the information to.
If you don't know how to manually install a plugin, its very simple.
Save the snippet as a .php file. Open up your hosting account and find the plugins folder (its in the wp-content folder) Copy the file into the folder.
Go back to Wordpress and look at your plugins. You should see it there. If its not activated, the activate it.
I installed another plugin:
Allow PHP in Posts and Pages (Version 3.0.4)
After installing it, the plugin will appear on the Wordpress menu.
Open it and you can use their snippet maker that will put php into your post inside a short code.
Configuration:
Show the snippet not found message: yes (for debugging)
Use the old (pre.2.2 code: no
Use the advanced filter method: yes
Remove all plugin data on install: no
You should see the code snippet box appear at the bottom of the page.
My snippet was simple. I just wanted to echo the "amount" parameter from the page url. So it looked like this:
echo $_GET['amount']?>
Note that you have to put the ending php tag, but not the beginning tag.
Now, you just use the shortcode [php function=1] on the page wherever you want to get this parameter.
Here's what it looks like on MY results page.
<h2>Payment of $ [php function=1]</h2>
<strong><em>Click Paypal button to start payment or cancel.</em></strong>
[s2Member-PayPal-Button sp="1" ids="xxx" exp="24" desc="Payment" ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="yoururl.com"
ra="[php function=1]" image="default" output="button" /]
To make sure that users can only enter in decimal numbers, I used jQuery validation on the form. There are other ways to do it, but this was very simple. Just put this code on the page with the form which I've included below.
<form id="myform" action="http://virginiabloom.com/?page_id=542" method="post"><span style="font-size:1.5em;">Enter Other Payment Amount $</span><input id="amount" class="left" name="amount" type="text" /><input type="submit" value="Submit" /></form>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://jquery.bassistance.de/validate/jquery.validate.js"></script>
<script src="http://jquery.bassistance.de/validate/additional-methods.js"></script>
<script>
$( "#myform" ).validate({
rules: {
amount: {
required: false,
number: true
}
}
});
</script>
That's it! I hope this helps somebody.
If you need to go to one of your WordPress page, please don't put the direct link in action.
Instead of that put the below php code.
<form method='post' action='<?php bloginfo('url'); ?>/your-page-name/' >
If you wants to go to a particular file inside your template directory put the below code
<form method='post' action='<?php bloginfo('template_url'); ?>/your-page.php' >
Check this WordPress codex page for more about bloginfo.
<?php bloginfo('url'); ?>
will generate the base site url.