auraphp / Aura.Input

Tools to describe HTML form fields and values.
MIT License
65 stars 11 forks source link

May be a isSuccess flag #38

Closed harikt closed 9 years ago

harikt commented 10 years ago

Hi Paul,

I was working on form, and submissions lately with the ADR .

The form is injected to the Domain\Contact . Now when the request method is post the form is calling fill() and filter() .

We are setting the form back to the responder.

One thing probably you may mention will be keep the get and post Actions different. But to me it seems duplicating so much efforts.

I was thinking whether it is good to have a isSuccess() method and return true / false if a check on filter() is called. Else nothing is returned.

Another thing is getMessages() can be checked for errors, but if the form is not submitted the getMessages() empty and that doesn't means it is success and display the message, the way isSuccess help us is recognize whether a call to filter has happened rather the user testing again on responder with certain flags set when a request is submitted etc.

Interested to hear your thoughts.

Thank you

stephen-hill commented 9 years ago

I like this suggestion and I'm willing to work on this if you both don't have the time.

I think that isSuccess() should throw an exception when filter() has not been called.

I would also like to suggest that fill() return $this so that it can be chained with filter:

$form->fill($data)->filter();

if ($form->isSuccess() === true) {

Cheers Stephen

pmjones commented 9 years ago

I'm OK with fill() being fluent.

I'm also OK with an isSuccess(), though I'd like for it to be ternary (true/false, and null if filter has not been called).

I don't recall -- do we have an isFailure() method?

stephen-hill commented 9 years ago

I'm wondering why isSuccess() should return null if filter() hasn't been called? I feel like isSuccess() should not be called unless filter() has been called, and thus, should throw an exception.

$form->fill($data);
if ($form->isSuccess()) { // Throw exception

By throwing an exception, your telling the developer that they have missed something. Otherwise the developer could write code for an unknown state.

if ($form->isSuccess()) {
    // Save Data
} else {
    // Are we false or null? Should I check?
}

Would love to hear your thoughts.

There is no isFailure() method().

harikt commented 9 years ago

@stephen-hill I don't think I will be able to look into this for the current time.

Feel free to pickup and move forward.

Thank you.

pmjones commented 9 years ago

@stephen-hill seems to have finished this off.

stephen-hill commented 9 years ago

@pmjones Thanks for merging this addition.