Jump to content

Call a PHP function using forms?


matleeds

Recommended Posts

I suspect I’m trying to achieve this in a cack handed way but my HTML/PHP experience is extremely rusty at the moment.

 

I want a button on a web page ‘SEND REMINDERS’. When the user clicks it I want to call do_send_reminders() that lives in ot.php on my webserver.

 

I suspect some sort of javascript is the best option so if you can help on that then greta but I’m also looking at using forms to do it to.

 

Here’s my admin page..the bit about forms is near the bottom...

 

<?php 

$appointments = ot::db('appointment')->fetch_all('status > 0');

?>

<div style="border-bottom: 1px dotted #AAA">

<?php if ($appointments):?>

 <table class="appointment_table">
                <thead>
      <th>Patient</th>
      <th></th>
                    <th>Date</th>
                    <th></th>
                    <th>Treatment</th>
                </thead>
            <?php foreach($appointments as $a):?>
  		<?php
	$p = ot::db('patient')->fetch('id = ?', array($a->pid));
	$patient = $p->fname.' '.$p->lname;
                           $t = ot::db('treatment')->fetch('id = ?', array($a->tid));
	$treatment = $t->description;
                           $date = date('l F jS, Y', $a->time).' at '.date('g:ia', $a->time);                    
                ?>
                <tr>
                    <td><?php echo $patient?></td>
                    <td>   </td>		
                    <td><?php echo $date?></td>
                    <td>   </td>
                    <td><?php echo $treatment?></td>
                </tr>
            <?php endforeach?>
    </table>       
</div>    

<form action='<?php echo $_SERVER['REQUEST_URI']?>' method='post' >
<p>Email:<br/><input type='text' name='email' /></p>
<p>Password:<br/><input type='password' name='pwd' /></p>
<p><input type='submit' name='do_send_reminders' value='Send reminders' /> 
</form>	

<?php else:?>
<p>There are currently no appointments where reminders have not been sent.</p>
<?php endif?>

 

As you can probably guess I’ve just copied the code from the login in page and tried to amend it.

 

I don’t want any text boxes appearing re. email/password. When I click oon the button at the moment nothing appears to happen..the do_send_reminders() isn’t called.

 

thanks.

Link to comment
Share on other sites

You can use javascript but the easiest way would be to post the form as you already are and pick up if the form was submitted..

<?php 

if (isset($_POST['do_send_reminders'])) {
// Run your send reminders code here
}

$appointments = ot::db('appointment')->fetch_all('status > 0');

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.