I need some help in the code below. I want to parse information from a custom_field (tech_spec_table) that contains a table with html tags of a blog/product (eg technical specs) only after the user has checked specific product/products and submitted (with a button) through a form in a blog-post. I have created a page "comparison-page.php" as a template page and try to link the action of the form on this page. screenshot
// check if we got posts to display:
if (have_posts()) :
echo "<form method='post' action='<?php bloginfo('template_url'); ?>/comparison-page.php' >";
while (have_posts()) : the_post();
//the post
echo "<article class='".... >";
echo "<input type='checkbox' name='comparison[]' />";
//the post
$post_loop_count++;
endwhile;
echo "<input type='submit' name='submit' value='Submit'/>";
echo "</form>";
The comparison-page.php file is located into a custom theme under :wp-content/themes/custom-theme. Here is the code for the comparison-page.php
<?php
/* Template Name: comparison-page */
?>
<?php get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
if(isset($_POST['submit'])){ //to run PHP script on submit
if(!empty($_POST['comparison'])){
// Loop to store and display values of individual checked checkbox.
foreach($_POST['comparison'] as $data_specs){
echo $data_specs."</br>";
$data_specs = get_post_meta(get_the_ID(), 'tech_specs_table', true);
$dom = new domDocument;
@$dom->loadHTML($data_specs);
$dom->preserveWhiteSpace = false;
$tables = $dom->getElementsByTagName('table');
$rows = $tables->item()->getElementsByTagName('tr');
foreach ($rows as $row) {
$cols = $row->getElementsByTagName('td');
echo $cols[];
}
}
}
}
?>
</main><!-- .site-main -->
</div><!-- .content-area -->
<?php get_footer(); ?>
Although when i click the button leads to a 404 not found 1)What should i do to make the path invisible and connect correctly to the page? 2)Will the variable "comparison" save all the information from the form so i can get the post_meta information and manipulate in the comparison page?