• Hi. I was asked to create a form that, when filled out and submitted, would pull data from an external server to show in a new or same page. Basically like the results you get on this page on a dental insurance site. They would like to display the contact info, which is far less info than on that link, as well as the map and said they would set up a JSON file for the site to send/receive the info from their server. Using JSON wrappers and POST method, they mentioned that I may only need an id to make this happen, but I’ve never done this before. I’ve seen a couple of form plugins that use a REST API attribute, but not sure if that would be the same thing or if that’s even what I’m looking for, but the client did say we should also be using REST API. Are there any good ways to go about creating this page in an existing WordPress site? Thanks in advance for anyone who can help.

Viewing 10 replies - 1 through 10 (of 10 total)
  • You can use wp fetch in your javascript that will be handling the form, something like

    # in your PHPcode
    wp_enqueue_script( 'your-script', 'yourscriptpath/script.js', array( 'wp-api','wp-api-fetch' ), 'your version', false );
    
    # in your script.js  that handles the form
    
    wp.apiFetch({
        url: remoute/url,
        method: 'POST', 
    }).then(response => {
        // Handle the response
        console.log('response:', response);
        // Display the lookup results on the page
        // ...
    }).catch(error => {
        // Handle any errors
        console.error('Error performing lookup:', error);
    }).finally(() => {
        // do anything else
    });
    Thread Starter dsb0328

    (@dsb0328)

    Thank you for your response @alanfuller I’ve been looking it over and I’m starting to wonder if this is too far over my head. The way they made it sound, it didn’t seem too difficult. However, I am not great with Java or PHP, so this code, as much as I appreciate it, doesn’t seem very understandable to me. I don’t know where to start with this, even tying it into a form, which I assumed I would create using a plugin like CF7 or something else. Thanks again, and if you or anyone else has any other advice that can help, please let me know.

    It is fairely straight forward for a PHP / Javascript developer. Perhaps your clients mis understood your skill set.

    The only advice I can give you is to be honest with your client such custom development is outside your experience.

    Thread Starter dsb0328

    (@dsb0328)

    Thanks. Yes, I have been open and honest with them. They are just asking me to try, and with a little bit of experience altering the PHP/Javascript code, I just thought I would ask. Sounds like this is the only way to go about doing this, so I will research what you mentioned to see if there’s any elaboration out there about it and go from there.

    There are non code approaches too.

    Being a development forum I assumed developer skills.

    However, using a (probably premium) form plugin and services like Zapier you probably could configure a solution without code.

    Thread Starter dsb0328

    (@dsb0328)

    @alanfuller You’re absolutely right, but I didn’t know where else to ask about this. I feel like I know quite a bit about WordPress, but certainly know that there are PHP and Javascript developers out there that know waaaaaay more than I do. That’s why I come to the community to ask questions… because I know I’ll get great answers. I appreciate the reply about Zapier. I am going to look into that as well as the first method you gave in order to hopefully improve my skills and do it the right way. Thanks again for all of your replies. Really appreciate it.

    Thread Starter dsb0328

    (@dsb0328)

    Just thought I’d bump this question to see if anyone else had any other ideas, since I have pretty much been stumped, even with Alan’s help. I just don’t understand where to put that code and how to use it with a contact form plugin, like CF7. If so, great, and I would appreciate it. If not, then thanks anyway for reading.

    May I remind you of the do not bump guideline https://wordpress.org/support/guidelines/#do-not-bump-posts

    It is horrible when a client asks you to do something beyond your capabilities, and my previous advice stands, tell the client this job is not for you.

    However there are a couple of other approaches
    1) if the client is paying enough, outsource the development
    2) AI is actually very good at giving technical /coding guidance
    Using this prompt
    using wp.api_fetch show me an example of how on submission of contact form 7 I can integrate javascript to make and API call
    on Chat GPT you get a pretty reasonable starter with explantations

    • This reply was modified 2 years, 5 months ago by Alan Fuller.
    • This reply was modified 2 years, 5 months ago by Alan Fuller.
    Thread Starter dsb0328

    (@dsb0328)

    Oh wow. I didn’t even know there was a “no bump” policy. I had just taken your previous advice, researched some, was still confused, didn’t see a different place to ask this question in the forums, and, instead of repeating the question, thought it better to just ask here again. My apologies. But thanks for the advice about Chat GPT. Hadn’t even thought about using AI. Also, I don’t know anyone else that can do this, so I can’t source it out. That’s why I’m asking here.

    It is better to start a new thread even if it is very similar it you are not getting the input you need from the volunteers already on the thread.

    The way the support volunteers work is first they look at the unanswered questions and pick the one they may be able to help on.

    So if my input is not getting you anywhere, feel free to repost but with perhaps narrower input, like for instance be specific you are trying to integrate to CF7 etc. ( I wont be offended if I see such a post I’ll leave it for other volunteers to look at )

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Pull data from external server using a Form, REST API & JSON’ is closed to new replies.