Skip to content

Instantly share code, notes, and snippets.

@crackcomm
Created December 30, 2010 08:49
Show Gist options
  • Select an option

  • Save crackcomm/759606 to your computer and use it in GitHub Desktop.

Select an option

Save crackcomm/759606 to your computer and use it in GitHub Desktop.
Is there another, better method to get same effect in view ?
<?php
echo Form::open();
echo Form::label('username', __('Username')); ?>
<p><?php echo Form::input('username', $input['username']); ?></p>
<?php if(isset($errors['username'])) echo "<p>{$errors['username']}</p>"; ?>
<?php echo Form::label('password', __('Password')); ?>
<p><?php echo Form::password('password', $input['password']); ?></p>
<?php if(isset($errors['password'])) echo "<p>{$errors['password']}</p>"; ?>
<?php echo Form::label('password_confirm', __('Repeat password')); ?>
<p><?php echo Form::password('password_confirm', $input['password_confirm']); ?></p>
<?php if(isset($errors['password_confirm'])) echo "<p>{$errors['password_confirm']}</p>"; ?>
<?php echo Form::label('email', __('E-mail address')); ?>
<p><?php echo Form::input('email', $input['email']); ?></p>
<?php if(isset($errors['email'])) echo "<p>{$errors['email']}</p>"; ?>
<p><?php echo Form::submit('submit', __('Register')) ?></p>
<?php echo Form::close(); ?>
@NARKOZ

NARKOZ commented Mar 25, 2011

Copy link
Copy Markdown

@crackcomm

<?php if ($errors): ?>
<p class="message">Please correct errors below and try again!</p>
<ul class="errors">
<?php foreach ($errors as $message): ?>
    <li><?php echo $message ?></li>
<?php endforeach ?>
</ul>
<?php endif ?>

<form action="<?php echo URL::site('controller/action'); ?>" method="post">
    <label for="username">Username</label><br />
    <input id="username" name="username" type="text" /><br />
    <label for="password">Password</label><br />
    <input id="password" name="password" type="password" /><br />
    <label for="password_confirm">Repeat password</label><br />
    <input id="password_confirm" name="password_confirm" type="password" /><br />
    <label for="email">E-mail address</label><br />
    <input id="email" name="email" type="text" /><br />
    <input type="submit" value="Register" />
</form>

@Samnan

Samnan commented Jun 24, 2011

Copy link
Copy Markdown

Extend the Kohana Form class with your own.

  1. Pass the errors list to the form by adding your own method e.g. Form::set_errors($errors);
  2. Override the input() method and put the isset() check and print logic in your overridden function.

Example code: (application/classes/form.php)

{Form::$form_errors[$name]}"; return $markup; } ``` }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment