1

I am currently making a report error form that has 4 fields:

  1. Job ID $jobid
  2. Part ID part_id
  3. Machine
  4. Note

The user clicks on a table corresponding the their work and are brought to a new page with a url that has variable. At the moment all the fields are empty however I want the fields to be populated automatically except for notes.

Current Model

Link to report error form:

$EM_html = '<a href="/report_error_form.php?JobID='.$jobid.'&Machine=EM&PartID='.$part_id.'">'.$tick.'</a>

Report error form:

<form action="" method="post">
        Job Number: <input type="text" value="<?php print ($jobid) ?>" name="jobNum"><br>
        Part Number: <input type="text" value="<?php print ($part_id) ?>" name="partNum"><br>
        Machine Code: <input type="text" name="machCode"><br>
        Note:<br><textarea rows="5" name="note" cols="30" placeholder="More detail... (Is there a way to recreate the error?)"></textarea><br>
        <input type="submit" name="submit" value="Submit">
</form>

Example URL

http://sra-pstest/report_error_form.php?JobID=KANBAN16-09-04-01&Machine=EM&PartID=124047 How do "extract" the information out of the url (JobID, Machine, PartID) and automatically fill out the form?

1
  • 1
    have you tried using $_GET['JobID?'] Commented Mar 3, 2016 at 5:21

5 Answers 5

1

You can use $_GET

<?php 
    if(isset($_GET))
    {
        foreach($_GET as $key=>$value)
        {
            $$key=$value;
        }

        echo $JobID."<br>".$Machine."<br>".$PartID;
    }

?>
Sign up to request clarification or add additional context in comments.

Comments

0

Please try this

<?php
        $jobid    = @$_REQUEST['JobID'];
        $part_id  = @$_REQUEST['PartID'];
        $machCode = @$_REQUEST['Machine'];
 ?>


    <form action="" method="post">
                Job Number: <input type="text" value="<?php print ($jobid) ?>" name="jobNum"><br>
                Part Number: <input type="text" value="<?php print ($part_id) ?>" name="partNum"><br>
                Machine Code: <input type="text" name="machCode"><br>
                Note:<br><textarea rows="5" name="note" cols="30" placeholder="More detail... (Is there a way to recreate the error?)"></textarea><br>
                <input type="submit" name="submit" value="Submit">
    </form>

1 Comment

Thanks for the help!
0

You use $_GET Method like this code

<?php 
$jobid=$part_id=$machine="";
if(isset($_GET['JobID']))
{
    $jobid= $_GET['JobID'];

}
if(isset($_GET['Machine']))
{
    $machine= $_GET['Machine'];

}
if(isset($_GET['PartID']))
{
    $part_id= $_GET['PartID'];

}

?>

Comments

0
 <form action="" method="post">
    <?php $jobNumber = isset($_GET['JobID']) ? $_GET['JobID'] : '' ?>
    Job Number: <input type="text" value="<?php echo jobNumber; ?>" name="jobNum"><br>
    <input type="submit" name="submit" value="Submit">
</form>

Comments

0

Try using isset and post method to check if variable are declared and get the variable data on submit of form

<?php
    if(isset($_POST['submit'])){
      $jobid = $_POST['JobID'];
      $part_id = $_POST['PartID'];
      $machCode = $_POST['Machine'];
    }

?>

<form action="" method="post">
     Job Number: <input type="text" value="<?php echo $jobid; ?>" name="jobNum"><br>
     Part Number: <input type="text" value="<?php echo $part_id; ?>" name="partNum"><br>
     Machine Code: <input type="text" name="machCode" value="<?php echo $machCode; ?>"><br>
     Note:<br><textarea rows="5" name="note" cols="30" placeholder="More detail... (Is there a way to recreate the error?)"></textarea><br>
     <input type="submit" name="submit" value="Submit">
</form>


Hope this help

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.