You will see I've set the "name" of the textboxes to "newtracks[]" because it will be an array of data to be sent through. Then the code I've added inside chronoforms.php is as follows:if($event=='submit' && $form->form_details->id == $uploadstatus){ $app = JFactory::getApplication(); print_r ($_POST['newtracks']);}For now, I just want to see what is inside $_POST and I don't get the values from those textboxes in $_POST and I'm not sure why.Please assist, let me know if you need more details.ThanksLindy"> Cannot access dynamically created textbox values - Forums

Forums

Cannot access dynamically created textbox values

rhapsidee 18 Apr, 2014
Hello,

I have a form with one hidden field and one submit button, added manually. Then Ive added a multi record loader that loads data from the database. Then in the Custom Code action, I add one checkbox and one textbox for every line displayed from the database. When clicking submit button, Ive added in the code so that it displays what is inside $_POST, and I only get the values from the hidden field and submit button, but no values are passed from the checkboxes and textboxes into $_POST.

I am not a very experienced programmer, so I need some help to know where I can get these values from. I've tried using the form->data as well to get the information but with no luck.

Here is the code I've used in my custom code action, just above the show html action:

<table border=1 frame=below rules=rows>
<tr>
<td width="80"><font style="color:black">DATE</font></td>
<td width="30">USER</td>
<td width="200">TRACK NAME</td>
<td width="150">MP3 NAME</td>
<td width="80">STATUS</td>
</tr>
<tr>
<td width="80"><font style="color:black">DATE</font></td>
<td width="30">USER</td>
<td width="200">TRACK NAME</td>
<td width="150">MP3 NAME</td>
<td width="80">STATUS</td>
</tr>
<tr>
<td width="80"><font style="color:black">DATE</font></td>
<td width="30">USER</td>
<td width="200">TRACK NAME</td>
<td width="150">MP3 NAME</td>
<td width="80">STATUS</td>
</tr>
<?php
foreach($form->data['TrackStatus'] as $detail):
?>
<tr>
<td width="80"><?php echo $detail['cf_created']; ?></td>
<td width="30"><?php echo $detail['cf_user_id']; ?></td>
<td width="200"><?php echo $detail['Approved_Trackname_0']; ?></td>
<td width="150"><?php echo $detail['mp3_upload_21']; ?></td>
<td width="80"><?php echo $detail['Track_Status_0']; ?></td>
<td><input type="checkbox" name="onsite" id="onsite[]"></td>
<td><input type="text" size="30" name="newtracks[]" value="<?php echo $detail['cf_id'] ?>"/></td>
</tr>
<?php
endforeach;
?>
</table>


You will see I've set the "name" of the textboxes to "newtracks[]" because it will be an array of data to be sent through. Then the code I've added inside chronoforms.php is as follows:

if($event=='submit' && $form->form_details->id == $uploadstatus){
	$app = JFactory::getApplication();
        print_r ($_POST['newtracks']);
}



For now, I just want to see what is inside $_POST and I don't get the values from those textboxes in $_POST and I'm not sure why.

Please assist, let me know if you need more details.

Thanks
Lindy
GreyHead 18 Apr, 2014
Hi Lindy,

If you check the Form HTML I suspect that you will find that your HTML is outside the <form></form> tags which would explain why it isn't being submitted.

The Custom Code action has a Mode setting which needs to be set to 'View' to get the output included in the Form HTML.

A tidier approach is to add your code into a Custom Element element from the Advanced Group in the Preview tab. That will let you use PHP and display the result in the form.

In general I use Custom Code actions to process data and add it to the ChronoForms $form->data array then Custom Element elements to get the data from the $form->data array and convert it into HTML for display in my forms.

Bob
rhapsidee 18 Apr, 2014
Thanks Bob, will look into this🙂
rhapsidee 18 Apr, 2014
Yayeeee it worked!! Struggled with this for 2 whole days, should have asked earlier, thanks Bob!
This topic is locked and no more replies can be posted.