Jump to content

HTML code ignored in php file


alwaysme

Recommended Posts

hello helpers

 

below is a code for an application form. It works fine when a user completes all required fields, however when the form is sent with missing fields it refreshes with an error msg. The problem is this new "refreshed" page is the form and all HTML under it, anything above it in the code. I do have a menu and a nice header but that wont appear since everything above the php code is ignored

 

 

anyone have an idea how to fix this for me?

 



<?php
/*
* application form
*/

ob_start();
require_once "../lib/tools.php";
no_cache();


?>

<html>
<head>
<title>testng</title>
<meta http-equiv='Content-Type' content='text/html; charset=<?php echo $charset; ?>'>
<link href="css/template_css.css" rel="stylesheet" type="text/css" />
</head>
<body class="mainbody">



STUFF HERE WONT APPEAR.........................
.........................WHEN user submits form and fails to complete required fields......
........................-----------------------------------


:home: :About:  :Services:  etc etc



<?php


include "top2.php";
if(!$allow_register) {
    ob_end_clean();
    exit();
}


/* cash all the form fields, produce the hashed names from it
* and put it in array with real names */
$field_types=get_field_types('resume');


/*
* Show a form
*/
if($check!=$msg_resume_register[FINISH]) {
    BeginForm(2,0,$msg_resume_register[HEADER1]);
    FrmEcho("$msg_resume_register[TEXT]</td></tr>");
    if($job2)
FrmEcho("
    $msg_resume_register[LOGIN]</td></tr>");
    FrmItemFormat("<tr><td width=31% bgcolor=#dbe5ef align=right class=whiteborders><b>$(req) $(prompt) $(bad)</b></td>
<td width=69% class=whiteborders bgcolor=#f5f5f5 colspan=2>$(input)</td></tr>\n");
    display_fields('resume','',1," active=1 and type<>22 and type<>21",array(
'bold_login'=>1/*,'fparam'=>' size=40'*/));
    frmecho("<input type=hidden name=job2 value='$job2'>");
#    EndForm('Continue');
    FrmEcho("<tr><td colspan=3 align=left bgcolor=#f5f5f5 class=whiteborders>
<input type=hidden name=check value='$msg_resume_register[CONTINUE_]'>
<input type=image src=../images/continue.jpg border=0></td></tr></table>");

}

/* step 2 */
if(($check==$msg_resume_register[CONTINUE_] && !$bad_form) || $check==$msg_resume_register[FINISH]) {
    if($check==$msg_resume_register[CONTINUE_]) {
unset($check);
unset($_POST['check']);
unset($HTTP_POST_VARS['check']);
$form_output='';
    }
    BeginForm(2,1,$msg_resume_register[HEADER2]);
    FrmItemFormat(" <b>$(req) $(prompt) $(bad)</b>
$(input)\n");
    display_fields('resume','',1," 0=1",array('show_resume'=>1));
    // display fields for upload .doc files and other attachments
    list($resume_file,$resume_file_required)=sqlget("select resume_file,resume_file_required from job_config");
    if($resume_file) {
$nfiles=1;
for($i=1;$i<=$nfiles;$i++) {
    InputField($msg_resume_register[RESUME_FILE],"f_resume_doc[]",array('type'=>'file',
        'required'=>($resume_file_required?'yes':'no'),'validator_param'=>array('type'=>'file')));
}
$nfiles=0;
for($i=1;$i<=$nfiles;$i++) {
    InputField($msg_resume_register[ADD_ATTACH],"f_resume_attach[]",array('type'=>'file','validator_param'=>array('type'=>'file')));
}
    }
    while(list($var,$val)=each($_POST)) {
if($var!='check')
    if(is_array($val))
	while(list($a,$b)=each($val))
	    FrmEcho("<input type=hidden name=$var"."[$a] value=\"$b\">\n");
    else
	FrmEcho("<input type=hidden name=$var value=\"$val\">\n");
    }
    EndForm($msg_resume_register[FINISH]);
}

# ْل‏هي üôï ?
if($bad_form) {
    $page_id=$x_title=$x_header=$x_footer=$x_bg=$x_has1=$x_has2=$x_has3=$x_has4=$x_has5=$x_hasbg=
$x_color=$x_font_size=$x_shading='';
    $_POST['check']=$_POST['check_x']=$_POST['check_y']='';
    $check=$check_x=$check_y='';
    ob_end_clean();
    include "top2.php";
}
ShowForm();

/*
* Submit form
*/
if($check==$msg_resume_register[FINISH] && !$bad_form) {
    $fields=$vals=array();
    if($f_resume) {
$f_resume=addslashes(stripslashes($f_resume));
$fields[]='resume';
$vals[]=$f_resume;
    }

    /* we want to fetch confirmation message body here
     * to expand some macros in a loop below */
    // Job Application Email
    list($body,$from,$subject,$html,$return_path,$reply_to)=sqlget("
select body,from_addr,subject,html,return_path,reply_to from system_emails
where email_id=2 and active=1");
    if(!$from)
$from="noreply@$email_domain";
    // New Resume email
    list($staff_from,$staff_subject,$staff_body,$staff_active,
$staff_reply_to,$staff_return_path)=sqlget("
select from_addr,subject,body,active,reply_to,return_path from system_emails
where email_id=4");
/*    $fp=fopen($url,'r');
    if($fp) {
while(!feof($fp)) {
    $html.=fgets($fp);
}
fclose($fp);
    }
*/
    /* process fields in a loop */
    reset($_POST);
    while(list($field,$val)=each($_POST)) {
$tmp_arr=explode('_',$field);
if($tmp_arr[0]=='resume' && $tmp_arr[1]!='id') {
    array_shift($tmp_arr);
    $field=join('_',$tmp_arr);
    if(!in_array($field_types[$field],$dead_fields)) {
	if($field_types[$field]==7 || $field_types[$field]==24) {
	    $f_login=$val;
	}
	if($field_types[$field]==5) {
	    if($val)
	    	$val2='Yes';
	    else $val2='No';
	}
	else if(in_array($field_types[$field],$multival_arr)) {
	    if(in_array($field_types[$field],$manyval_arr)) {
		$val2=array();
		for($i=0;$i<count($val);$i++) {
		    list($tmp)=sqlget("
			select name from resume_$field"."_options
			where resume_$field"."_option_id='$val[$i]'");
		    $val2[]=$tmp;
		}
    		$val=join('|',$val);
		$val2=join('; ',$val2);
	    }
	    else 
		list($val2)=sqlget("
		    select name from resume_$field"."_options
		    where resume_$field"."_option_id='$val'");
	}
	else $val2=$val;
        $fields[]="custom_".$field;
	$vals[]=$val;
    }
    else if($field_types[$field]== {
	$f_password=$val;
    }
    $body=str_replace("%$field%",$val2,$body);
    $html=str_replace("%$field%",$val2,$html);
    $staff_body=str_replace("%$field%",$val2,$staff_body);
    $staff_subject=str_replace("%$field%",$val2,$staff_subject);
}
    }

    $fields=join(',',$fields);
    $vals=join("','",$vals);
    if($vals) {
        $vals=",'$vals'";
        $fields=",$fields";
    }

    if($f_login) {
$q=sqlquery("insert into user (name,password) values ('$f_login','$f_password')");
$user_id=sqlinsid($q);
sqlquery("insert into user_group (user_id,group_id) values ('$user_id',4)");
$user=$f_login;
$password=$f_password;
checkuser(4);
    }
    $f_first=addslashes(stripslashes($f_first));
    $f_last=addslashes(stripslashes($f_last));
    $f_address=addslashes(stripslashes($f_address));
    $f_address2=addslashes(stripslashes($f_address2));
    $f_city=addslashes(stripslashes($f_city));
    $f_state=addslashes(stripslashes($f_state));
    // fix state
    list($state)=sqlget("select code from states where name='$f_state'");
    if($state)
$f_state=$state;
    $f_zip=addslashes(stripslashes($f_zip));
    $f_phone=addslashes(stripslashes($f_phone));
    $q=sqlquery("
        insert into resume (status,added,added_by,user_id $fields)
values (1,now(),'$user_id','$user_id' $vals)");
    $resume_id=sqlinsid($q);
    /* add skills to resume */
    for($i=0;$i<count($f_skills);$i++) {
        sqlquery("
    insert into skillsets (resume_id,skill_id)
    values ('$resume_id','$f_skills[$i]')");
list($tmp)=sqlget("select name from skills where skill_id='$f_skills[$i]'");
$skill[]=$tmp;
    }
    // resume files
    while(list($idx,$f)=each($_FILES[f_resume_doc][tmp_name])) {
if(is_uploaded_file($_FILES[f_resume_doc][tmp_name][$idx])) {
    if(($err=is_valid_upload($_FILES[f_resume_doc][name][$idx]))=='') {
        $doc=addslashes(file_get_contents($_FILES[f_resume_doc][tmp_name][$idx]));
	sqlquery("insert into resume_docs (resume_id,fname,doc)
		  values ('$resume_id','".addslashes($_FILES[f_resume_doc][name][$idx])."','$doc')");
    }
    else echo "<p>$err</p>";
}
    }
    // additional attachments
    while(list($idx,$f)=each($_FILES[f_resume_attach][tmp_name])) {
if(is_uploaded_file($_FILES[f_resume_attach][tmp_name][$idx])) {
    if(($err=is_valid_upload($_FILES[f_resume_attach][name][$idx]))=='') {
        $attach=addslashes(file_get_contents($_FILES[f_resume_attach][tmp_name][$idx]));
	sqlquery("insert into resume_attach (resume_id,fname,attach)
		  values ('$resume_id','".addslashes($_FILES[f_resume_attach][name][$idx])."','$attach')");
    }
    else echo "<p>$err</p>";
}
    }

    list($jobno)=sqlget("select name from resume_fields where type=22");
    list($jobcateg)=sqlget("select name from resume_fields where type=21");
    list($jobskills)=sqlget("select name from resume_fields where type=20");
    list($email_field)=sqlget("select name from resume_fields where type=7 or type=24");
    $jobno=castrate($jobno);
    $jobcateg=castrate($jobcateg);
    $jobskills=castrate($jobskills);
    list($ref,$jobtitle)=sqlget("select ref,title from jobs where job_id='$job2'");

    /* notify all subscribed admins */
    if($staff_active) {
if(!$staff_from)
    $staff_from="noreply@$email_domain";
        $staff_body=str_replace("%$jobno%",$ref,$staff_body);
$staff_body=str_replace("%jobtitle%",$jobtitle,$staff_body);
$q=sqlquery("
    select distinct email from user,user_group
    where user.user_id=user_group.user_id and
	user_group.group_id=3 and notify=1 and email<>''");
while(list($admin_email)=sqlfetchrow($q)) {
    mail2($admin_email,$staff_subject,
	str_replace('%link%',
	    "$server_name2/admin/resumes.php?op=edit&id=$resume_id",
	    $staff_body),"From: $staff_from".
	    ($staff_reply_to?"\nReply-To: $staff_reply_to":"").
	    ($staff_return_path?"\nReturn-Path: $staff_return_path":""));
}
    }

    /* confirmation email for the user himself */
    if($job2) {
        $body=str_replace("%$jobno%",$ref,$body);
$html=str_replace("%$jobno%",$ref,$html);
$body=str_replace("%jobtitle%",$jobtitle,$body);
$html=str_replace("%jobtitle%",$jobtitle,$html);
$skill=join(', ',$skill);
        $body=str_replace("%$jobskills%",$skill,$body);
$html=str_replace("%$jobskills%",$skill,$html);
list($category)=sqlget("
    select name from job_categories
    where category_id='$f_category'");
$body=str_replace("%$jobcateg%",$category,$body);
        $html=str_replace("%$jobcateg%",$category,$html);
$body=str_replace("%firstname%",stripslashes($resume_First_Name_),$body);
$html=str_replace("%firstname%",stripslashes($resume_First_Name_),$html);
$body=str_replace("%lastname%",stripslashes($resume_Last_Name_),$body);
$html=str_replace("%lastname%",stripslashes($resume_Last_Name_),$html);
$msg = new message($from,$_POST["resume_".castrate($email_field)],$subject);
$msg->body($body);
if($reply_to)
    $msg->headers.="\nReply-To: $reply_to";
if($return_path)
    $msg->headers.="\nReturn-Path: $return_path";
if($html)
    $msg->body($html,'text/html');
if($body)
    $msg->send();

/* confirmation email to staff */
list($body,$from,$subject,$html,$reply_to,$return_path)=sqlget("
    select body,from_addr,subject,html,reply_to,return_path from system_emails
    where email_id=5 and active=1");
        $body=str_replace("%jobno%",$ref,$body);
$html=str_replace("%jobno%",$ref,$html);
$subject=str_replace("%jobno%",$ref,$subject);
$body=str_replace("%link%","$server_name2/admin/resumes.php?op=edit&id=$resume_id",$body);
$html=str_replace("%link%","<a href=$server_name2/admin/resumes.php?op=edit&id=$resume_id>$server_name2/admin/resumes.php?op=edit&id=$resume_id</a>",$html);
if(!$from)
    $from="noreply@$email_domain";

$q=sqlquery("select distinct email from user,user_group
	     where user.user_id=user_group.user_id and
	        group_id=3 and notify=1 and email<>''");
while(list($admin_email)=sqlfetchrow($q)) {
    $msg = new message($from,$admin_email,$subject);
    $msg->body($body);
    if($reply_to)
	$msg->headers.="\nReply-To: $reply_to";
    if($return_path)
	$msg->headers.="\nReturn-Path: $return_path";
    if($html)
	$msg->body($html,'text/html');
    if($body)
	$msg->send();
}
    }

    ob_end_clean();
    if($job2)
        header("Location: jobsearch.php?job2=$job2".($f_login?"":"&resume_id=$resume_id").
    "&msg=".urlencode($msg_resume_register[LOGGED]));
    else
header("Location: jobsearch.php?msg=".urlencode($msg_resume_register[sUCCESS]));
    exit();
}

?>





----------when user forgets to complete required fields the page regreshes with
the form however any HTML above the form will  be ignored------
--------anything under displays without a problem......







</body>
</html>
code]

Link to comment
Share on other sites

may I ask why you're buffering the output?

 

I didn't really dive into it that much after noticing you're buffering the output.  If not used correctly, that will cause a shiz load of probs.

 

This is how I suggest your re-do your inline PHP if removing the output buffering doesn't work or is not the problem.

 

<?php

 

// SESSION LOGIC

 

// INCLUDE / STARTUP LOGIC

 

// CODE/MYSQL LOGIC, CODE STORED IN OUTPUT VARIABLE(S)

?>

 

<!-- HTML CODE START -->

 

OUTPUT PHP VARIABLE(S)

 

<!-- HTML CODE END -->

 

<?PHP

 

// FUNCTIONS USED IN CODE LOGIC

 

?>

Link to comment
Share on other sites

hello, i did not create that code, it a script  :-[ the only buffering i know is windows media player when it starts load...

 

all i want to say is that anything in the code above the php will not show, anything under displays normal...

 

this occur when fields are not completed and page refreshes

 

anyone have a step solution 4 me

Link to comment
Share on other sites

where is $allow_register being set? (eg look for a string exactly: "$allow_register =" or "$allow_register=" in all file included or used before this code (eg the tools.php file and anything included in this file)

 

i assume it is a setting in some config somewhere to allow people to register... try setting $allow_register = "yes"; at the top between the <?php and ?> tags...

 

hope this helps,

Link to comment
Share on other sites

hi uniflare

 

i looked inside the included files and include files within them too

 

all of them

 

include "$currdir/spaw/spaw_control.class.php";

include "$currdir/lib/mysql.php";

include "$currdir/lib/my_auth.php";

include "$currdir/lib/forms.php";

include "$currdir/lib/format.php";

include "$currdir/lib/http.php";

include "$currdir/lib/rights.php";

 

 

ob_start();

require_once "../lib/tools.php";

require_once "../display_fields.php";

include_once "../lib/misc.php";

include_once "../lib/mail.php";

 

 

 

sucks as i couldnt find what you said :(

i tried to do this with putting all the HTML above the form in a seperate file and did the following

 

<?php

include "html_above_form.php";
include "top2.php";
if(!$allow_register) {
    ob_end_clean();
    exit();
}

 

But it didnt work!!! ......anyone have any clue for me?

its a resume register form for job recruitment...

 

the HTML displays when i visit the page, but if someone forgets to complete a field and submits the form, it refreshs but ignores ALL html above the php code

Link to comment
Share on other sites

nono, stick with your original script u gave us, just add "$allow_register = true;" to the top.

 

no output be cause an OB buffer has been started (ob_start()), you need ob_get_contents() to put into a variable and then ob_end_clean() to stop the script catching the output.

Link to comment
Share on other sites

also, use notepad++ its search features are much more feature full. for instance you can search entire folders for a specific string in all the files it can, it then gives you line numbers of the files it found the string on. very handy,

 

if(!$allow_register) {
    ob_end_clean();
    exit();
}

this line is the line i believe is the line stopping the output. it says if the variable either is false or not been set or similar it will exit the script without sending the buffered content. try commenting out these lines. (though this seems a very lazy way of dealing with a specific event, personally i would code it properly and give answers to the client.).

 

or you could try instead of just "exit()", use "exit('$allow_register has not been properly set');" - then u will know where u r in the script and whats happening...kinda.

 

(the logic of this code seems strange to me somehow... but nm its prolly me)

Link to comment
Share on other sites

Uniflare, thanks for your persistant helping

 

i know what youre saying seems very specific to you, but for me its very complex, sorry...So  do i just change the line

 

include "top2.php";
if(!$allow_register) {
    ob_end_clean();
    exit();
}

 

to

 

include "top2.php";
if(!$allow_register = true;) {
    ob_end_clean();
    exit();
}

 

like that?

and thanks for recommending that program it will save me so much time

 

Link to comment
Share on other sites

 

guys neither solution work...and i wish i have time to understand all that programing thats why i purchased this script for 180$... im stuck and cannot get it to display right...the support takes forever sending tickets to them...i already have 3 "bug" tickets open so i dont want to flood them with this as its only a cosmetic thing...

 

back to the issue....i tried

<?php

include "top2.php";
if(!$allow_register)
{
   echo " my html stuff here";
    ob_end_clean();
    exit();
}

 

wont work either....please anyone know how to bypass this ob thing?

Link to comment
Share on other sites

gosh finally i solved this

thanks to all who helped especially uiniflare...i experimented and placed the code above the first instance "<?php

" and it worked

so silly......

 

 

in conclusion...its just shame that you get great responses before u buy the software and when u buy it i recieve one liner comments from the developers. I will not mention the company i bought the script from (180$) and will give them another chance.

 

Link to comment
Share on other sites

be careful how you edit scripts like this, even the most minute changes can create unnoticable but major logic flaws. which may not show straight away.

 

if you really need help with this script (because it is commercial), gimme a shout ill PM you my email, add me to msn or something.

 

glad you got it working at least. for $180 i would of thought it would work from the box , ul m8.

 

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.