Jump to content

[SOLVED] Minor tweek needed on a current script...


Recommended Posts

I have a script, (which I did not create) that makes form fields required…

[code]<?

function formatText($inputName,$text) {

                       if ($_SERVER['REQUEST_METHOD']=="POST") {

                                   if(empty($_POST[$inputName])) {

                                               echo '<span class="redBold">'.$text.'</span>'; 

                                               $_SESSION['ispassed']=false;  

                                   } 

                       else {echo $text;}

                       }

                       else echo $text;

           }

?>

 

and then:

 

<td><? formatText("nmF","First:"); ?></td>

 

This way works fine, but what I am now trying to do is to put it into a php page that is already echoing an output.

 

Basically:

<td>’.formatText("nmF","First:").’</td>

Problem is, all the text gets echoed at the top of the page, not where I want it, in the <td>.

I’ve tried to change all the “echos” and tried <td>’.$formatText("nmF","First:").’</td>

but it throws errors…

 

Any ideas?[/code]

Well, post the entire code then.

 

<td>.formatText("nmF","First:").</td>

 

That is obviously not the entire line...there has to be an echo or print in there.

 

This is the entire code...

[code]<?

function formatText($inputName,$text) {

                        if ($_SERVER['REQUEST_METHOD']=="POST") {

                                    if(empty($_POST[$inputName])) {

                                                echo '<span class="redBold">'.$text.'</span>'; 

                                                $_SESSION['ispassed']=false;  

                                    } 

                        else {echo $text;}

                        }

                        else echo $text;

            }

?>

 

If you want to see it in action, go here: http://www.carcityofdanbury.com/apply.php?applicant=single

 

I am now trying to change that page, so I need to change the code as well....[/code]

No...I don't want the code to the function. I want the code to where you are trying to USE the function.

 

 

<?
//Required Fields
	function formatText($inputName,$text) {
		if ($_SERVER['REQUEST_METHOD']=="POST") {
			if(empty($_POST[$inputName])) {
				echo '<span class="redBold">'.$text.'</span>'; 
				$_SESSION['ispassed']=false;  
			} 
		else {echo $text;}
		}
		else echo $text;
	}
if(isset($_GET['regType'])); switch($_GET['regType']) {
	case 'Rep': 
		$regType = '
<table>
<tr>
<td valign="top">
<!-- START LEFT -->
<div id="sctnTle">Personal Information</div>
<div id="sctnHldr">
<table>
<tr>
	<td class="frm">'.formatText("nmF","First") .'</td>
	<td width="10" rowspan="2"> </td>
	<td class="frm">M.</td>
	<td width="10" rowspan="2"> </td>
	<td class="frm">'.formatText("nmL","Last") .'</td>
</tr>
<tr>
	<td><input id="input" type="text" name="nmF" size="20" autocomplete="off" value="'.$POST_nmF.'" /></td>
	<td><input id="char1" type="text" name="nmM" size="1" autocomplete="off" maxlength="1" value="'.$POST_nmM.'" onKeyup="autotab(this, document.form.nmL)" /></td>
	<td><input id="input" type="text" name="nmL" size="24" autocomplete="off" value="'.$POST_nmL.'" /></td>
</tr>
<tr><td class="frmPad" colspan="5">'.formatText("email1","Email Address") .'</td></tr>
<tr><td  colspan="5"><input id="input" type="text" name="email1" size="40" autocomplete="off" value="'.$POST_email1.'" /></td></tr>
<tr><td class="frmPad" colspan="5">'.formatText("email2","Confirm Email Address") .'</td></tr>
<tr><td  colspan="5"><input id="input" type="text" name="email2" size="40" autocomplete="off" value="'.$POST_email2.'" /></td></tr>
</table>
<table>
<tr><td class="frmPad">Time Zone</td></tr>
<tr><td>'.$timezones.'</td></tr>
</table>
</div>

<div id="sctnTle">Login Information</div>
<div id="sctnHldr">
<table>
<tr><td class="frm">'.formatText("uname","Desired Username") .'</td></tr>
<tr><td><input id="input" type="text" name="uname" size="35" autocomplete="off" value="'.$POST_uname.'" /></td></tr>
<tr><td class="frmPad">'.formatText("pass1","Password") .'</td></tr>
<tr><td><input id="input" type="password" name="pass1" size="35" autocomplete="off" value="'.$POST_pass1.'" /></td></tr>
<tr><td class="frmPad">'.formatText("pass2","Confirm Password") .'</td></tr>
<tr><td><input id="input" type="password" name="pass2" size="35" autocomplete="off" value="'.$POST_pass2.'" /></td></tr>
</table>
</div>';
break;
}

?>

Problem is, all the text gets echoed at the top of the page, not where I want it, in the <td>.

I’ve tried to change all the “echos” and tried <td>’.$formatText("nmF","First:").’</td>

but it throws errors…

 

So it is printing out how you want it, it's just not showing up in the right spot? If thats the case, then it's an HTML problem, not PHP.

 

Throwing errors? What kind of errors?

 

I'm just confused now :o

Look at this page: http://bestsalesreps.com/index.php?main=004&regType=Rep here the error I am having is clearly shown.

Instead of the input names "First" , "Last" etc echoing where they should (above the input box) they are showing up at the top of the page...

 

That I what I am trying to solve...

Look at this page: http://bestsalesreps.com/index.php?main=004&regType=Rep here the error I am having is clearly shown.

Instead of the input names "First" , "Last" etc echoing where they should (above the input box) they are showing up at the top of the page...

 

That I what I am trying to solve...

 

Anyone???

Got it...

function formatText($inputName,$text)
{
    if ($_SERVER['REQUEST_METHOD']=="POST") {
        if (empty($_POST[$inputName])) {
            return '<span class="redBold">'.$text.'</span>';
            $_SESSION['ispassed']=false;
        } else {
            return $text;
        }
    } else {
        return $text;
    }
}

 

Had to change all "echo"s to "return".

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.