Jump to content

How to POST values to the custom fields in php file.


t8mas062184

Recommended Posts

Hi Everyone,

 

I would like to seek your advice for my problem. Honestly, I am new to php programming so bear with my 'possible easy question'. However, I don't know how to search my problem in google because it is very complicated for me. Here is my problem:

 

I have a php file, lets say 'file 1', that will post values to the next php file, lets say 'file 2', that would receive the values posted by 'file 1'. However, I cannot post values to some fields in 'file 2' because these fields are just being created at the time the 'file 2' was called. Meaning, the field name of these custom fields are just getting created at the time the 'file 2' was called. My problem here is I can successfully post values to the hard-coded fields in 'file 2' but not on these custom fields. Would you know how to resolve these?

Link to comment
Share on other sites

Actually, this is a simple php file with post values from 'file 1'

 

<form enctype="multipart/form-data" action="bug_report_advanced_page.php" method="POST">
<input type="text" name="category" value="Application"/>
<input type="text" name="severity" value="50"/>
        <input type="text" name="custom_field_19" value="Developer"/>
<p><input type="submit" value="Start Processing..." /></p>
</form>

 

I would not posts all the content of 'file 2' but i would post the code for the hard-coded fields and the custom fields.

This are the hard-coded fields. As you can see, I can see the names of the fields so the values are posted when i called 'file 2'

<!-- Category -->
<tr <?php echo helper_alternate_class() ?>>
<td class="category" width="30%">
	<?php echo '<span class="required">*</span>', lang_get( 'category' ) ?> <?php print_documentation_link( 'category' ) ?>
</td>
<td width="70%">
	<?php if ( $t_changed_project ) {
		echo "[" . project_get_field( $t_bug->project_id, 'name' ) . "] ";
	} ?>
	<select <?php echo helper_get_tab_index() ?> name="category">
		<?php 
			if ( is_blank( $f_category ) ) {
				echo '<option value="" selected="selected">', string_attribute( lang_get( 'select_option' ) ), '</option>';
			}

			print_category_option_list( $f_category ); 
		?>
	</select>
</td>
</tr>
<!-- Severity -->
<tr <?php echo helper_alternate_class() ?>>
<td class="category">
	<?php echo lang_get( 'severity' ) ?> <?php print_documentation_link( 'severity' ) ?>
</td>
<td>
	<select <?php echo helper_get_tab_index() ?> name="severity">
		<?php print_enum_string_option_list( 'severity', $f_severity ) ?>
	</select>
</td>
</tr>

 

Then this is the custom field being created at the time the 'file 2' was called (e.g. through browser)

 

<!-- Custom Fields -->
<?php
$t_custom_fields_found = false;
$t_related_custom_field_ids = custom_field_get_linked_ids( $t_project_id );

foreach( $t_related_custom_field_ids as $t_id ) {
	$t_def = custom_field_get_definition( $t_id );
	if( ( $t_def['display_report'] || $t_def['require_report']) && custom_field_has_write_access_to_project( $t_id, $t_project_id ) ) {
		$t_custom_fields_found = true;
?>
<tr <?php echo helper_alternate_class() ?>>
<td class="category">
	<?php if($t_def['require_report']) {?><span class="required">*</span><?php } ?><?php echo string_display( lang_get_defaulted( $t_def['name'] ) ) ?>
</td>
<td>
	<?php print_custom_field_input( $t_def, ( $f_master_bug_id === 0 ) ? null : $f_master_bug_id ) ?>
</td>
</tr>
<?php
	}
} # foreach( $t_related_custom_field_ids as $t_id )
?>


<?php if ( $t_custom_fields_found ) { ?>
<!-- spacer -->
<tr class="spacer">
<td colspan="2"> </td>
</tr>
<?php } # custom fields found ?>

 

How I know the name of the custom field? it is because I 'view source' the actual 'file 2' when I called in through browser. Here is the sample custom field generated when I checked it through 'view source':

<tr class="row-2">
<td class="category">
	Responsibility	</td>
<td>
	<select tabindex="20" name="custom_field_19" size="3"><option value="Host">Host</option><option value="Developer">Developer</option><option value="Unknown">Unknown</option></select>	</td>
</tr>

Link to comment
Share on other sites

Sorry guys if I confused you. Basically, I know all the field names when I 'view source' the actual php page. But the actual php file does not have these field names (hardcoded) and some of these field names are constructed at the time you accessed the php file because it contain some if conditions before rendering these custom fields. Meaning, I cannot pass on the values unless these field names were created at the time I accessed the php page. So my question is, is there a way that I can just call the php page and then were it was already rendered completely, I will posts the values that I want to be pre-populated to the php page?

Link to comment
Share on other sites

I'm still not 100% sure of what you're trying to do.  That said, remember that $_POST is an array.  You can obtain the key-value pairs in a variety of ways, even if they're dynamically generated (foreach, in_array, [m]array_key_exists[m], to name a few examples).  This will allow you to check the kinds of values coming into the system, either in if/else statements, or a switch.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.