I am trying to get field_1 value into the input text and I tried this code but it doesn't work.
function bbg_add_reg_field() {
$field_1= $_POST["signup_username"];
echo '<input name="field_1" id="field_1" value="$field_1" type="text">';
}
add_action( 'bp_before_registration_submit_buttons', 'bbg_add_reg_field' );
The echo value shown inside the input text is $field_1
The value should be a name, say for example peter.
In PHP you can interpolate a string (add variables to a string with $var) only when it is a double quoted string.
From the PHP Documentation
// Outputs: Variables do not $expand $either
echo 'Variables do not $expand $either';
Instead you could do this
echo '<input name="field_1" id="field_1" value="' . $field_1 . '" type="text">';
oh and don't forget htmlspecialchars
echo '<input name="field_1" id="field_1" value="' . htmlspecialchars($field_1) . '" type="text">';
You could also achieve the same using PHP Heredoc. Which goes like this
echo <<<EOF
<input name="field_1" id="field_1" value="$field_1" type="text">
EOF;
Related
I added an extra field to the cart.php using Snippet plugin.
function action_woocommerce_cart_coupon() {
echo '<input type="text" name="card" class="input-text" id="card" value="" placeholder="Card" />';
};
add_action( 'woocommerce_cart_coupon', 'action_woocommerce_cart_coupon');
And I would my own validation when the Apply coupon button is clicked. Unfortunately, There is no way I can get value of this new field.
I downloaded the post in several places but I don't have access to this field.
if ( ! empty( $_POST['card'] ) ) {
echo '<script>console.log("' . $_POST['card'] . '")</script>';
} else {
echo '<script>console.log("PHP error")</script>';
}
function action_woocommerce_applied_coupon( $coupon_code ) {
foreach ($_POST as $key => $value) {
echo '<script>console.log("' . $key . " " . $value . '")</script>';
}
};
add_action( 'woocommerce_applied_coupon', 'action_woocommerce_applied_coupon');
Output:
security ac228a43c2
coupon_code 1
I understand this is called in class-wc-cart.php but I can't understand how I could pass this field to this method. Is anyone able to tell me something about this?
I will also appreciate any other ideas to solve this problem.
I created custom post type named Emails, and added a custom field using advanced custom fields plugin to one post inside the custom post type called email footer, the field is image field that is supposed to show at the bottom of each automatic email going out of the website.
the current code I'm using
function wpcf7ev_verify_email_address2( $wpcf7_form ){
$email_footer = '<html>
<body style="color:#000000;">
<div style="font-size:16px;font-weight:bold;margin-top:20px;">
Regards,
<br/>
$email_footer .= '<img src="http://mysite.col/footer_image.jpg" width="100%" alt=""/>
</div>';
$email_footer .='<div style="display:none;">'.generateRandomString().
'</div></body>
</html>
';
the code is working, it displays the image with this url at the bottom: http://mysite.col/footer_image.jpg
but I don't want hardcoded, I want to be able to modify it with the custom field I created
I looked at ACF documentation and found this, but I don't know how to use it to still show that exact field on custom post type I created:
<?php
$image = get_field('image');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
The code you've outlined from the ACF documentation tells you how to get the image from an ACF field using Image (with type array).
If we were to implement this into your function, we'd have to reference the image from the page somewhere. Without knowing how you're calling this there are a couple of ways you could embed it.
The first way, we pass it through to the function called on the page, like so...
wpcf7ev_verify_email_address2(get_field('image'));
and then update your function like so...
function wpcf7ev_verify_email_address2($image, $wpcf7_form)
{
$email_footer = '<div style="font-size:16px;font-weight:bold;margin-top:20px;">Regards,<br/>';
// get the image from the passed in image function.
$email_footer .= '<img src="' . $image['url'] . '" width="100%" alt="' . $image['alt'] . '"/></div>';
$email_footer .='<div style="display:none;">' . generateRandomString() . '</div>';
}
Or, the second way, if you are calling the function to modify an action or something, you'd have to get the image from whichever page ID / options page it is assigned to in your ACVF settings. This would make your function look a little like this:
function wpcf7ev_verify_email_address2($wpcf7_form)
{
// get image acf field from page with id 1
$image = get_field('image', 1);
// or get image from acf field on options page
// $image = get_field('image', 'options');
$email_footer = '<div style="font-size:16px;font-weight:bold;margin-top:20px;">Regards,<br/>';
$email_footer .= '<img src="' . $image['url'] . '" width="100%" alt="' . $image['alt'] . '"/></div>';
$email_footer .='<div style="display:none;">' . generateRandomString() . '</div>';
}
All of the above is presuming that your function is working as intended, with you needing help grabbing the ACF field, and the image is uploaded. You can wrap your declarations of get_field in if statements if required.
am just confused why such a small difference can make a big problem.
here is the working code with just digits entered into it.
$user_info = get_userdata(70);
echo 'Username: ' . $user_info->user_login . "\n";
this code shows username: sarah
and now same but this time with code inside of it
$number = the_author_meta('ID');
echo $number; // echos 70
$user_info = get_userdata($number);
echo 'Username: ' . $user_info->user_login . "\n";
and with the code below it just shows userame: thats it.
MAke sure you read your code. At this line:
$user_info = get_userdata($number);
You miss a r in the variable $number
Here's the problem:
Replace "the_author_meta" with "get_the_author_meta"
the_author_meta just immediately outputs to the screen the information you're trying to retrieve. That's why it outputs '70'.. If you get rid of the echo in front of it, it'd STILL output that 70.
get_the_author_meta actually returns the value and assigns it to a variable, like you're expecting.
$aaaaaa = $author_id=$post->post_author;
$user_info = get_userdata($aaaaaa);
echo 'Username: ' . $user_info->user_login . "\n";
echo 'User roles: ' . implode(', ', $user_info->roles) . "\n";
echo 'User ID: ' . $user_info->ID . "\n";
echo get_user_option( 'rc_banned', $user_info->ID);
I have a Web Page that contains 1 to many tabs. Each tab has a dynamically created Form. So if there are 4 tabs, I generate 4 forms dynamically in my controller in a foreach loop where I pass the $Id like so:
foreach($ids as $id) {
$html .= $this->createHtml($id);
}
To the following function
private function createHtml($Id)
{
$html .= '<div id="product_'.$Id.'">';
$html .= ' <form id="form_'.$Id.'" name="form_'.$Id.'" class="formatted" method="POST">
<input type="hidden" name="_method" value="PUT">
<fieldset class="border">
{{ form_row(product_form_'.$Id.'.product, {
\'note\' : \'Enter Something\'
}) }}
</fieldset>
</form>';
$html .= ' <br/>';
$html .= '
<div>
Some text
</div>';
$html .= '</div>';
return $html;
}
So that function is called 4 times and keeps adding to $html.
I then pass $html and the 4 product_form->createView() to the twig and output the html like so:
{{html | raw}}
All the html div and form tags are rendered correctly but instead of rendering an input field for product, this gets displayed:
{{ form_row(product_form_'.$Id.'.product, { \'note\' : \'Enter Something\' }) }}
You see? It doesn't recognize that as a symfony input field to render. It thinks it's regular text.
I thought the | raw might have something to do with it so I adjusted my code to display {{form_row... }} without the | raw but that had no affect.
How do I use this API? I can extract some data, but not all of it... I'm a bit lost and I can't find any examples in the documentation. I'm using gapi.class.php.
I have code such as:
$ga = new gapi('user','pwd');
$ga->requestReportData('id',array('browser'),array('pageviews','visits', 'timeOnSite'));
var_dump($ga);
foreach($ga->getResults() as $result)
{
print_r($result);
echo '<strong>'.$result.'</strong><br />';
echo 'Pageviews: ' . $result->getPageviews() . ' ';
echo 'Visits: ' . $result->getVisits() . '<br />';
echo 'Time On site: ' . $result->getTimeOnSite() . '<br />';
}
echo '<p>Total pageviews: ' . $ga->getPageviews() . ' total visits: ' . $ga->getVisits() . '</p>';
The above is working, but then I also want to get other data such as goals... I see this: http://code.google.com/intl/es-ES/apis/analytics/docs/gdata/dimsmets/dimsmets.html
but I'm not really sure how to call each function, or property... I'm really lost, any examples would be appreciated!
GAPI uses magic get methods. You put in the dimensions and metrics that you want and get them using the magic get methods.
For example:
$ga = new gapi('user','pwd');
$ga->requestReportData('id',array('browser'),array('pageviews','visits', 'timeOnSite'));
foreach($ga->getResults() as $result)
{
print_r($result);
echo '<strong>'.$result.'</strong><br />';
echo 'Pageviews: ' . $result->getPageviews() . ' ';
echo 'Visits: ' . $result->getVisits() . '<br />';
echo 'Time On site: ' . $result->getTimeOnSite() . '<br />';
}
echo '<p>Total pageviews: ' . $ga->getPageviews() . ' total visits: ' . $ga->getVisits() . '</p>';
array('browser') is the dimension and array('pageviews','visits', 'timeOnSite') are the metrics. $result->getPageviews() is the magic get method for the pageviews metric.
So, refer to the list and put in the dimensions and metrics you want then return them using the magic get methods of getYourdimension or getYourmetric. Note that get is lowercase and the dimension or metric begins with a capital letter.
See the documentation for more information:
Access metrics and dimensions using magic get methods
With GAPI, when data is returned from Google it is automatically converted into a native PHP object, with an interface to allow the 'get' the value of any dimesion or metric.
For example, if you request the metric 'uniquePageviews' and the dimesion 'pagePath' you can do the following:
foreach($ga->getResults() as $result)
{
echo $result->getUniquePageviews();
echo $result->getPagePath();
}