This forum is no longer open and is for reading/searching only.

Please use our new MachForm Community Forum instead.

MachForm Community Forums » MachForm 2

Custom action URL and usage field data


  1. crash
    Member

    Hi, I have a small question on MachForm. Can I edit action URL in any form in MachForm and can I usage field data as variable in any script after submiting a form? I want form where user can set any fields and after submiting form redirect to my script where I can work with variables which user set. Sry for my english, but I hope that u understand my question :o)

    Posted 16 years ago #
  2. redityo

    Hi,

    I think you can send the element/field data to another page through GET variable.To do so you should edit "include/post-functions.php". I assume you are working on form 19 with 2 fields in there.
    1. text box {element_1}
    2. another text box {element_2}

    for example, you will send "text box {element_1} data via GET variable.
    Try to search around line 939 ~ 951, you will see this code :

    foreach ($table_data as $key=>$value){
    
    	if($value == ''){ //don't insert blank entry
    		continue;
    	}
    	$value		    = mysql_real_escape_string($value);
    	$field_list    .= "<back>$key<back>,";
    	$field_values  .= "'$value',";
    
    	if(!empty($value)){
    		$has_value = true;
    	}
    }

    replace with this one

    foreach ($table_data as $key=>$value){
    
    	if($value == ''){ //don't insert blank entry
    		continue;
    	}
    	$value		    = mysql_real_escape_string($value);
    	$field_list    .= "<back>$key<back>,";
    	$field_values  .= "'$value',";
    
    	if(!empty($value)){
    		$has_value = true;
    	}
    
    	if ($form_id == 19) {
    		if ($key == 'element_1') {$url_data = $value};
    	}
    }
    
    if ($form_id == 19) {
    	if (!empty($url_data) && $url_data != '')
    		$process_result['form_redirect']  = "http://www.domain.com/test.php?data=" . $url_data;
    }

    don't forget to replace <back> with "backtick" character. It should redirect to "http://www.domain.com/test.php" page after submission with variable "data" on it.


    MachForm Support

    Posted 16 years ago #
  3. celica
    Member

    This didn't work for me; I got:

    "Parse error: syntax error, unexpected '{' in /home/myweb/public_html/form/includes/post-functions.php on line 948 "

    when submitting the form.

    This suggests the following line:

    if ($key == 'element_1') {$url_data = $value};

    has a syntax error? Grateful for help.

    Posted 16 years ago #
  4. yuniar

    ooops..sorry, it should be like this:

    if ($key == 'element_1') {$url_data = $value; }

    MachForm Founder

    Posted 16 years ago #
  5. celica
    Member

    Thanks very much for quick reply yuniar.

    Yes this now works well..

    but for me only if the 'form review' is not requested.

    Sorry to ask more, but can this little script be used to pass the variable to the url string even then? Perhaps it must be moved elsewhere on post-functions.php. That would be a great help to give a better user experience.

    Posted 16 years ago #
  6. yuniar

    Hmm.. what variable are you referring to? custom variable?
    Perhaps an example of the URL string would make it clear.


    MachForm Founder

    Posted 16 years ago #
  7. celica
    Member

    Hi yuniar,

    I have a page which includes a Machform form with hidden field to 'GET' 'domain' variable (the user selected 'domain' before the form). So for example the string is:

    http://www.essentialwebs.co.uk/whois/order.php?domain=myselecteddomain.co.uk

    When the user completes and then submits this form, the 'domain' variable (in my case element_37) becomes 'data' because of the extra script in post-functions.php given by redityo in the solution above.

    My own 'success' form http://www.essentialwebs.co.uk/form/success.php?data=myselecteddomain works well now, collecting the 'data' variable from the string by using the additional script in post-functions.php --- but only if the "Show Review Page Before Submitting".

    I really wish to use the "Review Page Before Submitting" but sadly I do not then have any redirect or the field data sent to the url string.

    What I am asking is could redityo's script shown above be placed elsewere in post-functions.php to also allow use of field data as variable after submitting a form when having the "Review Page" activated also?

    I think then the user will have a better experience.

    Thanks & Regards Alan Davies

    Posted 16 years ago #
  8. redityo

    I see ..Since I don't know you will use the review feature so I only make the modification to normal case only :) .
    Anyway you need to do some modification again to "post-functions.php" file to use those code with review feature enabled. From my previous code you have add this code in there :

    if ($form_id == 19) {
    	if (!empty($url_data) && $url_data != '')
    		$process_result['form_redirect']  = "http://www.domain.com/test.php?data=" . $url_data;
    }

    update those code with this

    if ($form_id == 19) {
    	if (!empty($url_data) && $url_data != '') {
    		$process_result['form_redirect']  = "http://www.domain.com/test.php?data=" . $url_data;
    		$_SESSION['redirect'] = $process_result['form_redirect'] ;
    	}
    }

    it will store redirect url to the session variable, then go to around line 2295 you'll see these code :

    $commit_result['form_redirect'] = $form_redirect;

    and add these code bellow that line

    if (!empty($_SESSION['redirect'])) {
    	$commit_result['form_redirect'] = $_SESSION['redirect'];
    	unset($_SESSION['redirect']);
    }

    MachForm Support

    Posted 16 years ago #
  9. celica
    Member

    Thanks for your kind work on my request Redityo,

    This works great! Now I can use the review page and pass my variable to the final page. Your software is excellent.

    Regards Alan Davies

    Posted 16 years ago #
  10. bizzy
    Member

    hi,
    i want to do something similar to the first case...but it didnt redirect
    i get a suceess message only..if you could just suggest me something that would be great.
    thanks

    Posted 16 years ago #
  11. redityo

    Hi,

    Are sure have change the form id and element id number with yours ? if you look at the code, you will find this :

    $form_id == 19

    and

    $key == 'element_1'

    change the number with yours form id and element id


    MachForm Support

    Posted 16 years ago #
  12. bizzy
    Member

    i left simple }...got it working now..
    but i am getting this error now
    Warning: Cannot modify header information - headers already sent by (output started at /home/wordscri/public_html/machform/includes/post-functions.php:2304) in /home/wordscri/public_html/machform/view.php on line 8

    despite of the error..the redirection of the form was successful
    thanks

    Posted 16 years ago #
  13. redityo

    Hmmm .. maybe there is some typo when you modified the file, I think it's better to restore "post-functions.php" file and re-write the modification again.


    MachForm Support

    Posted 16 years ago #
  14. bizzy
    Member

    i tired doing that as well...but its echoing the same error..altough the form is working perfectly...entering the database and redirecting..just echoing that error on the top
    thanks

    Posted 16 years ago #
  15. bizzy
    Member

    i have uploded my post function code
    you can find it here
    http://rapidshare.com/files/233725056/post.txt.html
    any help will be higly appriciated
    thanks

    Posted 16 years ago #
  16. bizzy
    Member

    i got it working now...there was a couple of white spces at the end creating the problem..
    i deleted the above file..
    thanks for your help
    thanks

    Posted 16 years ago #
  17. akash8m
    Member

    Thanks for the tip, I am trying the same thing but I get the following error.

    http://www.finndr.com/machform/view.php?id=4

    INSERT INTO ap_form_4 (element_3,ip_address,date_created) VALUES ('1225','174.97.171.90','2011-05-27 12:38:30'); Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'element_3,ip_address,date_created) VALUES ('' at line 1

    I want the user to enter the number (element3) and want it go to to the following link http://www.finndr.com/page_id=element3

    Thanks for your help.

    Posted 14 years ago #

RSS feed for this topic

Reply