We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,497 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Calling functions from within a form

Hi

I've read through the posting regarding 'actions on a link' but as my function is not in javascript I didn't want to confuse the conversation.

I was wondering how/if it is possible to call a function from a text link, button, image etc via something like this:

<?php if (isset($_POST["condo_nm"])) 

     echo condoavailable($_POST["condo_nm"]) ;?>

The actuaal function is this:

function condoavailable($condo_nm)
{
// Connect to the database
 require_once ('myaccess/dbc.php');

// Make sure a review doesn't already exist for this Condo
  $query = "SELECT * FROM condo_reviews WHERE condo_nm = '$condo_nm'";
  $data = mysqli_query($dbc, $query);
  if (mysqli_num_rows($data) == 0) 
  {
echo 'Available';
  }
else {
    echo 'Review Complete';
}
}
}

What I'm trying to do is allow users to check to see whether a review has already been submitted for a particular name and if it has echo back to the screen: 'Review Complete' and if it does not exist echo to the screen 'Available'.

I just want users to be able to do this check before clicking on the 'submit' button at the end of the form.

Is there a way?

Mamy thanks

3
Contributors
2
Replies
9 Hours
Discussion Span
1 Year Ago
Last Updated
3
Views
ebanbury
Junior Poster
175 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

You'd need Javascript to do an AJAX call to a PHP script, which executes that function and returns the result.

pritaeas
Posting Prodigy
Moderator
9,317 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,467
Skill Endorsements: 86

You can only run a php function whilst the page is being generated - it is a server side script.

You need a javascript function to do something once the page has loaded and the user starts interacting.

AJAX that Pritaeas mentioned is a way to get javascript to open a php page when a user clicks/triggers something so you can run a php script based on what he has done(in javascript) then the php script does something and returns the data to your javascript function and shows him the data or does something based on what the php script returned.

Biiim
Posting Pro
504 posts since Oct 2011
Reputation Points: 104
Solved Threads: 83
Skill Endorsements: 7

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0707 seconds using 2.74MB