Custom Widget Not Saving Values to Database
I'm trying to create a widget that will allow you to pick a CTA and a
Landing Page from two separate drop down menus. The drop downs are
populated based on two custom post types which is working fine. My problem
is that I can't figure out how to save the values to teh database (i.e.,
clicking save on the widget in the admin doesn't commit the values to the
database.
Here are the relevant functions from my widget class called cta_widget. (I
left out the code for the 2nd dropdown as it's identical).
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
/* Strip tags (if needed) and update the widget settings. */
$instance['cta_id'] = $new_instance['cta_id'];
$instance['url_id'] = $new_instance['url_id'];
return $instance;
}
function form( $instance ) {
/* Set up some default widget settings. */
$defaults = array( 'cta_id' => '23', 'url_id' => '28');
$instance = wp_parse_args( (array) $instance, $defaults );
?>
<p>
<label for="<?php echo $this->get_field_name( 'cta_id' );
?>"><?php _e( 'CTA:' ); ?></label>
<select name="<?php echo $this->get_field_name( 'cta_id' );
?>" id="cta_id<?php echo $this->get_field_name( 'cta_id' );
?>" style="width:100%;">
<option value=""></option>
<?php
$posts = get_posts(
array(
'post_type' => 'locable_ctas',
'numberposts' => -1
)
);
if($posts)
{
foreach( $posts as $p )
{
if ($p==$selected)
{
$selected = "selected = 'selected'";
}
else
{
$selected = "";
}
echo '<option value="' . $p->ID . '" '.$selected.'>'
.$p->post_title . '</option>';
}
}
?>
</select>
</p>
}
Saturday, 24 August 2013
Finding the exact path of the file
Finding the exact path of the file
I am using the fileUpload control. When I upload the file, I want to find
the exact location of the file.
I tried using
string fname= Server.MapPath(FileUpload2.FileName);
string fname= FileUpload2.FileName;
string fname= FileUpload2.PostedFile.FileName;
2,#3 gave me the name of the file, #1 gave me the the path of my website
location.
I do not know what is the difference between 2 and 3, why both gave me
same results.
I read somewhere, that you cannot get the path. Is it true ? If not, what
code should I use ?
I am using the fileUpload control. When I upload the file, I want to find
the exact location of the file.
I tried using
string fname= Server.MapPath(FileUpload2.FileName);
string fname= FileUpload2.FileName;
string fname= FileUpload2.PostedFile.FileName;
2,#3 gave me the name of the file, #1 gave me the the path of my website
location.
I do not know what is the difference between 2 and 3, why both gave me
same results.
I read somewhere, that you cannot get the path. Is it true ? If not, what
code should I use ?
Streets and Intersections Data Structure
Streets and Intersections Data Structure
I am writing a program that is supposed to emulate a city, and one of the
problems I am running into is how to store a large amount of
interconnected data. For instance, each Street has a direction enumeration
(NORTH_ONE_WAY, EAST_WEST, etc.) and other attributes. The most important
attribute is that each street has a list of intersections (a map of the
street that it intersects with along with the block number at which it
intersects). From this data structure, I should be able to parse it and
create a visualization (that comes later and is not part of this
question).
The question is: what is the best type of data structure to use for this?
Obviously a relational database would be a good choice, but if I am
writing in C++ (not a constraint for this question, but C++ implementation
would be a plus), should I be using that? What other data structures may
work for this?
I am writing a program that is supposed to emulate a city, and one of the
problems I am running into is how to store a large amount of
interconnected data. For instance, each Street has a direction enumeration
(NORTH_ONE_WAY, EAST_WEST, etc.) and other attributes. The most important
attribute is that each street has a list of intersections (a map of the
street that it intersects with along with the block number at which it
intersects). From this data structure, I should be able to parse it and
create a visualization (that comes later and is not part of this
question).
The question is: what is the best type of data structure to use for this?
Obviously a relational database would be a good choice, but if I am
writing in C++ (not a constraint for this question, but C++ implementation
would be a plus), should I be using that? What other data structures may
work for this?
How to serialize a page with all controls that it contains
How to serialize a page with all controls that it contains
I'm quite new with the programming so please, don't be too hard in your
answers :-) I'm writing an app where in a page, or better in a grid of a
XAML page, I've put a couple of buttons, written directly in XAML (let's
call them "button1" and "button2"), and where it is possible to add two
more buttons in runtime ("button3" and "button4". Moreover, it is possible
to remove one or more of these buttons, included the ones created in XAML.
Till here there isn't any problem.
Obviously, if the status of the page, with the buttons present at the
moment, is not saved in the isolated storage, when the app is re-open I
find only the two buttons created in XAML. This is the tricky part of the
program. As far as I know, I should serialize the controls and then save
them in the isolated storage. I'd like to know if it is possible to
serialize the entire page with the controls present on it (if yes, how
should I proceed?) or if it is necessary to serialize every single control
(how to do that?) taking into account that, as written, not all buttons
could be present.
I tried to search in the Internet but I didn't find anything which could
help me with a clear example. I just know how to serialize arrays or save
strings in the isolated storage but this is new to me.
Thank you in advance
I'm quite new with the programming so please, don't be too hard in your
answers :-) I'm writing an app where in a page, or better in a grid of a
XAML page, I've put a couple of buttons, written directly in XAML (let's
call them "button1" and "button2"), and where it is possible to add two
more buttons in runtime ("button3" and "button4". Moreover, it is possible
to remove one or more of these buttons, included the ones created in XAML.
Till here there isn't any problem.
Obviously, if the status of the page, with the buttons present at the
moment, is not saved in the isolated storage, when the app is re-open I
find only the two buttons created in XAML. This is the tricky part of the
program. As far as I know, I should serialize the controls and then save
them in the isolated storage. I'd like to know if it is possible to
serialize the entire page with the controls present on it (if yes, how
should I proceed?) or if it is necessary to serialize every single control
(how to do that?) taking into account that, as written, not all buttons
could be present.
I tried to search in the Internet but I didn't find anything which could
help me with a clear example. I just know how to serialize arrays or save
strings in the isolated storage but this is new to me.
Thank you in advance
Is it possible to use the importHTML function with a concatenated URL?
Is it possible to use the importHTML function with a concatenated URL?
What I'm basically trying to do is use a URL previously made with the
CONCATENATE function in an IMPORTHTML function.
When I try
importHTML (H1, "table", 0)
Where H1 is the cell with the concatenated URL, I get a #VALUE! error. Not
even referencing H1 from a different sheet will work.
Any ideas about how to get past this? According to the usual syntax, the
URL needs to be enclosed in double quotes. I'm trying to set things up so
I only need to type in a few lines to automatically perform IMPORTHTML
runs.
What I'm basically trying to do is use a URL previously made with the
CONCATENATE function in an IMPORTHTML function.
When I try
importHTML (H1, "table", 0)
Where H1 is the cell with the concatenated URL, I get a #VALUE! error. Not
even referencing H1 from a different sheet will work.
Any ideas about how to get past this? According to the usual syntax, the
URL needs to be enclosed in double quotes. I'm trying to set things up so
I only need to type in a few lines to automatically perform IMPORTHTML
runs.
Friday, 23 August 2013
Calculation of volume and centre of mass of an arbitrary polyhedron
Calculation of volume and centre of mass of an arbitrary polyhedron
Hi I am developing a thesis that will calculate the volume and center of
mass of an arbitrary block of rock.
1- The calculation starts with triple volume integrals. The formulas are
transformed to line integrals using the divergence theorem and Green
theorem. This is a proven method and I have developed software that does
the calculations. The input to the software is the coordinates of the
vertices of the faces.
2- From the field, the orientations of the planes that define the block of
rock are measured using dip and dip direction. These are simply angles
that perfectly identify the planes in space. Additionally, the coordinates
of a point in the planes are measured. This information allows us to
obtain the equation of all the planes that define the block. These planes
are, for example, faults, fractures or geologic layers.
3- The combination of the planes in groups of three, without repetition,
gives us the coordinates of all vertices and the faces they belong to.
4- The last piece of the puzzle is to figure out the sequence of the
coordinates in the face in counterclockwise direction. In other words, it
is necessary to create an index of the coordinates so we know in what
order they are on the face. Moreover, it is required to determine what
vertices really belong to the polyhedron.
I think I can use linear programming to define what vertices (defined by 3
intercepting planes) are really part of the polyhedron. I wont't have an
objective function and I don't know how to define the constraints.
Any suggestion? ideas?
Thanks Jair Santos UBC-Canada
Hi I am developing a thesis that will calculate the volume and center of
mass of an arbitrary block of rock.
1- The calculation starts with triple volume integrals. The formulas are
transformed to line integrals using the divergence theorem and Green
theorem. This is a proven method and I have developed software that does
the calculations. The input to the software is the coordinates of the
vertices of the faces.
2- From the field, the orientations of the planes that define the block of
rock are measured using dip and dip direction. These are simply angles
that perfectly identify the planes in space. Additionally, the coordinates
of a point in the planes are measured. This information allows us to
obtain the equation of all the planes that define the block. These planes
are, for example, faults, fractures or geologic layers.
3- The combination of the planes in groups of three, without repetition,
gives us the coordinates of all vertices and the faces they belong to.
4- The last piece of the puzzle is to figure out the sequence of the
coordinates in the face in counterclockwise direction. In other words, it
is necessary to create an index of the coordinates so we know in what
order they are on the face. Moreover, it is required to determine what
vertices really belong to the polyhedron.
I think I can use linear programming to define what vertices (defined by 3
intercepting planes) are really part of the polyhedron. I wont't have an
objective function and I don't know how to define the constraints.
Any suggestion? ideas?
Thanks Jair Santos UBC-Canada
Form options as radio buttons or regular buttons?
Form options as radio buttons or regular buttons?
I'm very new to Rails, doing a few tutorials, and I don't have a
background in web development, so apologies in advance.
I'm creating a pretty simple app that allows a user to select one of three
available status updates. Should I store these three status updates as a
string or integer? Currently, my Postgres database stores the statuses as
integers, though I'm also curious if there's a way I can specify that only
the numbers 1, 2, or 3 can be inserted.
Second question: I want to display a form that shows as three buttons,
each button corresponding to a specific, set status update. I want the
button to display with a string inside so that it's human readable, but
with that status update corresponding to either 1, 2, or 3. The user can
choose which status, change which status they've selected if they change
their mind before submitting, and then hit a submit button once they've
made up their mind.
Should I use radio buttons to accomplish this? If so, how should I make it
where the radio button displays text and then saves as the integer? Or
should I just use a normal button?
Many thanks!
I'm very new to Rails, doing a few tutorials, and I don't have a
background in web development, so apologies in advance.
I'm creating a pretty simple app that allows a user to select one of three
available status updates. Should I store these three status updates as a
string or integer? Currently, my Postgres database stores the statuses as
integers, though I'm also curious if there's a way I can specify that only
the numbers 1, 2, or 3 can be inserted.
Second question: I want to display a form that shows as three buttons,
each button corresponding to a specific, set status update. I want the
button to display with a string inside so that it's human readable, but
with that status update corresponding to either 1, 2, or 3. The user can
choose which status, change which status they've selected if they change
their mind before submitting, and then hit a submit button once they've
made up their mind.
Should I use radio buttons to accomplish this? If so, how should I make it
where the radio button displays text and then saves as the integer? Or
should I just use a normal button?
Many thanks!
Subscribe to:
Posts (Atom)