Is it possible to specify more than one clsss for form->error?

Asked 2 years ago, Updated 2 years ago, 95 views

cake

$this->Form->error('Test.id', null, ['wrap'=>'p', 'class'=>'error-message']);

html

<div>
<div>
<p>
<input type="text" name="data[test][id]"id="test_id" class="test_class" required="required">
</p>
</div>
<p class="error-message">Error.</p>
<div>

Currently, I try to output an error-message when I get stuck in validation.
However, I would like to change the background color of the input field itself.

You can give valid and invalid to input with css, but
This will change the background color (just after loading the page) before the error message is called.
This time, when I call the error-message, I would like to learn how to change the background color of the input column of impu.

Is this possible to implement?

Alternative?
=: Active is the time you click, but there is no problem with the specification that it changes when you click.Is that possible?I looked it up and found that css alone was too harsh.

javascript php html css cakephp

2022-09-30 20:18

1 Answers

Use FormHelper::input().

<?php
echo$this->Form->input('User.name');
?>

provides the following output:

<div class="input text">
    <label for="UserName">Name</label>
    <input name="data[User][name]"type="text"value="id="UserName"/>
</div>

<!--- If there is a validation error -->
<div class="input text error">
    <label for="UserName">Name</label>
    <input name="data[User][name]"type="text"value="id="UserName"/>
    <div class="error-message">Some error message.</div>
</div>

HTML output is obtained with the input element enclosed in div.If there is an error, the div will be given the error class, so the CSS will

.error input [type=text]{
  background-color:#fcc;
}

and so on to give the input element a background color.

Note: Generate Form Element - FormHelper-2.x


2022-09-30 20:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.