Jump to content

Sticky form fields using templates


Donovan

Recommended Posts

I have an application that uses the phpBB template engine.  I needed to write some error checking logic but this has raised a problem.  If I catch an error the form is not sticky and refreshes to a blank form after displaying the error message.  The page is where I add a new question for exams.  I don't want them to add the questions if they forgot to identify a correct answer for a multiple choice question.

 

The questions.tpl looks like this.

 

<tr>
<td width="100%">

	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="borderline" align="center">
	 <tr> 
   			<td align="left" valign="top">
			<table width="100%" cellpadding="0" cellspacing="0" border="0"  class="bodyline">
			<tr>
				<td  height="240" valign="top">
<!-- BEGIN question -->
					<form name="{question.FORM_NAME}" action="{question.ACTION}" method="post">
						{question.FORM_HIDDEN}
						{question.CONTENTS}

					</form>
<!-- END question -->		
				</td>
			</tr>
			</table>
  			</td>
	</tr>
	</table>
	</td>
</tr>

 

And the last part of my question.php where I add new questions looks like this where I check for the existence of an answer.

elseif ( ($mode == 'addresp' ) &&( ( $userdata['user_level'] == ADMIN ) || ( in_array ($cid, $course['teaches'] ) )) ){

....

for ( $i=1; $i<$anscounter; $i++) {
				$question_values['points'] .= (empty($_POST["point$i"]) ?  0 $_POST["point$i"])) ."#";
			}																											
			$question -> setValue($question_values);					
			$sql = $question -> operation('addresp');

			//Lets check if the question has at least one correct answer - SFD 6/9/2010
			$point_array = explode("#",$question_values['points']);				
			$answer_exists = false; // Set to default
			if(in_array("1",$point_array))  {
            		$answer_exists = true;  // The answer exists - so insert into database.	
				$db->sql_query($sql);				
				$message = '  Question has been Created';
			$nav_path .= $question_values['qname'];
			$template->assign_block_vars('question',array('ACTION' => '', 
										'FORM_NAME' => 'questions',
										'FORM_HIDDEN' => '',
										'CONTENTS' => '<br><br><span class="catHead">'.$message.'</span>  <a href="javascript:void(0);" class="action" onClick="window.close()">Close Window</a><br><br>'
									));

        			}else{

//This is where I need to make the form sticky and re-display.  All the values that are on the form look like this...

$question_values['qstem'] =  (isset($_POST['ques_stem']) ? $_POST['ques_stem'] : '') ;
				$question_values['qname'] =  (isset($_POST['ques_name']) ? $_POST['ques_name'] : '') ;					
				$question_values['qch1'] =  (isset($_POST['ques_ch1']) ? $_POST['ques_ch1'] : '') ;
				$question_values['qch2'] =  (isset($_POST['ques_ch2']) ? $_POST['ques_ch2'] : '') ;
				$question_values['qch3'] =  (isset($_POST['ques_ch3']) ? $_POST['ques_ch3'] : '') ;
				$question_values['qch4'] =  (isset($_POST['ques_ch4']) ? $_POST['ques_ch4'] : '') ;
				$question_values['qch5'] =  (isset($_POST['ques_ch5']) ? $_POST['ques_ch5'] : '') ;
				$question_values['qch6'] =  (isset($_POST['ques_ch6']) ? $_POST['ques_ch6'] : '') ;
				$question_values['qch7'] =  (isset($_POST['ques_ch7']) ? $_POST['ques_ch7'] : '') ;
				$question_values['qch8'] =  (isset($_POST['ques_ch8']) ? $_POST['ques_ch8'] : '') ;
				$question_values['qch9'] =  (isset($_POST['ques_ch9']) ? $_POST['ques_ch9'] : '') ;
				$question_values['media_name'] =  (isset($_POST['media_name']) ? $_POST['media_name'] : '') ;				
				$question_values['feedback'] =  (isset($_POST['feedback']) ? $_POST['feedback'] : '') ;

}

 

I don't know what I need here when I need to redisplay this data.

 

}else{

$message = 'Error in Updating Question. You must have at least one correct answer marked.';

$nav_path .= $question_values['qname'];

$template->assign_block_vars('question',array('ACTION' => '',

'FORM_NAME' => 'questions',

'FORM_HIDDEN' => '',

'CONTENTS' => $question -> operation('add')

));

}

 

My operation('add') is not sticky and looks like this.

 

if ( ($mode == 'add' ) &&( ( $userdata['user_level'] == ADMIN ) || ( in_array ($cid, $course['teaches'] ) )) ) {

				$question = new question();
				$question -> setIDs($cid,$ca,$_POST['qtype'], $userdata['session_user_id']);

				$template->assign_block_vars('question',array('ACTION' => append_sid('questions.php?ARG1='.$cid.'&ARG2='.$ca), 
										'FORM_NAME' => 'questions',
										'FORM_HIDDEN' => '',
										'CONTENTS' => $question -> operation('add')
									));


		} // eof add

 

Any help is appreciated.

 

 

Link to comment
https://forums.phpfreaks.com/topic/204292-sticky-form-fields-using-templates/
Share on other sites

  • 1 month later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.