|
-
Mar 20th, 2012, 10:33 AM
#1
Thread Starter
Hyperactive Member
Use a php function in echo statement
I've made this code, which disables a textbox if $TaxiDest has a value, however for my form to work i need this code to work [<?php phpfmg_hsc("field_17", ""); ?>] within the value tag of the textbox.
Here is the code im working with:
Code:
<?php if($TaxiDest == "")
{echo "<input type='text' name='field_17' id='field_17' value='phpfmg_hsc('field_17', '');' class='text_box'>";}
else
{echo "<input type='text' name='field_17' id='field_17' disabled='disabled' value='$TaxiDest' class='text_box'>";}
?>
by the way when i run the page [phpfmg_hsc(] is displayed in the textbox
ive made a few changes but still not got it working heres a live link
Thanks in advance,
chris1990
Last edited by chris1990; Mar 20th, 2012 at 11:01 AM.
If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.
If you fail, try and try again, its the only way to success.
-
Mar 20th, 2012, 11:36 AM
#2
Re: Use a php function in echo statement
There are a couple of ways; my preference is:
PHP Code:
<?php if($TaxiDest == ""): ?> <input type='text' name='field_17' id='field_17' value='<?php echo phpfmg_hsc('field_17', '');?>' class='text_box'> <?php else: ?> <input type='text' name='field_17' id='field_17' disabled='disabled' value='<?php echo $TaxiDest;?>' class='text_box'> <?php endif; ?>
This makes for the cleanest division of PHP from HTML. It works by exiting the PHP context as needed to output markup.
But this would also work:
PHP Code:
echo "<input type='text' name='field_17' id='field_17' value='".phpfmg_hsc('field_17', '')."' class='text_box'>";
It works by string concatenation.
...as would this, for example:
PHP Code:
echo "<input type='text' name='field_17' id='field_17' value='", phpfmg_hsc('field_17', ''), "' class='text_box'>";
It works by echoing multiple strings.
-
Mar 20th, 2012, 01:04 PM
#3
Thread Starter
Hyperactive Member
Re: Use a php function in echo statement
Thanks for your help, but i still cant get it working. The problem is that it doesn't fill field_17 in the email i receive, when i use the $TaxiDest (it shows on screen but not in email). It does work though when i type it manually.
Code:
<?php if($TaxiDest == ""): ?>
<input type='text' name='field_17' id='field_17' value='<?php phpfmg_hsc("field_17", "");?>' class='text_box'>
<?php else: ?>
<input type='text' name='field_17' id='field_17' disabled='disabled' value='<?php phpfmg_hsc("field_17", "$TaxiDest");?>' class='text_box'>
<?php endif; ?>
I have the same problem with this line:
Code:
<input type="text" name="field_28" id="field_28" disabled="disabled" value="<?php phpfmg_hsc("field_28", "$TaxiPrice"); ?>" class='text_box'>
Yet no problems here:
Code:
<input type="text" name="field_15" id="field_15" value="<?php phpfmg_hsc("field_15", ""); ?>" class='text_box'>
Thanks,
Chris1990
If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.
If you fail, try and try again, its the only way to success.
-
Mar 21st, 2012, 11:05 AM
#4
Re: Use a php function in echo statement
Assuming that phpfmg_hsc() returns a string, you'll need to preface it with echo in all of those cases:
PHP Code:
<?php echo phpfmg_hsc("field_17", "");?>
If that's not necessarily the case, then it might help to see the code of phpfmg_hsc().
-
Mar 23rd, 2012, 11:48 PM
#5
Thread Starter
Hyperactive Member
Re: Use a php function in echo statement
Sorry for late reply, been busy this week.
I tried prefacing phpfmg_hsc() with echo and it still doesn't include it in the email.
Code:
function phpfmg_hsc($field, $default){
echo isset($_POST[ $field ])
? HtmlSpecialChars( $_POST[ $field ] )
: $default;
}
# Generated By Free PHP Formmail Generator : http://phpfmg.sourceforge.net
If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.
If you fail, try and try again, its the only way to success.
-
Mar 26th, 2012, 11:04 AM
#6
Re: Use a php function in echo statement
Since the function echos its result rather than returning one, you won't need to use echo before it.
You're saying that a field isn't appearing properly in an email - are you showing the code that is used for that email?
-
Mar 27th, 2012, 03:58 AM
#7
Thread Starter
Hyperactive Member
Re: Use a php function in echo statement
I've found the problem is due to the field being disabled, by removing the disabled property i receive its value in the email.
I think im going to have to hide the field rather than disable and use a div to display the value.
Thanks Chris1990.
If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.
If you fail, try and try again, its the only way to success.
-
Mar 27th, 2012, 04:28 AM
#8
Thread Starter
Hyperactive Member
Re: Use a php function in echo statement
Thanks for your help SambaNeko, ive got it working now.
Code:
<?php if($TaxiDest == ""): ?>
<input type='text' name='field_17' id='field_17' value='<?php phpfmg_hsc("field_17", "");?>' class='text_box'>
<?php else: ?>
<input type='text' name='field_17' id='field_17' style="visibility:hidden; display:none;" value='<?php phpfmg_hsc("field_17", $TaxiDest);?>' class='text_box'>
<input type='text' name='field_17a' id='field_17a' disabled="disabled" value='<?php phpfmg_hsc("field_17", $TaxiDest);?>' class='text_box'>
<?php endif; ?>
Chris1990.
If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.
If you fail, try and try again, its the only way to success.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|