patternphpMinor
Web register form
Viewed 0 times
formregisterweb
Problem
This is a page that allow user to do register:
This code only have 2 label and 2 fields: one is email, another is the invitation keys. This is the code that render for generation the form, table, and the button with these 2 label and fields. But as you can see, it is very messy, if I need to maintain, it will become a headache. Any suggestions on how to make it simpler?
table->set_template(array('table_open'=>''));
$this->table->add_row(form_label($label_email.
form_label(form_error('email'),'',array('class' => 'error_label')),
'label_email',
array('class' => 'form_label')),
array('class' => 'align_right_td',
'data' => form_input('email',
set_value('email'),
'class = "align_right_input require"')));
$this->table->add_row(form_label($label_invitation_key.
form_label(form_error('invitation_key'),'',array('class' => 'error_label')),
'label_invitation_key',
array('class' => 'form_label')),
array('class' => 'align_right_td',
'data' => form_password('invitation_key',
set_value('invitation_key'),
'class = "align_right_input require"')));
$this->table->add_row('',array('class' => 'button_td',
'data' => form_submit('register', $button_register, 'class = "form_td_button"')));
echo $this->table->generate();
?>
This code only have 2 label and 2 fields: one is email, another is the invitation keys. This is the code that render for generation the form, table, and the button with these 2 label and fields. But as you can see, it is very messy, if I need to maintain, it will become a headache. Any suggestions on how to make it simpler?
Solution
You could start by removing dynamic HTML generation where there is no benefit in it. You would be much better of writing something like this :
Yes, none of it is CodeIgniter , but then again i have huge dislike for frameworks with crappy OOP.
form;
?>
get_destination(); ?>" method="post">
render_field( 'email' ); ?>
render_field( 'invitation_key' ); ?>
render_field( 'submit' ); ?>
Yes, none of it is CodeIgniter , but then again i have huge dislike for frameworks with crappy OOP.
Code Snippets
<?php
$form = $this->form;
?>
<form action="<?php echo $form->get_destination(); ?>" method="post">
<ul>
<li>
<?php echo $form->render_field( 'email' ); ?>
</li>
<li>
<?php echo $form->render_field( 'invitation_key' ); ?>
</li>
<li><?php echo $form->render_field( 'submit' ); ?></li>
</ul>
</form>Context
StackExchange Code Review Q#4424, answer score: 3
Revisions (0)
No revisions yet.