skip to Main Content

I’m trying to invoke job.php from careers.php using the code below. Could someone help me identify what might be wrong or suggest a better approach?

careers.php:

   <div class="trending-lower-text d-flex align-items-center justify-content-between">
       <a class="custom-btn btn1" href=“aform.php"><span>Apply</span></a>
       <form id="hiddenForm" action="job.php" method="post">
           <input type="hidden" name="jobTitle" value="SoftwareEngineer">
           <button type="submit" class="custom-btn btn2"><span>Read More</span></button>
       </form>
   </div>

job.php

<?php include_once '../../includes/header.php';
if (isset($_POST['jobTitle'])) {
    $title = htmlspecialchars($_POST['jobTitle']); // Retrieve the value from the form
?>

2

Answers


  1. If you switch to using a link instead of a form, it would make things simpler:

    careers.php:

       <div class="trending-lower-text d-flex align-items-center justify-content-between">
           <a class="custom-btn btn1" href=“aform.php"><span>Apply</span></a>
           <a class="custom-btn btn2" href=“job.php?jobTitle=SoftwareEngineer"><span>Read More</span></a>
       </div>
    

    job.php

    <?php include_once '../../includes/header.php';
    if (isset($_GET['jobTitle'])) {
        $title = $_GET['jobTitle'];
    ?>
    
    
    Login or Signup to reply.
  2. I think You missed Curly braces in job.php that’s why you don’t access your variable and i echo variable it works after adding curly braces
    As i runs this code at my own end.

    Code:

    <?php 
    if (isset($_POST['jobTitle'])) {
    $title = htmlspecialchars($_POST['jobTitle']); // Retrieve the value from     the form
    echo $title;//variable that you take from career.php file
    } //here you have to add close curly braces
    ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search