Form inputs not showing the same across browsers - html

I have this JSFiddle that shows a user registration form. I am using Twitter Bootstrap. I have just realized that it shows fine when using Firefox.
However, when using Chrome or IE, the textfields are slightly above the input-group-addons where I have glyphicons.
How can I make the form inputs show correctly across browsers?
<div class="input-group">
<span class="input-group-addon glyphicon glyphicon-user"></span>
<?php
echo $this->Form->input('username', array('class' => 'form-control',
'placeholder' => 'Username', 'required' => 'required', 'type' => 'text'));
?>
</div>

Move the glyph class out and into their own spans.
<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
Always try to keep elements separate from their containers to prevent styles from conflicting with each other.

Related

CakePHP: How to use a AwesomeFont icon in submit()?

I'd like to use an Font Awesome icon in a submit button. I tried:
<?= $this->Form->submit('<i class="fa fa-save fa-2x"></i>', ['escape' => false]) ?>
But it doesn't work. How to do?
Using the code shown in the question you will end up with an HTML like this:
<div class="submit">
<input type="submit" value="<i class=" fa="" fa-save="" fa-2x"="">
</div>
This is not something you are looking for, so try using button instead of submit:
<?= $this->Form->button('<i class="fa fa-save fa-2x"></i>',
['escape' => false,'type' => 'submit']) ?>
See here : submit Vs button cakephp3, form helper
This answer comes 4 years later, but to use font awesome, or any icon syntax for the cake form submit helper, use the following syntax:
$caption = "<i class='fa fa-cloud-upload fa-2x'></i>" //defines the icon
$options = ['escape'=>true]; //defines the submit button options
echo $this->Form->button($caption,$options);

How to customize Flash Message with inline css in cakephp3

In my Controller :
$this->Flash->success(__(' Your Data has been Saved Successfully. Sheets Name in this XLS file : <span style="color:#FF9900"> '.$SheetName.'</span>'));
In my success.ctp located in Element\Falsh :
<div class="alert alert-success fade in" onclick="this.classList.add('hidden')"> × <strong>Success!</strong> <?= h($message) ?> </div>
The Message is display like :
Now the question is how to use inline css in the flash message.
I think the soloution for your problem would be to use another layout for this type of message.
$this->Flash->set($message, $options[])
You can specify to use a specific element in the options. Something like this:
create a new confirmation.ctp inyour project:
<div class="[...]">
<?= h($message) ?>
<span style="color:#FF9900">
<?= h($params['sheetName']) ?>
</span>
</div>
now when you want to show the new confirmation use this code:
$this->Flash->set(__('The Message:'), [
'element' => 'confirmation,
'params' => [
'sheetName' => $SheetName
]
]);
This will display your custom flash element.

Customize login cakephp3

I have a form like this:
email
[input]
password
[input]
Login-Button
I want to eliminate the "email" and "password" text and put them inside the inputs like placeholder and also change the "login" text to "LOGIN".
This is my login ctp.
<fieldset style="background:#F44336">
<?= $this->Form->create() ?>
<?= $this->Form->input('email') ?>
<?= $this->Form->input('password') ?>
<?= $this->Form->button('Login') ?>
<?= $this->Form->end() ?>
<div class="forgot">
<p>Forgot Password?</p>
</div>
Your question is confusing and vague.
But I believe you are asking you dont want the value or words "Email" and "Password" to be next to the input but rather inside the input textbox?
If so, you can add HTML code inside the HTML form
<input type="email" name="email_form" placeholder="Email">
Keep in mind that is HTML 5.
In HTML 4, the traditional way would to be adding an attribute to the HTML form to email or password as value="Email..."
Above code is correct but you should use helpers.
So a better way to achieve the same task with Html helpers is:
<?= $this->Form->input('email', array('label' => false)); ?>
<?= $this->Form->input('password', array('label' => false)); ?>
It's a suggestion to make your code better which we all should focus on.

Formgenerator with div

I want to create forms in symfony2. I need this HTML structur for each control.
<div class="form-group">
<label class="col-md-2 control-label">Firstname:</label>
<div class="col-md-10"><input type="text" name="firstname" class="form-control">/div>
</div>
Now is my question, how can i add the div with the class form-group and how can i surround the input element with the div .col-md-10?
$builder->add('firstname', 'text', array(
'attr' => array(
'class' => 'form-control'),
'label_attr' => array(
'class' => 'col-md-2 control-label'
)
)
);
Check How to customize Form Rendering section of the documentation.
You may need to override the form_widget block (form_widget_compound block to go into details).
Find here the default behavior of each twig form helper.
The Form Theming Sub Chapter contains many relevant examples on how to customize any given form field block.

CakePHP Span Tag within Anchor Tag

I'm trying to have CakePHP output a link that looks like this:
<a href="/foo/bar" class="some other classes">
<span class="icon new"></span>FooBar</a>
So I use the following code in my view
<?php
echo $this->Html->link(
$this->Html->tag('span', null, array('class' => 'icon new')) . "FooBar",
array('controller' => 'foo', 'action' => 'bar'),
array('class' => 'some other classes', 'escape' => false)
);
?>
However CakePHP outputs the following:
<a href="/foo/bar" class="some other classes">
<span class="icon new">FooBar</span></a>
Which breaks my design. How can I get CakePHP to append "FooBar" after the <span> tags?
EDIT: Its also worth mentioning that I know a <span> tags shouldn't be within an anchor tag usually, but in the case its a must.
You need to use an empty string in stead of null as the text for the span, then your code will work as expected.
Looking at the source code of the HtmlHelper, null is treated as a 'special' value, causing only the opening tag of the span to be created. You can see this in this line:
https://github.com/cakephp/cakephp/blob/2.3.2/lib/Cake/View/Helper/HtmlHelper.php#L906
Change your code to this and it should work;
echo $this->Html->link(
$this->Html->tag('span', '', array('class' => 'icon new')) . "FooBar",
array('controller' => 'foo', 'action' => 'bar'),
array('class' => 'some other classes', 'escape' => false)
);
Additional explanation of the closing </span>
A bit of explanation, for those who wonder:
The closing </span> in your example is actually not present in the output generated by CakePHP, but automatically 'added' by your browser. If you view the source of the HTML in your browser, you'll see that this is what is actually in your HTML:
<a href="/foo/bar" class="some other classes">
<span class="icon new">FooBar</a>
As you can see, no closing 'span'
Because the <span> is not closed, the browser will try to correct this error and automatically assumes that you 'forgot' to close it. Therefor it will add a closing </span> before the next tag it finds (in this case the closing </a>).
The 'inspector' in your browser will always show the HTML that the browser uses to render the output. This includes automatic corrections made by the browser and dynamically generated elements (e.g. Elements added via JavaScript).
To check the output of your PHP scripts, always view the source, not the inspector
In this situation, I've avoided the CakePHP helpers entirely because the markup becomes really messy and cannot take advantage of autocomplete or validation within your IDE.
I usually do something like this:
<span class="icon-new"></span>Foobar
This looks a little overkill for me. Just do this:
echo $this->Html->link(
"<span class="icon new"></span> FooBar",
array('controller' => 'foo', 'action' => 'bar'),
array('class' => 'some other classes', 'escape' => false)
);
I've been using CakePHP for 4 years and I don't see the benefit of using tag in this instance.
Would you be able to use regular PHP in this case?
I am thinking you could do it like this:
<?PHP
echo('<span class="' . 'icon new' . '"></span>' . 'FooBar' . '')
?>