I am trying to define block of html $result_html=""; to use inside the shortcode like this:
[ms-protect-content id="7001"]' . $result_html . '[/ms-protect-content]
I am trying to define the following html as a $result_html:
<p>
<input type="hidden" name="product_id" value="<?php echo $post->ID; ?>" />
<input type="submit" id="send_product_enquiry" value="<?php _e( 'Send Enquiry', 'wc_enquiry_form' ); ?>" class="button" />
</p>
<?php do_action( 'product_enquiry_after_form' ); ?>
I ran into the problem with correctly writing the quotes inside the quotes.
I know that I should add a backslash \ before the quotes to escape them, but in this case it is just getting a way to confusing for my understanding of php.
My code currently looks like this with my corrections:
$result_html='
<p>
<input type="hidden" name="product_id" value="<?php echo $post->ID; ?>" />
<input type="submit" id="send_product_enquiry" value="<?php _e( \'Send Enquiry\', \'wc_enquiry_form\' ); ?>" class="button" />
</p>
<?php do_action( \'product_enquiry_after_form\' ); ?>
';
According to Dreamweaver, there are no errors, but when the code is rendered, it is not correct, the <?php echo $post->ID; ?> is not passing, but I can't find my errors.
Can someone please correct me, thanks
btw, I changed from $result_html=""; ( double quotes ) to $result_html=''; ( single quotes ), not sure if it's ok
You seem to have a fundamental lack of understanding about how quoting works in php. There is no reason for you to have php opening and closing tags inside of single quotes!
Let me know how this works.
$result_html='
<p>
<input type="hidden" name="product_id" value="' .$post->ID . '" />
<input type="submit" id="send_product_enquiry" value="' . _e( 'Send Enquiry', 'wc_enquiry_form' ) . '" class="button" />
</p>' . do_action( 'product_enquiry_after_form' );
Related
I'm trying to create a custom index.php page and would like to make the users search result save inside of a search box. Here was what I peiced together that works a little bit:
<li class="result-searh"><form role="search" method="get" id="searchform" class="searchform" action="http://droogle.dil/">
<div>
<input type="text" value=<?php printf( esc_html__( '%s', stackstar ), '<span>' . get_search_query() . '</span>' ); ?> name="s" id="s">
<input type="submit" id="searchsubmit" value="Search">
</div>
</form></li>
Which looks like this:
When I search for "my search". As you can see, its is showing up. Just a bit funny looking. I am quite terrible at PHP so forgive me if this looks bad. I Frankenstein'd this code together using other plugins' code.
-
EDIT: changed it to this:
<input type="text" value=<?php printf( esc_html__( '%s', stackstar ), get_search_query()); ?> name="s" id="s">
and now when I search for "Hello I am joe" inspecting the element gives me this:
<input type="text" value="hello" I="" am="" joe="" name="s" id="s">
Going out on an untested limb and proposing enclosing the <php .. ?> with double quotes might fix this:
<input type="text" value="<?php printf( esc_html__( '%s', stackstar ), get_search_query()); ?>" name="s" id="s">
Hello my English is not so good.
I need to load the data from place HTML file 1 to $logos, but that doesn't work.
I don't know how to do it.
I believe the problem is here: esc_attr($feed->readmore_logon);.
File 1 :
<div class="field rssap-field-container1">
<p><label for="rssap-display-readmore1">
<input type="checkbox" <?php if ($feed->logo_readmore) : ?>checked="checked"<?php endif; ?> value="1" name="logo_readmore" id="rssap-display-readmore1" />
<?php esc_html_e('Display link to source', 'rss-autopilot'); ?>
</label></p>
<input type="text" size="50" name="readmore_logon" value="<?php echo esc_attr($feed->readmore_logon); ?>" />
<span title="<?php esc_html_e('HTML allowed. Use %LINK% placeholder to add URL', 'rss-autopilot'); ?>" class="rss-tooltip">?</span>
</div>
File 2, the esc_attr($feed->readmore_logon); doesn't work.
Can somebody help?
$logos = esc_attr($feed->readmore_logon);
....
update_post_meta($postId, 'haus', $logos);
thx an everyon ho give a ansser !! i get it work thets is the code
$logos = $this->readmore_logon;
I modified the Searchform.php to:
'search_id' => 'id', 'form_action' => ( 'http://local.amleo.com/newps/pulldata.php'
For the first Search widget, to go to a custom PHP page that displays results for something else.
The next Search Widget, I'd like to search the category "AML Hot Topics". Not sure how I can do that. Any ideas??
So you can visualize: http://i.imgur.com/HSd9EEZ.png
The 1st Search is the one I modified the Searchform.php for. The 2nd is the one I'm not sure about.
I'm no super-duper PHP wizard by any means, but I can follow directions pretty decently.
You don't need two target for search, instead you can do it using something like this
One form for newps
<form method="get" id="searchform" action="<?php echo esc_url( home_url() ); ?>">
<input type="text" value="<?php echo esc_attr( get_search_query() ); ?>" name="s" id="s" />
<input type="hidden" value="newps" name="key" />
<input type="submit" id="searchsubmit" value="<?php esc_attr_e('Search','Aggregate'); ?>" />
</form>
Another for AML
<form method="get" id="searchform" action="<?php echo esc_url( home_url() ); ?>">
<input type="text" value="<?php echo esc_attr( get_search_query() ); ?>" name="s" id="s" />
<input type="hidden" value="aml" name="key" />
<input type="submit" id="searchsubmit" value="<?php esc_attr_e('Search','Aggregate'); ?>" />
</form>
Create a search.php file in your theme's root folder, something like this
get_header();
// if you get `key` then it will be your custom search
// otherwise, default search will be performed
if(!empty($_GET['key'])) {
$key = $_GET['key']; // it will be either 'newps' or 'aml'
$search = $_GET['s'];
// modify the query using your $key and $search param
query_posts(...);
}
if (have_posts()) :
while(have_posts()): the_post();
// the_title() and more...
endwhile;
endif;
// reset the query if modified
if(!empty($key)) wp_reset_query();
get_sidebar();
get_footer();
Data or value in $description from database is
<div>Henry</div>
My HTML Code
<input type="textbox" id="textbox" value=""/>
<input type="hidden" id="hidden" value="<?php echo $description; ?>"/>
Output :
If the code be
<input type="hidden" id="hidden" value='<?php echo $description; ?>'/>
Its working fine !..Any one please tell me the issue ?
You are trying to have HTML code inside the value of a hidden input in a form? That doesn't sound right.
If you need to keep it as it is, you should at least use htmlentities to make it a string:
<input type="hidden" id="hidden" value="<?php echo htmlentities($description); ?>"/>
An example:
<?php
$str = "A 'quote' is <b>bold</b>";
// Outputs: A 'quote' is <b>bold</b>
echo htmlentities($str);
// Outputs: A 'quote' is <b>bold</b>
echo htmlentities($str, ENT_QUOTES);
?>
Your code becomes like this...
<input type="hidden" id="hidden" value = "<div><a href="www.google.com" > Henry </a></div> "/>
You can divide this as...
<input type="hidden" id="hidden" value = "<div><a href="www.google.com" >
Henry
</a></div>
"/>
That's how you get Henry"/>
Here comes 2 issues,
First of all use htmlentities to convert all applicable characters to HTML entities.
htmlentities($description);
And Its fair to use Single quote instead of double quotes. Ref link
By default, SGML requires that all attribute values be delimited using either double quotation marks (ASCII decimal 34) or single quotation marks (ASCII decimal 39). Single quote marks can be included within the attribute value when the value is delimited by double quote marks, and vice versa
look at the different between " and ':
if your code is :
$description = <div>Henry</div>
and
<input type="hidden" id="hidden" value="<?php echo $description; ?>"/>
so it's actually means
<input type="hidden" id="hidden" value="<div>Henry</div>"/>
and the " that before the url closes the "value", so the value is actually -
value="<div><a href="
so try to use ' instead of " on the url (google) OR in the value (not both).
This is how your browser sees the code:
<input type="textbox" id="textbox" value="<div>Henry</div>
"/>
See how the double-quotes don't make sense?
If you want to keep double-quotes you need to go with htmlentities.
$description = htmlentities($description);
<input type="hidden" id="hidden" value="<?php echo $description; ?>"/>
Also, your link "www.google.com" will point to a page called www.google.com RELATIVE to your directory. Be sure to use ABSOLUTE path: http://www.google.com
A simple replace in here like this
<div><a href='www.google.com'>Henry</a></div>
or like this
<input type="textbox" id="textbox" value=""/>
<input type="hidden" id="hidden" value='<?php echo $description; ?>'/>
but not both should do the trick.
http://php.net/manual/en/function.strip-tags.php
Try this:
div><a href='www.google.com'>Henry</a></div>
<input type="textbox" id="textbox" value=""/>
<input type="hidden" id="hidden" value='<?php echo strip_tags($description); ?>'/>
I am hoping that there is someone that can help me with this question. I am a ASP programmer and not sure how this works in PHP
echo '</textarea>
<input type="hidden" name="g_word" id="g_word" value="$_POST[g_word]" />
<input type="hidden" name="article_no" id="article_no" value="$_POST[article_no]" />
</form>';
How do I use the $_POST[article_no] in the example above? In asp I would have used it like this "+Request.Form("article_no")+". How would I do it in PHP?
Thanks
if you use the solution posted above, please add some basic protection against xss injection - for example htmlentities($_POST['article_no'])
echo '</textarea><input type="hidden"
name="g_word" id="g_word"
value="'.$_POST[g_word].'" /> <input
type="hidden" name="article_no"
id="article_no"
value="'.$_POST[article_no].'" /></form>';
Close the single quote, and use a dot to concatonate
$value = "cool";
echo 'My String is ' . $value . '!!!!!';
In this case, the dot is the same as the plus concatenation operator.
echo '</textarea><input type="hidden"
name="g_word" id="g_word"
value="'.$_POST['g_word'].'" /> <input
type="hidden" name="article_no"
id="article_no"
value="'.$_POST['article_no'].'" /></form>';
You have to put article_no between '-s.
I think I've understood your question; feel free to let me know if not.
In PHP (and many other languages), the number of quotes around a string determines how the string is parsed. If single quotes are used, then nothing in the string is parsed (except for another single quote — it will need to be escaped with a backslash if you intend it to be a part of the string rather than the closequote). If double-quotes are used, more things are parsed, but you accordingly have to do more escaping.
There are a variety of ways of dealing with inserting variables in strings.
Using double quotes:
echo "</textarea><input type=\"hidden\"
name=\"g_word\" id=\"g_word\"
value=\"$_POST['g_word']\" /> <input
type=\"hidden\" name=\"article_no\"
id=\"article_no\"
value=\"$_POST['article_no']\" /></form>';
Using single quotes:
echo '</textarea><input type="hidden"
name="g_word" id="g_word"
value="' . $_POST['g_word'] . '" /> <input
type="hidden" name="article_no"
id="article_no"
value="' . $_POST['article_no'] . " /></form>';
Or, in my opinion the most elegant way, using (s)printf to return a formatted string:
printf('</textarea><input type="hidden"
name="g_word" id="g_word"
value="%s" /> <input
type="hidden" name="article_no"
id="article_no"
value="%d" /></form>', $_POST['g_word'], $_POST['article_no']);
Variables aren't interpreted inside of single quotes. However, they are inside double quoted strings, or heredoc. Personally, I'd switch out of PHP mode entirely, like so:
<?php
//...
?>
</textarea><input type="hidden"
name="g_word" id="g_word"
value="<?php echo htmlentities($_POST['g_word']); ?>" /> <input
type="hidden" name="article_no"
id="article_no"
value="<?php echo htmlentities($_POST['article_no']); ?>" /></form>
<?php
//...
This is even more readable if you do some formatting and use short tags -- although, it requires a non-default configuration option, and there are other disadvantages, primarily if you have XML docs parsed by the PHP interpereter, or your app is going to be installed on servers you don't control.
That'd look like this:
<form>
<textarea>
<?
//...
?>
</textarea>
<input type="hidden" name="g_word" id="g_word" value="<?= htmlentities($_POST['g_word']); ?>" />
<input type="hidden" name="article_no" id="article_no value="<?= htmlentities($_POST['article_no']); ?>"/>
</form>
<?
//...