I have added a custom field in a post (wp-themes/template/modal-question.php) like this
<input type="checkbox" name="anonymous" value="true">
<span><?php _e('Go Anonymous', ET_DOMAIN); ?></span>
and variable is
<?php if(isset($_POST['anonymous1']))
{ $post_author = 3; echo $post_author; }
?>
I need to pass this varible '$post_author' ($_GET or $_POST) into another file post.php (Insert query into DB file), which resides in wp-includes/post.php
Please let me know if there's a way to do it.
Thanks in advance.
Here you go:
One time create this:
$GLOBALS['anonymous1'] = 'Your Value';
Then you get in any template of WordPress
echo $GLOBALS['anonymous1'];
Edit:
<?php
if(isset($_POST['anonymous1'])) {
$GLOBALS['anonymous2'] = $_POST['anonymous1'];
echo $GLOBALS['anonymous2'];
}
?>
Related
<?php $content = $_POST['content']?>
<p>Page title: <input type='text' name='title' value="<?php $content ?>"/></p>
I would like to know if something like this is either possible, or if theres a work around, like a way to save the previously entered content as the value. Any help is greatly appreciated.
Save it in a session and retrieve it anywhere using the key just start the session like below :
<?php
// Start the session
session_start();
?>
<?php
// Set session variables
$content = $_POST['content']
$_SESSION["content"] = $content;
echo "Session variables are set."+ $_SESSION["content"] ;
?>
If you want to do it with PHP you need to learn about sessions and cookies.
Here is an example with cookies
<?php
start_session();
if(isset($_GET["title"])) {
if(isset($_SESSION["oldTitle"])) {
// do what you want to do
}
// update to the new value
$_SESSION["oldTitle"] = $_GET["title"];
}
I currently have a form that will let you create a family.
FamilyForm.php
$description = new Textarea(self::KEY_FAMILY_DESCRIPTION);
$description->setAttribute("id", self::KEY_FAMILY_DESCRIPTION);
$description->setLabel("Description");
$this->add($description);
$status = new Hidden(self::KEY_FAMILY_STATUS);
$status->setAttribute("id", self::KEY_FAMILY_STATUS);
$this->add($status);
$save = new Button(self::KEY_SAVE_BTN);
$save->setAttributes(array("id", self::KEY_SAVE_BTN));
$save->setLabel("Save");
$save->setValue("Save");
$this->add($save);
Create.phtml
<?php echo ctrlGroup($this, ProjectFamilyForm::KEY_FAMILY_DESCRIPTION, !($this->admin)); ?>
<?php echo ctrlGroup($this, ProjectFamilyForm::KEY_FAMILY_STATUS, !($this->admin)); ?>
<div class="form-actions">
<?php $save = $this->form->get(ProjectFamilyForm::KEY_SAVE_BTN); ?>
<?php $save->setAttribute("class", "btn btn-primary"); ?>
<?php echo $this->formSubmit($save); ?>
<a class="btn" href="<?php echo $this->url('home'); ?>">Cancel</a>
</div>
This works and allows me to input the description and the status of the family upon creation. However, everytime a family is created the status should be "active". However, the setValue() method seems to not be working.
I am not expert of ZEND but to do this some ways are there:-
most preferable way:- Make you db table field set type and set the default value to active.
Create a hidden field with predefined active value.
Please check this link for help:- http://forums.zend.com/viewtopic.php?t=2079
this is my first time to use codeigniter to make a web site.
My problem is as follow:
My view file contains:
<label class="control-label ">Insert Number of photos : </label>
<?php echo form_open('project_controller/no_of_pics'); ?>
<input name="no_pics" placeholder="Insert a number" type="text" value="<?php echo set_value('no_pics'); ?>" >
<input type='submit' name='submit' value='Insert' />
<?php echo form_close() ?>
<?php $no_pic=''; ?>
<?php echo $no_pic; ?>
<br><br>`
My controller file contains:
public function no_of_pics(){
$this->load->view('control_panel');
$number=$this->input->post('no_pics');
$hoho = array('no_pic' => $number );
$this->load->view('control_panel',$hoho);
}
and I wrote that line the .htaccess file:
$route['project_controller/no_of_pics'] = "/project_controller/no_of_pics";
my problem is that I can't get the no_pics back to the view, it is supposed to check the number through validation rules in the controller but I want firstly to get the number back to the view file
when I wrote the code above I get the number back but in a plain page of the view file without any styling and in the top the number I inserted in the input form not even where I want to use.
3-01-2015
I think I knew what the problem is, but I still don't know how to fix it . I have an other method in that controller
"project_controller" is:
public function project($page = 'home'){
if ( ! file_exists ('application/views/'.$page.'.php')){
show_404();
}
$this->load->view($page);
}
and I wrote in the route.php file:
$route['(:any)'] = 'project_controller/project/$1';
so I think the problem is "function no_of_pics()" can not view the page properly when sending a variable to it as function project() is responsible for that , so what is the solution now?
You must supply the field name via the first parameter of the function. The second (optional) parameter allows you to set a value for the form.check here
set_value('no_pics',$no_pic);
You can try this technique
$hoho['no_pic'] =$number;
$this->load->view('control_panel',$hoho);
I think then you find it on view page.
You need to remove this line from view file
<?php $no_pic=''; ?>
It reset the variable that passes from the controller.
It seems my code is correct, however the posted variables in the form will not echo in the update user settings page in the form. I have echoed the posted ids from the input in the database but I cannot get the variables to show.
I have done this in Codeigniter fine but am trying to do it in pure php with my own framework.
$users = new Users($db); comes from my init.php file that is called at the beginning of the file below.
when I
<?php var_dump($user['first_name'])?>
I get Null
<input type="text" name="first_name" value="<?php if (isset($_POST['first_name']) )
{echo htmlentities(strip_tags($_POST['first_name']));} else { echo
$user['first_name']; }?>">
Hoi Stephen,
Try print_r($_POST["first_name"]); instead of var_dump();
or just for all:
print_r($_POST);
best regards ....
add this at the top of your html page
#extract($_REQUEST);
and put is just to check and after checking remove the below line
print_r($_REQUEST);
hope this help .
I likes to assign posted values to a variable,
In view i wrote the code,
<?php echo $this->Form->create('Register'); ?>
<fieldset>
<?php echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->input('Confirm password');
?>
</fieldset>
Form->end(__('Submit'));
and in controller,
if($this->request->is('post')){
//print_r($this->data);
$uname = $this->request->data('username');
echo "uname".$uname;
exit;
}
The problem is that i didnt get the value on $uname.
Make sure your debug is enabled. Use this - pr($this->request->data); to see what's in that variable. The CakePHP form naming data usually looks something like this
$this->request->data['Formname']['fieldname']
In your case it should be
$this->request->data['Register']['username']
please try using this code
$this->params['form']['YOUR_VARIABLE_NAME']
or
$this->data['FORMNAME']['YOUR_VARIABLE_NAME']