Do I need to convert regular html code to follow codeigniter standard? - codeigniter

Since I ported my website to codeigniter I am wondering if I really need to convert regular html code to codeigniter coding standard.
Say for example I have the following html code:
<input type="text" id="first_name" name="first_name" size="32" maxlength="32" value="<?php echo $first_name ?>">
In codeigniter I can do the same as above or use the following code:
$format = 'size="32" maxlength="32"';
echo form_input('first_name', '$first_name', $format);
So which one should I follow?

Just do this for ease:
echo '<input type="text" id="first_name" name="first_name" size="32" maxlength="32" value="'.$first_name.'">';
its better and suggestable and also supported by each browser damn sure

Leave your code as it is, there is no standard in writing HTML here, use whatever suits you best and whatever is more readable for you. Your way is much more rapid, than CodeIgniter's as it's basically plain html with echo of one variable. CodeIgniter's helper is basically an option for lazy ones to get things up faster, if you're familiar with them.
If you work in a team and then ask for your designer or the one that's usually working with frontend and he's not familiar with CodeIgniter you will have to change things by yourself.

Related

Laravel: How to use destroy with html forms

So since the form helpers arent included in laravel anymore. How do we call for a delete method with regular html forms? I can't find nothing about this, every example uses the form helpers..
thanks
Edit: It works using this:
<input name="_method" type="hidden" value="DELETE">
However, a little bit of explanation would be nice.

Can't access checkbox with watir

When I'm trying to click checkbox I getting an error
browser.checkbox(:id, 'AgreeToProceedWithPersonalData').click
Element is not clickable at point (314.5, 448). Other element would receive the click: <label for="AgreeToProceedWithPersonalData"></label>
And when I click at element below I getting agreement page opened.
browser.label(:for, 'AgreeToProceedWithPersonalData').click
How do I can set checkbox and do not open agreement?
<div class="checkbox">
<input data-val="true" data-val-mustbetrue="Ваше согласие необходимо для продолжения" data-val-required="The I agree to proceed personal data field is required." id="AgreeToProceedWithPersonalData" name="AgreeToProceedWithPersonalData" type="checkbox" value="true" autocomplete="off" checked="checked">
<label for="AgreeToProceedWithPersonalData">I agree to proceed personal data.
Read the agreement
</label>
<span class="field-validation-valid" data-valmsg-for="AgreeToProceedWithPersonalData" data-valmsg-replace="true"></span>
</div>
Often times developers like to make things pretty by layering things on top of standard html elements, and the driver doesn't like that.
Please don't over-use this, as it is not good practice for most things, but in situations like this I find myself needing to do:
browser.checkbox(id: 'AgreeForBKIRequest').fire_event :click
Most probably there is something very custom with javascript on the page if fire_event is not working. So it is hard to suggest and it will be nice if you will provide the url of the page to experiment with.
However you could try such suggestion with no guaranty (just guess)
browser.execute_script("window.stop")# That will stop all the scripts on the page. May be usefull may be not
browser.execute_script("document.getElementById('AgreeToProceedWithPersonalData').click();")# That will perform click using pure javascript

How to Use JavaScript instead of Custom HTML Attributes for Angular Forms?

Considering this example markup (from http://www.ng-newsletter.com/posts/validations.html):
<div class="row">
<div class="large-12 columns">
<label>Your name</label>
<input type="text"
placeholder="Name"
name="inputNameAttributeValue"
ng-model="signup.name"
ng-minlength=3
ng-maxlength=20 required />
<div class="error"
ng-show="signup_form.name.$dirty && signup_form.name.$invalid">
<small class="error"
ng-show="signup_form.name.$error.required">
Your name is required.
</small>
<small class="error"
ng-show="signup_form.name.$error.minlength">
Your name is required to be at least 3 characters
</small>
<small class="error"
ng-show="signup_form.name.$error.maxlength">
Your name cannot be longer than 20 characters
</small>
</div>
</div>
</div>
Is there a way to accomplish the same thing, but use JavaScript instead of custom Angular attributes?
For example, is there a way I can use JavaScript instead of these Angular html attributes: ng-model, ng-minlength, ng-maxlenth, ng-show?
EDIT:
Just to clarify, I'm looking for a solution that uses the Angular JavaScript API. I would like to have a separate JavaScript document (linked from my HTML document) that uses the Angular JavaScript API. For example, is there a way to specify ng-model for a particular form field using the Angular API instead of the custom Angular HTML attribute?
As I understand it, you want to add a directive (for example ng-model) from javascript, similar to how you would do it with jQuery. Short answer: Don't do it.
Longer Answer: It's probably technically possible, but it would violate the basic principles of AngularJS. Your controller should not touch the HTML at all, in fact any code which should directly manipulate the HTML should be placed in a directive. And that directive should be placed on the input directly in your HTML, which is exactly what you wanted to avoid.
If placing directives in your HTML is not practical for your project, then perhaps you should reconsider using AngularJS.
There's a rather long (and well written) answer here on Stackoverflow which explains "how to think in AngularJS", you might find that it's of interest: https://stackoverflow.com/a/15012542/179024
It would also be interesting to know why you want to do this? There is often an "Angular way" of doing things, but it can be different from what we are used to doing.

Zend_Forms and decorators in ZF - Displaying label, input and errors in one container

pretty much ripping my hair out over how badly designed the decorators are in Zend Framework.
I've spent a lot of today and a few other days trying to figure out how to do something that should be a simple frontend task.
Zend_Forms and decorators in my opinion are the worst part of ZF as backend and frontend are not properly seperated. Why is the form class dictating how the HTML should be printed?
All I'm looking for, is something simple like:
<div class="labeledField">
<label for="username">Username</label>
<input type="text" id="username" name="username" />
</div>
<div class="labeledField">
<label for="password">Password</label>
<input type="password" id="password" name="password" />
</div>
The reason I want it like this is because I want the label to sit on top of the field like:
[Username ]
[Password ]
This way I can make the label slightly fade when the input is selected but still remain when the input is selected. Using JS the label is hidden when the input box contains anything. This functionality exists on the Apple shopping cart.
I love the validation parts of Zend_form and I would love how it can be placed in the frontend if backend code wasn't dictating how the HTML looks.
In my opinion it should either take a template (from a frontender with access to the /views/ folder or I should be able to do something like:
<div class="labeledField">
<?php
echo $this->form->username->getLabel();
echo $this->form->username->getElement();
$errors = $this->form->username->getErrors();
if (sizeof($errors) > 0) {
?>
<div class="errors">
<?php
foreach($errors as $error) {
?>
<li><?php echo $error ?></li>
<?php
}
?>
</div>
<?php
}
?>
</div>
But then the templating would allow me to just echo $this->form and have it use the format as above for fields I want to.
No question about it, decorators can take some getting used to. Let me address/answer some of your issues/questions:
pretty much ripping my hair out over how badly designed the decorators are in Zend Framework. I've spent a lot of today and a few other days trying to figure out how to do something that should be a simple frontend task.
Yep, it's a miracle I have any hair left at all.
Zend_Forms and decorators in my opinion are the worst part of ZF as backend and frontend are not properly separated. Why is the form class dictating how the HTML should be printed?
I agree with you here that how the form is to be rendered is a presentation issue, so it's probably more view-related. If you really wanted to separate the concerns, you could create your forms undecorated and then add decorators in your view-script, perhaps using some custom view-helpers. This makes the most sense to me, though I confess I have never bothered to do it.
For examples of a standalone class that sets decorators on a separate form, check out EasyBib_Form_Decorator and Using Zend_Form without Zend Framework MVC
In my opinion it should either take a template (from a frontender with access to the /views/ folder or I should be able to do something like:
You pretty much do have that functionality using the ViewScript decorator.
$form->setDecorators(array(
array('ViewScript', array( // note case
'viewScript' => '_partials/forms/my.phtml', // note case
)));
That said, your desired markup is relatively straightforward using standard decorators:
// not tested, but should be pretty close
$element->setDecorators(array(
'ViewHelper',
'Label',
'Errors',
array('HtmlTag', array('tag' => 'div', 'attribs' => array('class' => 'labeledField'))),
));
Of course, any special styling or client-side manipulation of the form - for example, the Apple cart effect you cite - can be layered on to this markup on the client-side.

Ruby / Mechanize aborts when it finds an accentuated u letter

I want to read this form of a php script using Ruby/Mechanize:
<form name="editevent" method="post" action="/index.php" enctype="multipart/form-data">
<input type="text" name="veranstaltung">
<select name='ortid'>
<option value='2'>Kaminwerk</option>
<option value='3'>Pitú</option>
<option value='4'>Apollo-Center</option>
</select>
<input type="text" name="neutermin" id="neutid" />
<textarea name="beschreibung" cols="40" rows="7"></textarea><br />
<input type="submit" name="button" value="Absenden">
</form>
In Ruby I have got:
form = page.forms.first
form.fields.each { |f| puts f.name }
However Ruby can find only the form elements with the name "veranstaltung" and "ortid"
I found out that the problem ist the "u" letter with the accent on it in the word "Pitú". Proofs: when I print the inner_html of the html code the part of the form looks like this:
<form name="editevent" method="post" action="/index.php" enctype="multipart/form-data">
<input type="text" name="veranstaltung">
<select name='ortid'>
<option value='2'>Kaminwerk</option>
<option value='3'>Pit</form>
The other part of the form has vanished! How can I use that form completely despite of the "ú"?
I would be very glad if anyone could help.
What version of Ruby? It smells like 1.8.7, which is not Unicode savvy. If you can, upgrade to 1.9.2.
It's also important to specify the code-set of the language when parsing the content. Often times that information is in the DOCTYPE statement, but if it isn't you have to give the language a hint of what to expect.
Because those characters are embedded in PHP, they could be UTF-8, or maybe a variant of WIN-1252 or ISO-8951 which implies they'd be a single byte character. Mechanize uses Nokogiri to parse, and it will want to know what the language is to give you the best decoding of the values. Nokogiri will put errors in the errors attribute when it can't parse something to its liking, so you might want to check there.
SO, if I were you, I'd look to see what the DOCTYPE is when the content is sent, and also check the HTTP headers, and see if something will define the codeset.
This is a problem I've encountered many times on the internet because HTML is so poorly written and so often fails to follow the specs.

Resources