How do I create a link for every row / record found in the database to use as a way to fill out the form on click?

I have a site with members, and when members register, they have access to a page with a form that they can use to submit information. This form has a hidden input "user_email" with a preloaded defualt value equal to the registered members email item in the file.

<form action="xxx.php" class="well" id="xxx" name"xxx" method="post">   

<input type="hidden" id="user_email" name="user_email" value="xxx@email.com">
<input type="text" id="invoice_id" name="invoice_id">
<input type="text" id="other1" name="other1">

<input type="submit" value="Submit">

</form>

      

I need a script that will take this prepopulated form input value named "user_email" and search and fetch every row / data record in my database that has the same value in the "user_email" column.

Then For every line / record matched / found I try to create the link I created

When clicking any generated link, a function is required to pre-populate the form with the corresponding received line / record data.

I can't imagine how long it will take for one to have the skills required to compose the code needed to achieve the above ... Any direction point or any help is greatly appreciated ... thanks for your time.

+3


source to share


1 answer


You can make a request to a PHP script that reads an email, finds and returns related data as an array of objects, and outputs HTML links, with each link containing data in custom 'data-x' attributes. For example:

//email_details.php <?php //your function that returns an array of objects $rows = find_the_data($_GET['user_email']); foreach($rows as $row) { ?> <a class="email_data_link" href="#" data-invoice-id="<?php echo $row->invoice_id ?>" data-other1="<?php echo $row->other1 ?>">A link</a> <?php } ?>

Then you can use a tool like jquery to change the form when the link is clicked



$('.email_data_link').on('click', function() { //copy the data embedded in the clicked link to the form $('#invoice_id').val($(this).data('invoice-id')); $('#other1').val($(this).data('other1'); });

Without additional context and an understanding of your level of knowledge, it is difficult to create a truly useful example, but it might at least give you some food for thought.

Good luck

0


source







All Articles