Directing form to the correct directory

Hi, and thanks for previous help! I am almost where I want to be.

I have been trying to get a form which sends an accompanying file working. I just managed it.

I got the form from here.

It comes with a lot of bewildering stuff. It has PHPMailer and composer. I uploaded it to my webpage in the /home/mywebpage/public_html/php directory, as it is php. There are now a lot of sub-directories and many many things I do not understand.

The above link gives me a formpage.html page.

When I open this page from www.mywebpage.com/php/formpage.html I can send data and a file to an email address I specify in handler.php I get a nice email with the contact form data in the email and an email attachment, my file.

You can view formpage.html and all of these files from the link above.

I am a raw beginner with this stuff. When I send data to myself, the <form line looks like this:

<form action="php/thankyou18BEweek15.php" method="POST" name="myForm" onsubmit="return checkForExpiration();" >

because I keep all php stuff in the subfolder /php.

The formpage html <form part looks like this:

<form role="form" method="post" id="reused_form">

I don’t see any <form action=“handler.php” so I am not sure how to alter this.

How can I alter this to make it drop a directory (it is in public_html) to /php/ and find all the php and PHPMailer stuff?

I think I should put formpage.html in /home/mywebpage/public_html and I want to leave all the other stuff in /php

How to redirect the form from public_html to php?

Changing the action would be the simplest. You just need the action to direct to the script that processes the form.

Trouble is, there is no action=" just role="…

I have not encountered this before. I do not know how to handle it.

In my ordinary, only data forms I set action="php/thankyou18BEweek15.php"

Can I do the same with role="form"

??

role is something weird!

Just add it to the form. Unless the form is dynamically generated, it’s an easy change; if it IS created dynamically, you just need to find where that is, and add it there.Without the action there, it is expecting the form to be processed on the same script the form is or to have javascript handle the sending of the data to where it needs to go.

The form data is submitted using jquery/ajax. The code doing this is in form.js. An onsubmit event is being attached to the form with an id=‘reused_form’ attribute. The URL to handler.php is found in this code. You can edit it to add php to the path.

What the code should have done is have an action=’…’ attribute in the form tag and have the javascript code get and use that attribute value as the url in the ajax code.

Just change the url: handler.php, line in form.js to the following and add an action=‘php/handler.php’ attribute to the form tag -

url: $form.attr('action'),
1 Like

Thank you!

That worked, just the success message does not display properly. I’ll have to work on that, but I get the emails with the file attached! Success!

Thanks again!

Sponsor our Newsletter | Privacy Policy | Terms of Service