Skip to content

Form_helper#281

Closed
Portaflex wants to merge 4 commits intocodeigniter4:developfrom
Portaflex:Form_helper
Closed

Form_helper#281
Portaflex wants to merge 4 commits intocodeigniter4:developfrom
Portaflex:Form_helper

Conversation

@Portaflex
Copy link
Copy Markdown
Contributor

Form helper revisited.

@Portaflex
Copy link
Copy Markdown
Contributor Author

There is one issue with this helper: For the HTML5 output element we would need a class instead of a helper. This is the code to be generated:

`
0

100 +





`

We have to pass the "oninput" attr to form_open() function.

Copy link
Copy Markdown
Member

@lonnieezell lonnieezell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI - There's no need to delete a PR and submit a new one. You lose discussion history when you do that. Just add new commits to the branch and it will show up in the same PR.

This is still missing the HTML inputs I asked for last time, like email, number, date, etc.

Also, you need to provide tests for all of the fields. It looks like you brought over the existing tests from CI3, but then never added any more.

* @param mixed
* @return string
*/
function _attributes_to_string($attributes): string
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we can remove this method and use the stringify_attributes that is in the Common file....

Please double-check, but at a glance, they appear the same.

@@ -0,0 +1,201 @@
<?php namespace CodeIgniter\Helpers;

class FormHelperTest extends \CIUnitTestCase
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filename is incorrect here. You have FormHelperText, instead of FormHelperTest. Did you run this locally before providing a PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, name changed and local test passed. ;-) I'll try to add some more test.


// ------------------------------------------------------------------------

if ( ! function_exists('_parse_form_attributes'))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the CI3 style naming where functions start with underscores.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Done.

{
$value = $_POST[$field] ?? $default;

return ($html_escape) ? html_escape($value) : $value;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No function named html_escape exists in the framework. You should be using the esc() method instead. Which will also require you ensure it's loaded....

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Done.


if ( ! function_exists('form_output'))
{
function form_output()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be possible as a simple field. While other fields need to be attached to it, usually through JS, the output field itself seems to be a standalone field if I understand this one correctly.

Copy link
Copy Markdown
Contributor Author

@Portaflex Portaflex Oct 4, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, no. It's not a standalone field. Look at the code:

`


0 100 + =



`

You have to declare the oninput html event in the form opening label. So, you need to have the oninput operation set before calling form_open().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright, let's simplify then and scrap this one also. Not sure how often people actually use it anyway...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. I would say nobody uses it.


if ( ! function_exists('form_keygen'))
{
function form_keygen()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This element doesn't seem to be used by any browsers at the moment, so scrap this method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, scrapped.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW I closed one PR and opened a new one because some files from other branches "slided" into this one. I didn't know how to remove them. :-(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. No worries, just trying to keep things orderly where possible. :)

@Portaflex
Copy link
Copy Markdown
Contributor Author

Portaflex commented Oct 4, 2016

We have this:

HTML5 input types:

color
date
datetime
datetime-local
email
month
number
range
search
tel
time
url
week

HTML5 input attributes:

autocomplete
autofocus
form
formaction
formenctype
formmethod
formnovalidate
formtarget
height and width
list
min and max
multiple
pattern (regexp)
placeholder
required
step

And almost all of them can be passed as attributes to form_input() as $data or $extra. A few attributes don't go as a key = value pair, e.g. "disabled" and "readonly".

So which of them are we gonna put in?.

@lonnieezell
Copy link
Copy Markdown
Member

And almost all of them can be passed as attributes to form_input() as $data or $extra. A few attributes don't go as a key = value pair, e.g. "disabled" and "readonly".

So which of them are we gonna put in?.

Ideally all of the input types should be included. Another option, and a simpler and more future-proof version, would be to adjust the form_input() method to allow you to specify the type.

As for the attributes, allow them all. No sense restricting. I'm not sure if it would be best to do special checks here, or modify stringify_attributes to check for numeric $keys and create them as single. I think the only place that method is used currently is a couple of methods in the url helper, which would face the same issue, so it's probably safe to do that.

@lonnieezell lonnieezell mentioned this pull request Nov 3, 2016
@lonnieezell
Copy link
Copy Markdown
Member

Updated and merged in #298

@lonnieezell lonnieezell closed this Nov 3, 2016
@Portaflex Portaflex deleted the Form_helper branch November 8, 2016 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants