php - cloning form elements and the return a template file -
i building website, on click of link can clone form elements, wanting know that, when send $_post
controller , check information submitted correct, how return template has enough elements errors can rectified, example original form looks this,
<fieldset class="entry"> <label for="email_address">email address</label> <input type="text" name="email_address[]" value="" class="text small"/> <label for="firstname">firstname</label> <input type="text" name="firstname[]" value="" class="text small"/> <label for="surname">surname</label> <input type="text" name="surname[]" value="" class="text small"/> </fieldset>
how can return correct amound of fieldsets based on $_post?
to answer this:
how can return correct amount of fieldsets based on $_post?
if each fieldset has 1 instance of each bracketed[] field name, can count how many submitted (of of fields).
$number_of_fieldsets = count((array) $this->input->post('email_address'));
i've used $this->input->post()
(since you're using ci) in case value not set (it return false), may use isset()
logic instead if wish.
i've cast array here in case return value of $this->input->post('email_address')
false (count return 0) or reason, string (count return 1). mild attempt @ being defensive, want handle unexpected results own methods.
once again, doesn't matter field choose count.
Comments
Post a Comment