How to call data from another file - php

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;

Related

Chrome and Opera delete record data when editing a record

I'm new to php and mysql, I'm using a script like CMS, my problem that I can write new article, but when editing it on chrome or opera all of article content is not shown for editing and deleted and it's not the case with firefox, here below the edit php script,
<?php echo link_tag('assets/themes/' . $this->selected_theme . '/'.UIKIT_VERSION.'/css/' . $this->session->userdata('selected-theme')); ?>
<script src="<?php echo base_url() ?>assets/themes/<?php echo $this->selected_theme . '/ckeditor/ckeditor.js'; ?>"></script>
<h4><i class="uk-icon-edit"></i> edit step </h4>
<hr class="uk-article-divider">
<?php $this->load->view('user/template/default/flash_data') ?>
<?php
$attributes = array(
'method' => 'post',
'class' => 'uk-form'
);
echo form_open_multipart('articles/edit/' . $step->step_id, $attributes) ?>
<div class="uk-form-controls">
<label class="uk-form-label">
<?php if ($step->step_photo_url) { ?>
<img src="<?php echo $step->step_photo_url ?>" class="uk-thumbnail-small"/><br/>
<?php } else { ?>
<i class="uk-icon-image uk-icon-large"></i>
<?php } ?>
</label><br/>
<input type="file" name="step_photo_url"/>
<br/>
<label class="uk-form-label uk-text-muted uk-text-bold">Or Enter a URL</label>
<input class="uk-width-90 uk-form-large" type="text" placeholder="Image Url" name="step_photo_url"
value="<?php echo set_value('step_photo_url', $step->step_photo_url, true) ?>"/>
<?php echo form_error('step_photo_url') ?>
</div>
<div class="uk-form-controls uk-margin-top">
<div class="uk-form-controls uk-margin-bottom">
<input value="<?php echo $step->step_title ?>" name="step_title" class="uk-width-90 uk-form-large"
type="text" placeholder="step title">
<?php echo form_error('step_title'); ?>
</div>
<div class="uk-margin-bottom uk-form-controls">
<textarea name="step_description" rows="4" class="uk-width-90 uk-form-large ckeditor"
placeholder="Enter Description"><?php echo set_value('step_description', $step->step_description,
true) ?></textarea>
<?php echo form_error('step_description'); ?>
</div>
<a href="<?php echo site_url('articles/delete/' . $step->step_id) ?>"
class="uk-button uk-button-danger uk-float-left">Delete</a>
<button class="uk-button uk-button-success uk-float-right">Save</button>
</div>
</form>
This is a hard problem to guess at with what you have, though it sounds like a mistake I made when I first started working with PHP and databases. That is converting output in value fields using htmlspecialchars($value,ENT_QUOTES). If you have this value:
$content = '"What are you talking about?" she asked, "that is ridiculous!"';
then you echo into an input field for editing:
<input name="test" value="<?php echo $content ?>" />
The html output is:
<input name="test" value=""What are you talking about?" she asked, "that is ridiculous!"" />
which has two sets of quotes, and most browsers then will show that field as blank. Then when you click the update, it clears out what you previously had. To get around that, you should use:
<input name="test" value="<?php echo htmspecialchars($content,ENT_QUOTES) ?>" />
which then gives you this output in the field:
"What are you talking about?" she asked, "that is ridiculous!"
but the html looks like this:
<input name="test" value=""What are you talking about?" she asked, "that is rediculous!"" />
This is just a stab in the dark based on your description and based on personal experience. You will have to show your html or some of the php values for a more clear picture.

Wordpress get_option not working

I want to get array value from get_option following this answer to add more but its not working for me. I can't find where I have gone wrong. It works when I am not using array.
Working code (without array):
add_action('admin_init', function() {
register_setting('my-test', 'option1');
register_setting('my-test', 'option2');
register_setting('my-test', 'option3');
});
function my_function() {
?>
<div class="wrap">
<h1>Dashboard</h1>
<form action="options.php" method="post">
<?php
settings_fields('my-test');
do_settings_sections('my-test');
?>
<input type="text" name="option1" value="<?php echo esc_attr( get_option('option1') ); ?>"" />
<?php submit_button(); ?>
</form>
</div>
<?php
}
Then I want to use array to get_option. I followed the answer I mention above but it gives me error. Please see this code below.
Not working code (with array):
add_action('admin_init', function() {
register_setting('my-test', 'option1');
register_setting('my-test', 'option2');
register_setting('my-test', 'option3');
});
function my_function() {
$new_option = esc_attr(get_option('option2'));
?>
<div class="wrap">
<h1>Dashboard</h1>
<form action="options.php" method="post">
<?php
settings_fields('my-test');
do_settings_sections('my-test');
?>
<input type="text" name="option1" value="<?php echo esc_attr( get_option('option1') ); ?>"" />
<input type="text" name="option2[first]" value="<?php echo $new_option['first']; ?>" />
<input type="text" name="option2[second]" value="<?php echo $new_option['second']; ?>" />
<?php submit_button(); ?>
</form>
</div>
<?php
}
Am I missing something? Any help is much appreciated. Thanks in advance.
Remove esc_attr function in the below line. This function takes string as input and returns string. Since you are dealing with array this will cause error.
$new_option = get_option('option2');
You should use the function where you are actually outputting the value.
<input type="text" name="option2[first]" value="<?php echo esc_attr( $new_option['first'] ); ?>" />
Hope it helps. :)

Possible errors in session

I just want to ask what are the possible errors in SESSION... Because I've been suffering from my bugs! My codes are right but I don't know why it has happened that when I click the submit button it's supposed to pass the value that i declare but it always declare the last value I declared(it means I can't renew the value! once I declared my value that is permanent which is wrong because every time you click the submit it suppose to give new variable)
home.php
<form method="post" action="1home.php">
<label id="checkinD">
<h3>Day</h3>
<Input id="chiD" name="chiD" type="number" min="<?php echo $_SESSION["day_today"]; ?>" max="<?php echo $_SESSION["day_count"]; ?>" required />
</label>
</form>
$chiD = $_POST['chiD'];
$_SESSION["chiD"] = "$chiD";
1home.php
<form method="post" action="2home.php" onsubmit="return validate()">
<label id="checkinD">
<h3>Day</h3>
<Input id="chiD" name="chiD" type="text" value = " <?php echo $_SESSION["chiD"]; ?>" readonly />
</label>
</form>
BTW There is also a crazy one that occurs on my codes it's working very smoothly without logical errors but every 4 hours my codes will have logical errors without my fault!!! it's like automated bugs appeared every hour.
and sometimes to make it work I need to erase the name of my form then replace it again and typed the word that I erased. What kind of shit is this?
PHP, you need to session_start() before assigning values to your
session variables. The date_today variable holds the present datetime, and date_count variable holds a random number.
Though i can not see your full code but here's the working solution.
home.php
<?php
session_start();
$_SESSION["day_today"] = date("Y-m-d H:i:s");
$_SESSION["day_count"] = rand();
?>
<form method="post" action="1home.php">
<label id="checkinD"><h3>Day</h3></label>
<Input id="chiD" name="chiD" type="number" min="<?php echo $_SESSION["day_today"]; ?>" max="<?php echo $_SESSION["day_count"]; ?>" required />
<input type="submit" value="FORM 2" name="btn_form2" >
</form>
home1.php
<?php
session_start();
if(isset($_POST['chiD'])):
$chiD = $_POST['chiD'];
$_SESSION["chiD"] = $chiD;
?>
<form method="post" action="2home.php" onsubmit="return validate()">
<label id="checkinD"><h3>Day</h3></label>
<input id="chiD" name="chiD" type="text" value = "<?php echo $_SESSION["chiD"]; ?>" readonly />
</form>
<?php echo "Day: ". $_SESSION['day_today']; ?>
<br>
<?php echo "Day Count: ". $_SESSION['day_count']; ?>
<?php else: ?>
<h4> Sorry! Somethinh went wrong. </h4>
<?php endif; ?>
Here's a screenshot of the result
Hope this helps

In codeigniter, how will i know which checkboxes are checked?

I have a dynamic number of checkbox in my view,like this:
<?php foreach($documents as $row): ?>
<input type="checkbox" name="options[]" value="<?php echo $row->docu_title?>"><?php echo $row->docu_title?><?php endforeach; ?>
And I set the rule for this group of checkboxes to be required in my controller:
$this->form_validation->set_rules('options[]','options', 'required');
How will i know which checkboxes are checked? so whenever there are errors on the other fields i can still show the user the checkboxes that has been checked already. like this:
<input style="" type="text" class="form-control" name="ClientName" id="ClientName" value="<?php echo set_value('ClientName'); ?>">
You could use form helper 's set_checkbox() function.
This permits you to display a checkbox in the state it was submitted. The first parameter must contain the name of the checkbox, the second parameter must contain its value, and the third (optional) parameter lets you set an item as the default (use boolean TRUE/FALSE). Example:
<input style="" type="checkbox" class="form-control" name="ClientName" id="ClientName"
value="<?php echo set_value('ClientName'); ?>" <?php echo set_checkbox('ClientName', '1'); ?> />
For reference visit CodeIgniter User Guide Version 2.2.0
should be something like this
<?php foreach($documents as $row): ?>
<input type="checkbox" name="option[]" value="<?php echo $row->docu_title?>" <?php echo set_checkbox('option[]', $row->docu_title); ?>>
<?php echo $row->docu_title?>
<?php endforeach; ?>

PHP Show if hides update fields, but they get overwritten with an empty string

This is one of those ones that probably falls between PHP and SQL stuff.
Basically I have a page where some update fields are displayed depending on who is logged, for example:
<?php if ($row_Users['UserID']=="101"){ ?>
<input <?php if (!(strcmp($row_lodges['101_finalist'],"Yes"))) {echo "checked=\"checked\"";} ?> type="checkbox" name="101_finalist" value="Yes"/>
<input type="text" class="rankfield" name="101_rank" value="<?php echo($row_lodges['101_rank']); ?>" />
<?php } ?>
<?php if ($row_Users['UserID']=="102"){ ?>
<input <?php if (!(strcmp($row_lodges['102_finalist'],"Yes"))) {echo "checked=\"checked\"";} ?> type="checkbox" name="102_finalist" value="Yes"/>
<input type="text" class="rankfield" name="102_rank" value="<?php echo($row_lodges['102_rank']); ?>" />
<?php } ?>
The issue I have is that if User101 is logged in and updates fields 101_finalist and 101_rank, it overwrites 102_finalist and 102_rank with an empty string.
Is it possible to prevent each user from seeing the other fields for other users, and prevent the existing values for those other users not be overwritten?
Hope that makes sense!
Thank you.
You'll want to do something like this. It's basically what #taco is saying:
<?php
// Set's the default user logged in
$_def = ($row_Users['UserID'] == "101")? '101': '102'; ?>
<input <?php if (!(strcmp($row_lodges[$_def.'_finalist'],"Yes"))) { ?>checked="checked"<?php } ?> type="checkbox" name="<?php echo $_def; ?>_finalist" value="Yes"/>
<input type="text" class="rankfield" name="<?php echo $_def; ?>_rank" value="<?php echo ($_def == '101')? $row_lodges['101_rank']:$row_lodges['JA_rank']; ?>" />
You can do something like
<?php
$userid = $row_Users['UserID'];
$finalist = $userid."_finalist";
$rank = $userid."_rank";
?>
<input <?php if (!(strcmp($row_lodges[$finalist],"Yes"))) {echo "checked=\"checked\"";} ?> type="checkbox" name="101_finalist" value="Yes"/>
<input type="text" class="rankfield" name="101_rank" value="<?php echo($row_lodges[$rank]); ?>" />

Categories