I ran into a problem what i cant solve.
i took a look at the fuelphp documentation, made it that way, but i get an error with passed walue
code
$email_data = array();
//echo Config::get('base_url'). "user/activate/". $user['hash'];
$email = Email::forge();
$email->from('my#email.me', Config::get('site_name'));
$email->to(Input::post('email'), Input::post('first_name') . " " . Input::post('last_name'));
$email->subject('Regisztráció');
$email_data['name'] = "Kedves " . Input::post('first_name'). " " .Input::post('last_name') ."<br><br>" ;
$email_data['title'] = "Üdvözöllek a ".Config::get('site_name')." oldalán" ."<br>";
$email_data['link'] = 'Fiókod mherősítéséhez kérlek kattints ide';
$email->html_body(\View::forge('email/activation', $email_data));
$email->send();
$response->body(json_encode(array(
'status' => 'ok',
)));
the email template file
<?php
print_r($email_data);
?>
and the email sends me out this
Notice!
ErrorException [ Notice ]: Undefined variable: email_data
APPPATH/views/email/activation.php # line 3:
2:3:print_r($email_data);4:?>
could please someone give me a hint what im doing wrong?
$email->html_body(\View::forge('email/activation', $email_data));
Should be
$email->html_body(\View::forge('email/activation', array('email_data' => $email_data)));
Your controller is correct. This is you template that is not correct.
When passing data to the view (template) you pass it as an array.
So you view should be:
...
You Name is : <?php echo $name ?>
You title is : <?php echo $title ?>
...
This is the way it should be done. Not transforming the array into an element of an other array in order to perform a print_r...
Related
How do you create an activeRadioList in yii2 where the checkboxes are not wrapped in labels? Ie. The label and input are adjacent to each other.
The following creates a list of radio buttons where each input is wrapped in labels:
<?= $form->field($model,'myattribute')->radioList(['n'=>'No','y'=>'Yes']) ?>
You can create one radio button that is not wrapped in a label by setting the second argument to false:
<?= $form->field($model,'myattribute')->radio(null,false) ?>
But how do you do this for a list? (FYI. I need this to work with the materializedcss framework in case your wondering).
you just need to set label property false
<?= $form->field($model,'myattribute')->radioList(['n'=>'No','y'=>'Yes'])->label(false); ?>
Updated answer
So in that case you need to use custom logic as follows.
<?=
$form->field($model, 'myattribute')
->radioList(
['n'=>'No','y'=>'Yes'], [
'item' => function($index, $label, $name, $checked, $value) {
$return = '<input type="radio" name="' . $name . '" value="' . $value . '">';
$return .= '<i></i>';
$return .= '<span>' . ucwords($label) . '</span>';
return $return;
}
]
)
->label(false);
?>
I want to use pagination in FuelPHP, I'm using this code:
$config = array(
'pagination_url' => 'http://localhost/live/public/index.php/admin/accounts/index/',
'total_items' => Model_Account::count(),
'per_page' => 10,
'uri_segment' => 3,
// or if you prefer pagination by query string
//'uri_segment' => 'page',
);
$pagination = Pagination::forge('mypagination', $config);
$data['example_data'] = Model_Account::query()
->rows_offset($pagination->per_page)
->rows_limit($pagination->offset)
->get();
// we pass the object, it will be rendered when echo'd in the view
$data['pagination'] = $pagination;
and here's the view:
<?php echo Pagination::instance('mypagination')->previous(); ?>
<?php echo Pagination::instance('mypagination')->render(); ?>
<?php echo Pagination::instance('mypagination')->next(); ?>
<?php echo Pagination::instance('mypagination')->last(); ?>
But when I try to click on any pagination in frontend then it sends error: 404 page not found
You will need to have a route set up so fuel knows how to map the URI admin/accounts/index/:page to the correct controller.
Something like the below should work in your routes.php config file. (Might need tweaking depending on your app)
'admin/accounts/index/:page' => 'admin/accounts/index'
In a symfony 1.4 view I'm attempting to pass some html/javascript in the "attributes" parameter of the sfFormField::renderRow function:
<?php echo $form['ownership_status_id']->renderRow(array('onFocus' => 'displayHelp("<p>help text</p>");'), 'Own/Rent')?>
Unfortuantely the when the page gets rendered, all of the javascript/html output is escaped:
<select name="address[ownership_status_id]" onFocus="displayHelp("("<p>help text</p>");" id="address_ownership_status_id">
I'm not clear on how to prevent this content from being escaped, can someone help?
Try to unescape the $form variable as so:
sfOutputEscaperGetterDecorator::unescape($form);
Then call renderRow():
<?php echo $form['ownership_status_id']->renderRow(array('onFocus' => 'displayHelp("<p>help text</p>");'), 'Own/Rent'); ?>
I had to use this:
<?php echo sfOutputEscaperGetterDecorator::unescape($form['ownership_status_id']->renderRow(array('onFocus' => 'displayHelp("<p>help text</p>");'), 'Own/Rent')); ?>
I have this view:
<?php echo form_open(); ?>
<?php echo form_input('username', '', ''); ?>
<?php echo form_submit('submit', 'Submit'); ?>
<?php echo form_close(); ?>
<?php echo validation_errors(); ?>
and this controller method:
function test() {
$username = $this->input->post('username');
$this->form_validation->set_rules($username, 'Username', 'required|min_length[4]');
if ($this->form_validation->run() !== FALSE) {
echo 'Tada!';
}
$this->load->view('test');
}
but when I leave the username field blank, nothing happens. However, if I type in something in it will tell me the field is required. I've downloaded and given CI a fresh install almost ten times now, trying to load with and without different helpers etc. It's becoming really frustrating, please help.
Try using this:
$this->form_validation->set_rules('username', 'Username', 'required|min_length[4]');
The problem lies in the first parameter of set_rules, which is the field name.
The $username you're passing is basically setting the field name to validate as whatever the user puts in the input field. If you were to type 'username' into the input box, you'd see that your form validates.
Change the line
$this->form_validation->set_rules($username, 'Username', 'required|min_length[4]');
to
$this->form_validation->set_rules('username', 'Username', 'required|min_length[4]');
Maybe is the problem of this line
<?php echo form_open(); ?>
If you leave it blank it basically send back to the controller itself and calling the construct and index function only. In this case your function dealing with form processing is "test()"
try this
<?php echo form_open('yourControllerName/test'); ?> //test is the function dealing with
if it is not working try on this
<?php echo form_open('test'); ?>
Im trying to render a row field in a template with some extra styles, like this:
<?php echo $form['email']->renderRow(array('class' => 'text')) ?>
<?php echo $form['email']->renderError() ?>
The problem occurs when my form doesnt validate on this field... then it displays the error message 2 times!, i.e the renderRow renders one errorMsg string, and the renderError does it again... How can i stop renderRow from displaying the error message?
If I just do this, then it works:
<?php echo $form['email'] ?>
But in that case I cant style the field as I want....
thanks!
I am pretty sure this is also valid for 1.2. Instead of using renderRow, use something like this:
<?php echo $form['FormElementName']->renderLabel() ?> //display form element label
<?php echo $form['FormElementName']->renderError() ?> //display form element error (if exist)
<?php echo $form['FormElementName']->render(array('class' => 'text')); ?> //display form element
renderRow does them all at once.
EDIT From comments (Flask) - added ->render(array('class' => 'text'));